Bug 1719505 - [remote] Add CDP and WebDriver BiDi tests for navigator.webdriver. r=webdriver-reviewers,jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D144984
This commit is contained in:
Henrik Skupin 2022-04-29 17:38:14 +00:00
Родитель 4d7a8c9ac8
Коммит dcd3dae49f
6 изменённых файлов: 81 добавлений и 0 удалений

Просмотреть файл

@ -9,6 +9,7 @@ with Files("**"):
BROWSER_CHROME_MANIFESTS += [
"test/browser/browser.ini",
"test/browser/browser_cdp_only.ini",
"test/browser/dom/browser.ini",
"test/browser/emulation/browser.ini",
"test/browser/fetch/browser.ini",

Просмотреть файл

@ -0,0 +1,15 @@
[DEFAULT]
tags = remote
subsuite = remote
args =
--remote-debugging-port
--remote-allow-origins=null
prefs = # Bug 1600054: Make CDP Fission compatible
fission.bfcacheInParent=false
fission.webContentIsolationStrategy=0
remote.active-protocols=2
support-files =
chrome-remote-interface.js
head.js
[browser_interface.js]

Просмотреть файл

@ -0,0 +1,20 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function navigator_webdriver({ client }) {
const { Runtime } = client;
const url = toDataURL("default-test-page");
await loadURL(url);
await enableRuntime(client);
const { result } = await Runtime.evaluate({
expression: "navigator.webdriver",
});
is(result.type, "boolean", "The returned type is correct");
is(result.value, true, "navigator.webdriver is enabled");
});

Просмотреть файл

@ -0,0 +1,4 @@
[interface.py]
[test_navigator_webdriver_enabled]
disabled:
if os == "android": bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1762135

Просмотреть файл

Просмотреть файл

@ -0,0 +1,41 @@
import pytest
from webdriver.bidi.client import BidiSession
pytestmark = pytest.mark.asyncio
async def test_navigator_webdriver_enabled(inline, browser):
# Request a new browser with only WebDriver BiDi and not Marionette/CDP enabled.
current_browser = browser(use_bidi=True, extra_prefs={"remote.active-protocols": 1})
server_port = current_browser.remote_agent_port
async with BidiSession.bidi_only(f"ws://localhost:{server_port}") as bidi_session:
# Until script.evaluate has been implemented use console logging
# as workaround to retrieve the value for navigator.webdriver.
url = inline(
"""
<script>console.log("navigator.webdriver", navigator.webdriver);</script>
"""
)
await bidi_session.session.subscribe(events=["log.entryAdded"])
on_entry_added = bidi_session.event_loop.create_future()
async def on_event(method, data):
remove_listener()
on_entry_added.set_result(data)
remove_listener = bidi_session.add_event_listener("log.entryAdded", on_event)
contexts = await bidi_session.browsing_context.get_tree(max_depth=0)
assert len(contexts) > 0
await bidi_session.browsing_context.navigate(
context=contexts[0]["context"], url=url, wait="complete"
)
event_data = await on_entry_added
assert event_data["args"][0]["value"] == "navigator.webdriver"
assert event_data["args"][1]["value"] is True