change that tab open change url inplace and get active tab from window id
Testing / test (push) Successful in 29s
Package Extension / package-extension (push) Successful in 11s
Build & Publish Package / publish (push) Successful in 43s

This commit is contained in:
2026-04-13 19:50:46 +02:00
parent 9dbe57c66c
commit 5150933319
8 changed files with 90 additions and 10 deletions
+27 -1
View File
@@ -154,6 +154,12 @@ class TestNavigation:
b.focus_url("github.com")
mock_send.assert_called_once_with("navigate.focus", {"pattern": "github.com"}, profile=None)
def test_navigate_tab(self, b, mock_send):
b.navigate_tab(5, "https://example.com")
mock_send.assert_called_once_with(
"navigate.to", {"tabId": 5, "url": "https://example.com"}, profile=None
)
def test_profile_forwarded(self, b_profile, mock_send):
b_profile.reload()
mock_send.assert_called_once_with("navigate.reload", {"tabId": None}, profile="brave")
@@ -244,6 +250,18 @@ class TestTabs:
b.tabs_active(10)
mock_send.assert_called_once_with("tabs.active", {"tabId": 10}, profile=None)
def test_window_active_tab(self, b, mock_send):
mock_send.return_value = TAB_DATA
tab = b.window_active_tab(1)
assert isinstance(tab, Tab)
assert tab.id == 10
mock_send.assert_called_once_with("tabs.active_in_window", {"windowId": 1}, profile=None)
def test_window_active_tab_missing_raises(self, b, mock_send):
mock_send.return_value = None
with pytest.raises(RuntimeError, match="No active tab found for window 1"):
b.window_active_tab(1)
def test_tabs_filter(self, b, mock_send):
mock_send.return_value = [TAB_DATA]
tabs = b.tabs_filter("example")
@@ -564,7 +582,15 @@ class TestTabModel:
def test_open(self, tab, mock_send):
tab.open("https://new.example.com")
mock_send.assert_called_once_with(
"navigate.open", {"url": "https://new.example.com", "background": False}, profile=None
"navigate.to", {"tabId": 10, "url": "https://new.example.com"}, profile=None
)
def test_open_background_changes_same_tab(self, tab, mock_send):
tab.open("https://new.example.com", background=True)
mock_send.assert_called_once_with(
"navigate.to",
{"tabId": 10, "url": "https://new.example.com"},
profile=None,
)
def test_unbound_raises(self):
+21
View File
@@ -81,3 +81,24 @@ def test_nav_open_in_background(browser):
assert not new_tab.get("active"), "background tab should not be active"
finally:
browser("tabs.close", {"tabId": new_id})
def test_nav_to_updates_existing_tab(browser):
result = browser("navigate.open", {"url": "https://example.com", "background": True})
tab_id = result["id"]
try:
before_ids = {t["id"] for t in browser("tabs.list")}
updated = browser("navigate.to", {"tabId": tab_id, "url": "https://example.org"})
assert updated["id"] == tab_id
tabs = browser("tabs.list")
after_ids = {t["id"] for t in tabs}
assert after_ids == before_ids
tab = next(t for t in tabs if t["id"] == tab_id)
assert "example.org" in (tab.get("url") or "")
finally:
try:
browser("tabs.close", {"tabId": tab_id})
except Exception:
pass
+7
View File
@@ -44,6 +44,13 @@ def test_tabs_active_exists(browser):
assert len(active) >= 1, "Expected at least one active tab"
def test_tabs_active_in_window(browser):
active = next(t for t in browser("tabs.list") if t.get("active"))
result = browser("tabs.active_in_window", {"windowId": active["windowId"]})
assert result["id"] == active["id"]
assert result["windowId"] == active["windowId"]
def test_tabs_html(browser, http_tab):
html = browser("tabs.html", {"tabId": http_tab["id"]})
assert isinstance(html, str)