tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 2a6e93945a073f62a51281b6fef6d7d6523b96b5
parent 5a83a161a49512e0b29ee83d178b015b77da334f
Author: Henrik Skupin <mail@hskupin.info>
Date:   Tue,  9 Dec 2025 14:06:20 +0000

Bug 1944568 - [wdspec] Add Mozilla specific tests for retrieving chrome browsing contexts via browsingContext.getTree. r=jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D275232

Diffstat:
Atesting/web-platform/mozilla/meta/webdriver/bidi/browsing_context/get_tree/moz_scope.py.ini | 13+++++++++++++
Atesting/web-platform/mozilla/tests/webdriver/bidi/browsing_context/get_tree/__init__.py | 0
Atesting/web-platform/mozilla/tests/webdriver/bidi/browsing_context/get_tree/moz_scope.py | 181+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 194 insertions(+), 0 deletions(-)

diff --git a/testing/web-platform/mozilla/meta/webdriver/bidi/browsing_context/get_tree/moz_scope.py.ini b/testing/web-platform/mozilla/meta/webdriver/bidi/browsing_context/get_tree/moz_scope.py.ini @@ -0,0 +1,13 @@ +[moz_scope.py] + [test_multiple_browser_windows] + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=2004388 + expected: + if os == "android": FAIL + + [test_custom_chrome_window_without_iframes] + disabled: + if os == "android": https://bugzilla.mozilla.org/show_bug.cgi?id=1762066 + + [test_custom_chrome_window_with_iframes] + disabled: + if os == "android": https://bugzilla.mozilla.org/show_bug.cgi?id=1762066 diff --git a/testing/web-platform/mozilla/tests/webdriver/bidi/browsing_context/get_tree/__init__.py b/testing/web-platform/mozilla/tests/webdriver/bidi/browsing_context/get_tree/__init__.py diff --git a/testing/web-platform/mozilla/tests/webdriver/bidi/browsing_context/get_tree/moz_scope.py b/testing/web-platform/mozilla/tests/webdriver/bidi/browsing_context/get_tree/moz_scope.py @@ -0,0 +1,181 @@ +import pytest +from tests.bidi.browsing_context import assert_browsing_context +from webdriver.bidi import error + +pytestmark = pytest.mark.asyncio + + +@pytest.fixture +def browser_chrome_url(current_session): + if current_session.capabilities["platformName"] == "android": + return "chrome://geckoview/content/geckoview.xhtml" + else: + return "chrome://browser/content/browser.xhtml" + + +async def test_without_system_access(bidi_session): + with pytest.raises(error.UnsupportedOperationException): + await bidi_session.browsing_context.get_tree( + _extension_params={"moz:scope": "chrome"} + ) + + +@pytest.mark.allow_system_access +async def test_multiple_browser_windows( + bidi_session, new_window, top_context, browser_chrome_url +): + # Retrieve the top-level browsing context for all the open browser windows + parent_contexts = await bidi_session.browsing_context.get_tree( + max_depth=0, _extension_params={"moz:scope": "chrome"} + ) + + assert len(parent_contexts) == 2 + + assert_browsing_context( + parent_contexts[0], + None, + children=None, + parent=None, + url=browser_chrome_url, + client_window=top_context["clientWindow"], + ) + assert parent_contexts[0]["context"] != top_context["context"] + + assert parent_contexts[0]["moz:scope"] == "chrome" + + assert_browsing_context( + parent_contexts[1], + None, + children=None, + parent=None, + url=browser_chrome_url, + client_window=new_window["clientWindow"], + ) + assert parent_contexts[1]["context"] != new_window["context"] + assert parent_contexts[1]["clientWindow"] != top_context["clientWindow"] + + assert parent_contexts[1]["moz:scope"] == "chrome" + + assert parent_contexts[0]["context"] != parent_contexts[1]["context"] + + +@pytest.mark.allow_system_access +async def test_custom_chrome_window_without_iframes( + bidi_session, top_context, default_chrome_handler, new_chrome_window +): + # Bug 1762066: Skip this test on Android, as it currently causes the browser to crash + # when attempting to register a chrome handler for files that cannot be found. + # Since we cannot disable the test via the manifest, we return early instead. + if bidi_session.capabilities["platformName"] == "android": + return + + chrome_url = f"{default_chrome_handler}test_dialog.xhtml" + new_window = new_chrome_window(chrome_url) + + # Retrieve all browsing contexts for the custom chrome window + parent_contexts = await bidi_session.browsing_context.get_tree( + root=new_window.id, _extension_params={"moz:scope": "chrome"} + ) + + assert len(parent_contexts) == 1 + + assert_browsing_context( + parent_contexts[0], + None, + children=0, + parent=None, + url=chrome_url, + client_window=None, + ) + + assert len(parent_contexts) == 1 + + assert parent_contexts[0]["clientWindow"] != top_context["clientWindow"] + + assert parent_contexts[0]["moz:scope"] == "chrome" + assert parent_contexts[0]["moz:name"] == "null" + + +@pytest.mark.allow_system_access +async def test_custom_chrome_window_with_iframes( + bidi_session, top_context, default_chrome_handler, new_chrome_window +): + # Bug 1762066: Skip this test on Android, as it currently causes the browser to crash + # when attempting to register a chrome handler for files that cannot be found. + # Since we cannot disable the test via the manifest, we return early instead. + if bidi_session.capabilities["platformName"] == "android": + return + + chrome_url = f"{default_chrome_handler}test.xhtml" + iframe_url = f"{default_chrome_handler}test_iframe.xhtml" + nested_iframe_url = f"{default_chrome_handler}test_nested_iframe.xhtml" + + new_window = new_chrome_window(chrome_url) + + # Retrieve all browsing contexts for the custom chrome window + parent_contexts = await bidi_session.browsing_context.get_tree( + root=new_window.id, _extension_params={"moz:scope": "chrome"} + ) + + assert_browsing_context( + parent_contexts[0], + None, + children=2, + parent=None, + url=chrome_url, + client_window=None, + ) + assert parent_contexts[0]["clientWindow"] != top_context["clientWindow"] + + assert parent_contexts[0]["moz:scope"] == "chrome" + assert parent_contexts[0]["moz:name"] == "null" + + iframes = parent_contexts[0]["children"] + + # First iframe has no children + assert_browsing_context( + iframes[0], + None, + children=0, + parent_expected=False, + url=iframe_url, + client_window=parent_contexts[0]["clientWindow"], + ) + assert iframes[0]["context"] != parent_contexts[0]["context"] + + assert iframes[0]["moz:scope"] == "chrome" + assert iframes[0]["moz:name"] == "iframe" + + # Second iframe has a children + assert_browsing_context( + iframes[1], + None, + children=1, + parent_expected=False, + url=nested_iframe_url, + client_window=parent_contexts[0]["clientWindow"], + ) + assert iframes[1]["context"] != parent_contexts[0]["context"] + assert iframes[1]["context"] != iframes[0]["context"] + + assert iframes[1]["moz:scope"] == "chrome" + assert iframes[1]["moz:name"] == "iframe-nested" + + nested_iframes = iframes[1]["children"] + + # Second iframe has a children + assert_browsing_context( + nested_iframes[0], + None, + children=0, + parent_expected=False, + url=iframe_url, + client_window=parent_contexts[0]["clientWindow"], + ) + assert iframes[1]["context"] != parent_contexts[0]["context"] + assert iframes[1]["context"] != iframes[0]["context"] + assert nested_iframes[0]["context"] != iframes[1]["context"] + assert nested_iframes[0]["context"] != parent_contexts[0]["context"] + + assert nested_iframes[0]["moz:scope"] == "chrome" + assert nested_iframes[0]["moz:name"] == "iframe"