-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc7931f
commit 21176db
Showing
8 changed files
with
531 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Test console log are present</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
<script> | ||
promise_test(async () => { | ||
const some_message = "SOME MESSAGE"; | ||
// Subscribe to `log.entryAdded` BiDi events. This will not add a listener to the page. | ||
await test_driver.bidi.log.entry_added.subscribe(); | ||
// Add a listener for the log.entryAdded event. This will not subscribe to the event, so the subscription is | ||
// required before. The cleanup is done automatically after the test is finished. | ||
const log_entry_promise = new Promise(resolve => test_driver.bidi.log.entry_added.on(resolve)); | ||
// Emit a console.log message. | ||
console.log(some_message) | ||
// Wait for the log.entryAdded event to be received. | ||
const event = await log_entry_promise; | ||
// Assert the log.entryAdded event has the expected message. | ||
assert_equals(event.args.length, 1); | ||
const event_message = event.args[0]; | ||
assert_equals(event_message.value, some_message); | ||
}, "Assert log event is logged"); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# mypy: allow-untyped-defs | ||
import sys | ||
|
||
from typing import Dict, List, Literal, Optional, Union | ||
|
||
|
||
# TODO: check if type annotation is supported by all the required versions of Python. | ||
# noinspection PyCompatibility | ||
class WindowProxyProperties(Dict): | ||
context: str | ||
|
||
|
||
# TODO: check if type annotation is supported by all the required versions of Python. | ||
# noinspection PyCompatibility | ||
class WindowProxyRemoteValue(Dict): | ||
""" | ||
WebDriver BiDi browsing context descriptor. | ||
""" | ||
type: Literal["window"] | ||
value: WindowProxyProperties | ||
|
||
|
||
class BidiSessionSubscribeAction: | ||
name = "bidi.session.subscribe" | ||
|
||
# TODO: check if type annotation is supported by all the required versions of Python. | ||
# noinspection PyCompatibility | ||
class Payload(Dict): | ||
""" | ||
Payload for the "bidi.session.subscribe" action. | ||
events: List of event names to subscribe to. | ||
contexts: Optional list of browsing contexts to subscribe to. Each context can be either a BiDi serialized value, | ||
or a string. The latter is considered as a browsing context id. | ||
""" | ||
events: List[str] | ||
contexts: Optional[List[Union[str, WindowProxyRemoteValue]]] | ||
|
||
def __init__(self, logger, protocol): | ||
self.logger = logger | ||
self.protocol = protocol | ||
|
||
async def __call__(self, payload: Payload): | ||
events = payload["events"] | ||
contexts = None | ||
if payload["contexts"] is not None: | ||
contexts = [] | ||
for c in payload["contexts"]: | ||
if isinstance(c, str): | ||
contexts.append(c) | ||
elif isinstance(c, dict) and "type" in c and c["type"] == "window": | ||
contexts.append(c["value"]["context"]) | ||
else: | ||
raise ValueError("Unexpected context type: %s" % c) | ||
return await self.protocol.bidi_events.subscribe(events, contexts) | ||
|
||
|
||
async_actions = [BidiSessionSubscribeAction] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.