8356425814
浮动面板可最小化至右下角、左下角随时展开;标签与浏览记录写入 MySQL,切换菜单保持活动。 Co-authored-by: Cursor <cursoragent@cursor.com>
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
"""Tests for embedded browser UI state."""
|
|
|
|
from server.utils.browser_ui_state import (
|
|
empty_browser_state,
|
|
parse_browser_state,
|
|
record_visit,
|
|
)
|
|
|
|
|
|
def test_empty_browser_state():
|
|
assert parse_browser_state(None) == empty_browser_state()
|
|
|
|
|
|
def test_parse_filters_unsafe_urls():
|
|
raw = {
|
|
"url_history": ["https://ok.example", "javascript:alert(1)", "ftp://x"],
|
|
"tabs": [
|
|
{"id": "t1", "url": "https://a.com", "stack": ["https://a.com"], "stack_index": 0},
|
|
{"id": "t2", "url": "data:text/html,x"},
|
|
],
|
|
}
|
|
state = parse_browser_state(raw)
|
|
assert state["url_history"] == ["https://ok.example"]
|
|
assert len(state["tabs"]) == 1
|
|
assert state["tabs"][0]["id"] == "t1"
|
|
|
|
|
|
def test_record_visit_dedupes_history():
|
|
state = empty_browser_state()
|
|
state = record_visit(state, "https://a.example", "A")
|
|
state = record_visit(state, "https://b.example", "B")
|
|
state = record_visit(state, "https://a.example", "A again")
|
|
assert state["url_history"][0] == "https://a.example"
|
|
assert state["url_history"][1] == "https://b.example"
|
|
assert len(state["visits"]) == 3
|
|
assert state["visits"][0]["title"] == "A again"
|