Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sadym-chromium committed Jan 31, 2025
1 parent 1569905 commit 8526917
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 1 deletion.
104 changes: 104 additions & 0 deletions tests/browsing_context/__snapshots__/test_navigate_events.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,107 @@
}),
])
# ---
# name: test_window_open_aboutBlank_checkEvents[]
list([
dict({
'method': 'browsingContext.contextCreated',
'params': dict({
'children': None,
'clientWindow': '',
'context': 'stable_0',
'originalOpener': 'stable_2',
'parent': None,
'url': 'stable_1',
'userContext': 'default',
}),
'type': 'event',
}),
])
# ---
# name: test_window_open_aboutBlank_checkEvents[about:blank?test]
list([
dict({
'method': 'browsingContext.contextCreated',
'params': dict({
'children': None,
'clientWindow': '',
'context': 'stable_0',
'originalOpener': 'stable_2',
'parent': None,
'url': 'stable_1',
'userContext': 'default',
}),
'type': 'event',
}),
])
# ---
# name: test_window_open_aboutBlank_checkEvents[about:blank]
list([
dict({
'method': 'browsingContext.contextCreated',
'params': dict({
'children': None,
'clientWindow': '',
'context': 'stable_0',
'originalOpener': 'stable_2',
'parent': None,
'url': 'stable_1',
'userContext': 'default',
}),
'type': 'event',
}),
])
# ---
# name: test_window_open_url_checkEvents
list([
dict({
'method': 'browsingContext.contextCreated',
'params': dict({
'children': None,
'clientWindow': '',
'context': 'stable_0',
'originalOpener': 'stable_2',
'parent': None,
'url': 'stable_1',
'userContext': 'default',
}),
'type': 'event',
}),
dict({
'method': 'browsingContext.navigationStarted',
'params': dict({
'context': 'stable_0',
'navigation': 'stable_3',
'url': 'stable_4',
}),
'type': 'event',
}),
dict({
'method': 'browsingContext.navigationCommitted',
'params': dict({
'context': 'stable_0',
'navigation': 'stable_3',
'url': 'stable_4',
}),
'type': 'event',
}),
dict({
'method': 'browsingContext.domContentLoaded',
'params': dict({
'context': 'stable_0',
'navigation': 'stable_3',
'url': 'stable_4',
}),
'type': 'event',
}),
dict({
'method': 'browsingContext.load',
'params': dict({
'context': 'stable_0',
'navigation': 'stable_3',
'url': 'stable_4',
}),
'type': 'event',
}),
])
# ---
57 changes: 56 additions & 1 deletion tests/browsing_context/test_navigate_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

SNAPSHOT_EXCLUDE = props("timestamp", "timings", "headers", "stacktrace",
"response", "initiator", "realm")
KEYS_TO_STABILIZE = ['context', 'navigation', 'id', 'url', 'request']
KEYS_TO_STABILIZE = [
'context', 'navigation', 'id', 'url', 'request', 'originalOpener'
]


async def set_beforeunload_handler(websocket, context_id):
Expand Down Expand Up @@ -76,6 +78,59 @@ async def test_navigate_checkEvents(websocket, context_id, url_base,
assert messages == snapshot(exclude=SNAPSHOT_EXCLUDE)


@pytest.mark.asyncio
async def test_window_open_url_checkEvents(websocket, context_id, url_example,
read_messages, snapshot):
await subscribe(websocket, ["browsingContext"])

# Make same-document navigation.
await send_JSON_command(
websocket, {
"method": "script.evaluate",
"params": {
"expression": f"window.open('{url_example}');",
"target": {
"context": context_id,
},
"awaitPromise": False
}
})

messages = await read_messages(5,
filter_lambda=lambda x: 'id' not in x,
keys_to_stabilize=KEYS_TO_STABILIZE,
check_no_other_messages=True,
sort=False)
assert messages == snapshot(exclude=SNAPSHOT_EXCLUDE)


@pytest.mark.asyncio
@pytest.mark.parametrize("url", ["", "about:blank", "about:blank?test"])
async def test_window_open_aboutBlank_checkEvents(websocket, context_id, url,
read_messages, snapshot):
await subscribe(websocket, ["browsingContext"])

# Make same-document navigation.
await send_JSON_command(
websocket, {
"method": "script.evaluate",
"params": {
"expression": f"window.open('{url}');",
"target": {
"context": context_id,
},
"awaitPromise": False
}
})

messages = await read_messages(1,
filter_lambda=lambda x: 'id' not in x,
keys_to_stabilize=KEYS_TO_STABILIZE,
check_no_other_messages=True,
sort=False)
assert messages == snapshot(exclude=SNAPSHOT_EXCLUDE)


@pytest.mark.asyncio
async def test_navigate_aboutBlank_checkEvents(websocket, context_id, url_base,
read_messages, snapshot):
Expand Down

0 comments on commit 8526917

Please sign in to comment.