diff options
Diffstat (limited to 'testing/web-platform/tests/webdriver/tests/interop')
4 files changed, 266 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webdriver/tests/interop/__init__.py b/testing/web-platform/tests/webdriver/tests/interop/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testing/web-platform/tests/webdriver/tests/interop/__init__.py diff --git a/testing/web-platform/tests/webdriver/tests/interop/frames.py b/testing/web-platform/tests/webdriver/tests/interop/frames.py new file mode 100644 index 0000000000..b2cafb4987 --- /dev/null +++ b/testing/web-platform/tests/webdriver/tests/interop/frames.py @@ -0,0 +1,37 @@ +import pytest +from webdriver.error import NoSuchWindowException + +from tests.support.sync import AsyncPoll + +pytestmark = pytest.mark.asyncio + + +async def test_classic_switch_to_parent_no_browsing_context(bidi_session, current_session, url): + # With WebDriver classic it cannot be checked if the parent frame is already + # gone before switching to it. To prevent race conditions such a check needs + # to be done via WebDriver BiDi. + current_session.url = url("/webdriver/tests/support/html/frames.html") + + subframe = current_session.find.css("#sub-frame", all=False) + current_session.switch_frame(subframe) + + deleteframe = current_session.find.css("#delete-frame", all=False) + current_session.switch_frame(deleteframe) + + button = current_session.find.css("#remove-top", all=False) + button.click() + + async def is_frame_removed(_): + contexts = await bidi_session.browsing_context.get_tree(root=current_session.window_handle) + return not contexts[0]["children"] + + # Wait until IFrame is gone. + wait = AsyncPoll( + current_session, + timeout=5, + message="IFrame that should be closed is still open", + ) + await wait.until(is_frame_removed) + + with pytest.raises(NoSuchWindowException): + current_session.switch_frame("parent") diff --git a/testing/web-platform/tests/webdriver/tests/interop/shared_id_node.py b/testing/web-platform/tests/webdriver/tests/interop/shared_id_node.py new file mode 100644 index 0000000000..aeb2bc4597 --- /dev/null +++ b/testing/web-platform/tests/webdriver/tests/interop/shared_id_node.py @@ -0,0 +1,101 @@ +import pytest + +from webdriver import ShadowRoot, WebElement +from webdriver.bidi.modules.script import ContextTarget + +pytestmark = pytest.mark.asyncio + +DOCUMENT_FRAGMENT_NODE = 11 +ELEMENT_NODE = 1 + + +async def test_web_element_reference_created_in_classic( + bidi_session, + current_session, + get_test_page, + top_context, +): + current_session.url = get_test_page() + + node = current_session.execute_script( + """return document.querySelector("div#with-children")""" + ) + shared_id = node.id + + # Use element reference from WebDriver classic in WebDriver BiDi + result = await bidi_session.script.call_function( + function_declaration="(node)=>{return node.nodeType}", + arguments=[{"sharedId": shared_id}], + await_promise=False, + target=ContextTarget(top_context["context"]), + ) + + assert result == {"type": "number", "value": ELEMENT_NODE} + + +async def test_web_element_reference_created_in_bidi( + bidi_session, + current_session, + get_test_page, + top_context, +): + current_session.url = get_test_page() + + result = await bidi_session.script.evaluate( + expression="""document.querySelector("div#with-children")""", + target=ContextTarget(top_context["context"]), + await_promise=False, + ) + + nodeType = result["value"]["nodeType"] + assert nodeType == ELEMENT_NODE + + # Use element reference from WebDriver BiDi in WebDriver classic + node = WebElement(current_session, result["sharedId"]) + nodeType = current_session.execute_script( + """return arguments[0].nodeType""", args=(node,) + ) + assert nodeType == ELEMENT_NODE + + +@pytest.mark.parametrize("shadow_root_mode", ["open", "closed"]) +async def test_shadow_root_reference_created_in_classic( + bidi_session, current_session, get_test_page, top_context, shadow_root_mode +): + current_session.url = get_test_page(shadow_root_mode=shadow_root_mode) + + node = current_session.execute_script( + """return document.querySelector("custom-element")""" + ) + shared_id = node.shadow_root.id + + # Use shadow root reference from WebDriver classic in WebDriver BiDi + result = await bidi_session.script.call_function( + function_declaration="(node)=>{return node.nodeType}", + arguments=[{"sharedId": shared_id}], + await_promise=False, + target=ContextTarget(top_context["context"]), + ) + + assert result == {"type": "number", "value": DOCUMENT_FRAGMENT_NODE} + + +@pytest.mark.parametrize("shadow_root_mode", ["open", "closed"]) +async def test_shadow_root_reference_created_in_bidi( + bidi_session, current_session, get_test_page, top_context, shadow_root_mode +): + current_session.url = get_test_page(shadow_root_mode=shadow_root_mode) + + result = await bidi_session.script.evaluate( + expression="""document.querySelector("custom-element")""", + target=ContextTarget(top_context["context"]), + await_promise=False, + ) + shared_id_for_shadow_root = result["value"]["shadowRoot"]["sharedId"] + + # Use shadow root reference from WebDriver BiDi in WebDriver classic + node = ShadowRoot(current_session, shared_id_for_shadow_root) + nodeType = current_session.execute_script( + """return arguments[0].nodeType""", args=(node,) + ) + assert nodeType == DOCUMENT_FRAGMENT_NODE diff --git a/testing/web-platform/tests/webdriver/tests/interop/shared_id_window.py b/testing/web-platform/tests/webdriver/tests/interop/shared_id_window.py new file mode 100644 index 0000000000..d13262b4e5 --- /dev/null +++ b/testing/web-platform/tests/webdriver/tests/interop/shared_id_window.py @@ -0,0 +1,128 @@ +import pytest + +from webdriver import WebFrame, WebWindow +from webdriver.bidi.modules.script import ContextTarget + +pytestmark = pytest.mark.asyncio + + +async def test_top_level_context_id_equals_window_handle(top_context, current_session): + assert top_context["context"] == current_session.window_handle + + +async def test_web_window_reference_created_in_classic( + bidi_session, + current_session, + get_test_page, +): + handle = current_session.new_window(type_hint="tab") + current_session.window_handle = handle + current_session.url = get_test_page() + + expected_test_value = "bar" + window = current_session.execute_script( + f"window.foo = '{expected_test_value}'; return window;" + ) + + contexts = await bidi_session.browsing_context.get_tree() + assert len(contexts) == 2 + + assert window.id == contexts[1]["context"] + + result = await bidi_session.script.evaluate( + expression="window.foo", + target=ContextTarget(window.id), + await_promise=False, + ) + + assert result["value"] == expected_test_value + + +async def test_web_frame_reference_created_in_classic( + bidi_session, + current_session, + get_test_page, +): + handle = current_session.new_window(type_hint="tab") + current_session.window_handle = handle + current_session.url = get_test_page() + + expected_test_value = "foo" + frame = current_session.execute_script( + f"window.frames[0].bar='{expected_test_value}'; return window.frames[0]" + ) + + contexts = await bidi_session.browsing_context.get_tree() + assert len(contexts) == 2 + + assert frame.id == contexts[1]["children"][0]["context"] + + result = await bidi_session.script.evaluate( + expression="window.bar", + target=ContextTarget(frame.id), + await_promise=False, + ) + + assert result["value"] == expected_test_value + + +async def test_web_window_reference_created_in_bidi( + bidi_session, + current_session, + get_test_page, + new_tab +): + await bidi_session.browsing_context.navigate( + context=new_tab["context"], + url=get_test_page(), + wait="complete" + ) + + expected_test_value = "bar" + result = await bidi_session.script.evaluate( + expression=f"window.xyz = '{expected_test_value}'; window;", + target=ContextTarget(new_tab["context"]), + await_promise=False, + ) + + context_id = result["value"]["context"] + + # Use window reference from WebDriver BiDi in WebDriver classic + current_session.window_handle = new_tab["context"] + window = WebWindow(current_session, context_id) + test_value = current_session.execute_script( + """return arguments[0].xyz""", args=(window,) + ) + + assert test_value == expected_test_value + + +async def test_web_frame_reference_created_in_bidi( + bidi_session, + current_session, + get_test_page, + new_tab +): + await bidi_session.browsing_context.navigate( + context=new_tab["context"], + url=get_test_page(), + wait="complete" + ) + + expected_test_value = "foo" + result = await bidi_session.script.evaluate( + expression=f"window.frames[0].baz='{expected_test_value}'; window.frames[0];", + target=ContextTarget(new_tab["context"]), + await_promise=False, + ) + + context_id = result["value"]["context"] + + # Use window reference from WebDriver BiDi in WebDriver classic + current_session.window_handle = new_tab["context"] + window = WebFrame(current_session, context_id) + test_value = current_session.execute_script( + """return arguments[0].baz""", args=(window,) + ) + + assert test_value == expected_test_value |