545abeb515
- Add throttled large-operation handling for tab, group, and session commands. - Introduce performance profiles, audible-tab aware gentle mode, and job progress tracking. - Support background session restores with status/cancel commands and lazy placeholders. - Expose new perf and extension CLI groups plus matching Python SDK methods. - Preserve pinned tabs during session snapshots and debounce auto-save updates. - Bump browser-cli and extension versions to 0.10.0 and add pytest-cov to dev deps. - Add coverage for performance controls, background jobs, lazy restores, and tab metadata.
138 lines
4.8 KiB
Python
138 lines
4.8 KiB
Python
"""Tests for tabs.* commands."""
|
|
import pytest
|
|
|
|
def test_tabs_list(browser):
|
|
tabs = browser("tabs.list")
|
|
assert isinstance(tabs, list)
|
|
assert len(tabs) > 0
|
|
first = tabs[0]
|
|
assert "id" in first
|
|
assert "windowId" in first
|
|
assert "url" in first
|
|
assert "title" in first
|
|
assert "muted" in first
|
|
assert "groupId" in first
|
|
|
|
def test_tabs_count(browser):
|
|
count = browser("tabs.count", {})
|
|
tabs = browser("tabs.list")
|
|
assert count == len(tabs)
|
|
|
|
def test_tabs_count_with_pattern(browser):
|
|
count = browser("tabs.count", {"pattern": "http"})
|
|
assert isinstance(count, int)
|
|
assert count >= 0
|
|
|
|
def test_tabs_filter(browser):
|
|
result = browser("tabs.filter", {"pattern": "http"})
|
|
assert isinstance(result, list)
|
|
for tab in result:
|
|
assert "http" in tab.get("url", "")
|
|
|
|
def test_tabs_query(browser):
|
|
result = browser("tabs.query", {"search": "a"})
|
|
assert isinstance(result, list)
|
|
|
|
def test_tabs_active_exists(browser):
|
|
tabs = browser("tabs.list")
|
|
active = [t for t in tabs if t.get("active")]
|
|
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_status(browser):
|
|
result = browser("tabs.status", {})
|
|
assert isinstance(result, dict)
|
|
assert "id" in result
|
|
assert "muted" in result
|
|
|
|
def test_tabs_html(browser, http_tab):
|
|
html = browser("tabs.html", {"tabId": http_tab["id"]})
|
|
assert isinstance(html, str)
|
|
assert len(html) > 0
|
|
assert "<html" in html.lower() or "<!doctype" in html.lower()
|
|
|
|
def test_tabs_close_by_id(browser):
|
|
result = browser("navigate.open", {"url": "https://example.com", "background": True})
|
|
tab_id = result["id"]
|
|
|
|
browser("tabs.close", {"tabId": tab_id})
|
|
|
|
tabs = browser("tabs.list")
|
|
assert tab_id not in [t["id"] for t in tabs]
|
|
|
|
def test_tabs_dedupe(browser):
|
|
# Open the same URL twice
|
|
r1 = browser("navigate.open", {"url": "https://example.com", "background": True})
|
|
r2 = browser("navigate.open", {"url": "https://example.com", "background": True})
|
|
id1, id2 = r1["id"], r2["id"]
|
|
|
|
try:
|
|
result = browser("tabs.dedupe")
|
|
assert isinstance(result, dict)
|
|
assert result.get("closed", 0) >= 0
|
|
# At least one of the two duplicates should be gone
|
|
remaining = browser("tabs.list")
|
|
remaining_ids = {t["id"] for t in remaining}
|
|
assert not (id1 in remaining_ids and id2 in remaining_ids), \
|
|
"Both duplicate tabs still open after dedupe"
|
|
finally:
|
|
for tid in (id1, id2):
|
|
try:
|
|
browser("tabs.close", {"tabId": tid})
|
|
except Exception:
|
|
pass
|
|
|
|
def test_tabs_sort(browser):
|
|
result = browser("tabs.sort", {"by": "domain"})
|
|
# No error and at least returns something (None or dict)
|
|
assert result is None or isinstance(result, dict)
|
|
|
|
def test_tabs_move_forward(browser):
|
|
r1 = browser("navigate.open", {"url": "https://example.com", "background": True})
|
|
r2 = browser("navigate.open", {"url": "https://example.com", "background": True})
|
|
id1, id2 = r1["id"], r2["id"]
|
|
|
|
try:
|
|
# Move id1 forward — just verify no error is raised
|
|
browser("tabs.move", {"tabId": id1, "forward": True})
|
|
finally:
|
|
browser("tabs.close", {"tabId": id1})
|
|
browser("tabs.close", {"tabId": id2})
|
|
|
|
def test_tabs_merge_windows_no_crash(browser):
|
|
result = browser("tabs.merge_windows")
|
|
assert isinstance(result, dict)
|
|
assert "moved" in result
|
|
|
|
def test_tabs_mute_and_unmute(browser, http_tab):
|
|
muted = browser("tabs.mute", {"tabId": http_tab["id"]})
|
|
assert isinstance(muted, dict)
|
|
assert muted["tabId"] == http_tab["id"]
|
|
assert muted["muted"] is True
|
|
listed = browser("tabs.list")
|
|
listed_tab = next(t for t in listed if t["id"] == http_tab["id"])
|
|
assert listed_tab["muted"] is True
|
|
|
|
unmuted = browser("tabs.unmute", {"tabId": http_tab["id"]})
|
|
assert isinstance(unmuted, dict)
|
|
assert unmuted["tabId"] == http_tab["id"]
|
|
assert unmuted["muted"] is False
|
|
listed = browser("tabs.list")
|
|
listed_tab = next(t for t in listed if t["id"] == http_tab["id"])
|
|
assert listed_tab["muted"] is False
|
|
status = browser("tabs.status", {"tabId": http_tab["id"]})
|
|
assert status["muted"] is False
|
|
|
|
def test_tabs_mute_requires_explicit_tab_when_multiple_tabs_open(browser):
|
|
opened = browser("navigate.open", {"url": "https://example.com", "background": True})
|
|
try:
|
|
with pytest.raises(RuntimeError, match="Refusing to mute without explicit tab ID"):
|
|
browser("tabs.mute", {})
|
|
finally:
|
|
browser("tabs.close", {"tabId": opened["id"]})
|