From 59203c63bb777a3bacec32fb8830fba33540e809 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:35:29 +0200 Subject: Adding upstream version 127.0. Signed-off-by: Daniel Baumann --- .../capture_screenshot/capture_screenshot.py | 28 ++- .../browsing_context/capture_screenshot/clip.py | 39 ++++ .../bidi/browsing_context/locate_nodes/invalid.py | 28 ++- .../bidi/browsing_context/locate_nodes/locator.py | 76 +++++++- .../locate_nodes/max_node_count.py | 123 ++++++++++++- .../browsing_context/locate_nodes/start_nodes.py | 69 ++++++- .../set_viewport/device_pixel_ratio.py | 53 ++++++ .../bidi/browsing_context/set_viewport/viewport.py | 4 +- .../external/permissions/set_permission/invalid.py | 5 +- .../permissions/set_permission/set_permission.py | 20 +-- .../tests/bidi/input/perform_actions/key_events.py | 8 +- .../tests/bidi/input/perform_actions/wheel.py | 26 +++ .../response_completed/response_completed.py | 2 +- .../response_completed_status.py | 55 ------ .../network/response_started/response_started.py | 26 +++ .../tests/webdriver/tests/bidi/storage/__init__.py | 2 +- .../webdriver/tests/classic/add_cookie/add.py | 4 +- .../tests/classic/element_clear/__init__.py | 5 + .../webdriver/tests/classic/element_clear/clear.py | 66 +------ .../tests/classic/element_clear/disabled.py | 113 ++++++++++++ .../tests/classic/element_clear/user_prompts.py | 8 +- .../tests/classic/element_click/navigate.py | 6 +- .../tests/classic/get_element_text/get.py | 21 ++- .../tests/classic/get_named_cookie/get.py | 4 +- .../tests/classic/is_element_enabled/__init__.py | 8 + .../tests/classic/is_element_enabled/enabled.py | 199 +++++++++++++++------ .../classic/is_element_enabled/user_prompts.py | 11 +- .../tests/classic/perform_actions/wheel.py | 16 ++ .../tests/webdriver/tests/support/dom.py | 29 +++ .../tests/webdriver/tests/support/fixtures_bidi.py | 12 +- .../tests/support/html/test_actions_scroll.html | 16 +- 31 files changed, 833 insertions(+), 249 deletions(-) delete mode 100644 testing/web-platform/tests/webdriver/tests/bidi/network/response_completed/response_completed_status.py create mode 100644 testing/web-platform/tests/webdriver/tests/classic/element_clear/disabled.py create mode 100644 testing/web-platform/tests/webdriver/tests/support/dom.py (limited to 'testing/web-platform/tests/webdriver') diff --git a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/capture_screenshot/capture_screenshot.py b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/capture_screenshot/capture_screenshot.py index 40497ce6ac..414f5ae2d0 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/capture_screenshot/capture_screenshot.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/capture_screenshot/capture_screenshot.py @@ -1,6 +1,6 @@ import pytest -from math import floor +from math import ceil, floor from tests.support.image import png_dimensions from . import get_physical_viewport_dimensions @@ -79,3 +79,29 @@ async def test_capture_with_viewport(bidi_session, new_tab, delta_width, delta_h result = await bidi_session.browsing_context.capture_screenshot( context=new_tab["context"]) assert png_dimensions(result) == (expected_size["width"], expected_size["height"]) + + +@pytest.mark.parametrize("dpr", [0.5, 2]) +@pytest.mark.asyncio +async def test_capture_with_different_dpr(bidi_session, new_tab, inline, dpr): + page = inline("
") + await bidi_session.browsing_context.navigate( + context=new_tab["context"], url=page, wait="complete" + ) + + original_viewport = await get_viewport_dimensions(bidi_session, new_tab) + + await bidi_session.browsing_context.set_viewport( + context=new_tab["context"], + device_pixel_ratio=dpr) + + expected_width = original_viewport["width"] * dpr + expected_height = original_viewport["height"] * dpr + + data = await bidi_session.browsing_context.capture_screenshot(context=new_tab["context"]) + (actual_width, actual_height) = png_dimensions(data) + # The rounding is implementation-specific and can be either floor, ceil or round depending on the browser + # implementation. Tolerate any value between floor and ceil. + assert floor(expected_width) <= actual_width <= ceil(expected_width) + assert floor(expected_height) <= actual_height <= ceil(expected_height) + diff --git a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/capture_screenshot/clip.py b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/capture_screenshot/clip.py index 8300e962b9..67d4b0d06c 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/capture_screenshot/clip.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/capture_screenshot/clip.py @@ -373,3 +373,42 @@ async def test_clip_element_outside_of_window_viewport( comparison = await compare_png_bidi(reference_data, data) assert comparison.equal() + + +@pytest.mark.parametrize("dpr", [0.5, 2]) +async def test_clip_with_different_dpr(bidi_session, new_tab, inline, compare_png_bidi, dpr): + div_size = {"width": 100, "height": 100} + + reference_page = inline(f"""
""") + await bidi_session.browsing_context.navigate( + context=new_tab["context"], url=reference_page, wait="complete" + ) + element = await bidi_session.script.evaluate( + await_promise=False, + expression="document.querySelector('div')", + target=ContextTarget(new_tab["context"]), + ) + reference_data = await bidi_session.browsing_context.capture_screenshot( + context=new_tab["context"], clip=ElementOptions(element=element) + ) + + page = inline(f"""
""") + await bidi_session.browsing_context.navigate( + context=new_tab["context"], url=page, wait="complete" + ) + + await bidi_session.browsing_context.set_viewport( + context=new_tab["context"], + device_pixel_ratio=dpr) + + element = await bidi_session.script.evaluate( + await_promise=False, + expression="document.querySelector('div')", + target=ContextTarget(new_tab["context"]), + ) + data = await bidi_session.browsing_context.capture_screenshot( + context=new_tab["context"], clip=ElementOptions(element=element) + ) + + comparison = await compare_png_bidi(data, reference_data) + assert comparison.equal() diff --git a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/locate_nodes/invalid.py b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/locate_nodes/invalid.py index ecd3173e87..52aabca267 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/locate_nodes/invalid.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/locate_nodes/invalid.py @@ -46,10 +46,36 @@ async def test_params_locator_type_invalid_value(bidi_session, inline, top_conte ) +@pytest.mark.parametrize("type", ["css", "xpath", "innerText"]) +@pytest.mark.parametrize("value", [None, False, 42, {}, []]) +async def test_params_locator_value_invalid_type( + bidi_session, inline, top_context, type, value +): + await navigate_to_page(bidi_session, inline, top_context) + + with pytest.raises(error.InvalidArgumentException): + await bidi_session.browsing_context.locate_nodes( + context=top_context["context"], locator={"type": type, "value": value} + ) + + +@pytest.mark.parametrize("value", [None, False, 42, {}, []]) +async def test_params_locator_accessability_value_invalid_type( + bidi_session, inline, top_context, value +): + await navigate_to_page(bidi_session, inline, top_context) + + with pytest.raises(error.InvalidArgumentException): + await bidi_session.browsing_context.locate_nodes( + context=top_context["context"], locator={"type": "accessability", "value": value} + ) + + @pytest.mark.parametrize("type,value", [ ("css", "a*b"), ("xpath", ""), - ("innerText", "") + ("innerText", ""), + ("accessibility", {}) ]) async def test_params_locator_value_invalid_value(bidi_session, inline, top_context, type, value): await navigate_to_page(bidi_session, inline, top_context) diff --git a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/locate_nodes/locator.py b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/locate_nodes/locator.py index e560fa9239..66c512d792 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/locate_nodes/locator.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/locate_nodes/locator.py @@ -6,11 +6,17 @@ from ... import any_string, recursive_compare @pytest.mark.parametrize("type,value", [ ("css", "div"), ("xpath", "//div"), - ("innerText", "foobarBARbaz") + ("innerText", "foobarBARbaz"), + ("accessibility", {"role": "banner"}), + ("accessibility", {"name": "foo"}), + ("accessibility", {"role": "banner", "name": "foo"}), ]) @pytest.mark.asyncio async def test_find_by_locator(bidi_session, inline, top_context, type, value): - url = inline("""
foobarBARbaz
foobarBARbaz
""") + url = inline(""" +
foobarBARbaz
+
foobarBARbaz
+ """) await bidi_session.browsing_context.navigate( context=top_context["context"], url=url, wait="complete" ) @@ -165,3 +171,69 @@ async def test_find_by_inner_text(bidi_session, inline, top_context, locator, ex ) recursive_compare(expected, result["nodes"]) + + +@pytest.mark.parametrize( + "html,locator_value,expected_node_local_name", + [ + ( + "
foo
bar
", + {"role": "article"}, + "article", + ), + ( + "", + {"role": "searchbox"}, + "input", + ), + ( + "", + {"name": "Ok"}, + "button", + ), + ( + "
ok
go
", + {"name": "ok go"}, + "button", + ), + ( + "", + {"name": "foo"}, + "button", + ), + ( + "
", + {"role": "banner", "name": "foo"}, + "div", + ), + ], +) +@pytest.mark.asyncio +async def test_locate_by_accessibility_attributes( + bidi_session, + inline, + top_context, + html, + locator_value, + expected_node_local_name, +): + await bidi_session.browsing_context.navigate( + context=top_context["context"], url=inline(html), wait="complete" + ) + + expected = [ + { + "type": "node", + "value": { + "attributes": {"data-class": "one"}, + "localName": expected_node_local_name, + }, + } + ] + + result = await bidi_session.browsing_context.locate_nodes( + context=top_context["context"], + locator={"type": "accessibility", "value": locator_value}, + ) + + recursive_compare(expected, result["nodes"]) diff --git a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/locate_nodes/max_node_count.py b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/locate_nodes/max_node_count.py index 4652026e96..9d9c05260b 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/locate_nodes/max_node_count.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/locate_nodes/max_node_count.py @@ -43,6 +43,45 @@ from ... import any_string, recursive_compare }, }] ), + ("accessibility", {"role": "banner"}, 1, [ + { + "type": "node", + "sharedId": any_string, + "value": { + "attributes": {"data-class":"one"}, + "childNodeCount": 1, + "localName": "div", + "namespaceURI": "http://www.w3.org/1999/xhtml", + "nodeType": 1, + }, + }] + ), + ("accessibility", {"name": "bar"}, 1, [ + { + "type": "node", + "sharedId": any_string, + "value": { + "attributes": {"data-class":"one"}, + "childNodeCount": 1, + "localName": "div", + "namespaceURI": "http://www.w3.org/1999/xhtml", + "nodeType": 1, + }, + }] + ), + ("accessibility", {"role": "banner", "name": "bar"}, 1, [ + { + "type": "node", + "sharedId": any_string, + "value": { + "attributes": {"data-class":"one"}, + "childNodeCount": 1, + "localName": "div", + "namespaceURI": "http://www.w3.org/1999/xhtml", + "nodeType": 1, + }, + }] + ), ("css", "div", 10, [ { "type": "node", @@ -114,18 +153,96 @@ from ... import any_string, recursive_compare "nodeType": 1, }, }] - ) + ), + ("accessibility", {"role": "banner"}, 10, [ + { + "type": "node", + "sharedId": any_string, + "value": { + "attributes": {"data-class":"one"}, + "childNodeCount": 1, + "localName": "div", + "namespaceURI": "http://www.w3.org/1999/xhtml", + "nodeType": 1, + }, + }, { + "type": "node", + "sharedId": any_string, + "value": { + "attributes": {"data-class":"two"}, + "childNodeCount": 1, + "localName": "div", + "namespaceURI": "http://www.w3.org/1999/xhtml", + "nodeType": 1, + }, + }] + ), + ("accessibility", {"name": "bar"}, 10, [ + { + "type": "node", + "sharedId": any_string, + "value": { + "attributes": {"data-class":"one"}, + "childNodeCount": 1, + "localName": "div", + "namespaceURI": "http://www.w3.org/1999/xhtml", + "nodeType": 1, + }, + }, { + "type": "node", + "sharedId": any_string, + "value": { + "attributes": {"data-class":"two"}, + "childNodeCount": 1, + "localName": "div", + "namespaceURI": "http://www.w3.org/1999/xhtml", + "nodeType": 1, + }, + }] + ), + ("accessibility", {"role": "banner", "name": "bar"}, 10, [ + { + "type": "node", + "sharedId": any_string, + "value": { + "attributes": {"data-class":"one"}, + "childNodeCount": 1, + "localName": "div", + "namespaceURI": "http://www.w3.org/1999/xhtml", + "nodeType": 1, + }, + }, { + "type": "node", + "sharedId": any_string, + "value": { + "attributes": {"data-class":"two"}, + "childNodeCount": 1, + "localName": "div", + "namespaceURI": "http://www.w3.org/1999/xhtml", + "nodeType": 1, + }, + }] + ), ], ids=[ "css_single", "xpath_single", "inner_text_single", + "accessibility_role_single", + "accessibility_name_single", + "accessibility_role_name_single", "css_multiple", "xpath_multiple", - "inner_text_multiple" + "inner_text_multiple", + "accessibility_role_multiple", + "accessibility_name_multiple", + "accessibility_role_name_multiple", ]) @pytest.mark.asyncio async def test_find_by_locator_limit_return_count(bidi_session, inline, top_context, type, value, max_count, expected): - url = inline("""
foo
foo
""") + url = inline(""" +
foo
+
foo
+ """) await bidi_session.browsing_context.navigate( context=top_context["context"], url=url, wait="complete" ) diff --git a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/locate_nodes/start_nodes.py b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/locate_nodes/start_nodes.py index 707d83a337..f44a6d4857 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/locate_nodes/start_nodes.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/locate_nodes/start_nodes.py @@ -92,13 +92,59 @@ from ... import any_string, recursive_compare "namespaceURI": "http://www.w3.org/1999/xhtml", "nodeType": 1, } - }]) + }]), + ("accessibility", {"role": "banner"}, [{ + "type": "node", + "sharedId": any_string, + "value": { + "attributes": {"data-class":"one"}, + "childNodeCount": 1, + "localName": "p", + "namespaceURI": "http://www.w3.org/1999/xhtml", + "nodeType": 1, + } + }, + { + "type": "node", + "sharedId": any_string, + "value": { + "attributes": {"data-class":"two"}, + "childNodeCount": 1, + "localName": "p", + "namespaceURI": "http://www.w3.org/1999/xhtml", + "nodeType": 1, + } + }]), + ("accessibility", {"name": "bar"}, [{ + "type": "node", + "sharedId": any_string, + "value": { + "attributes": {"data-class":"one"}, + "childNodeCount": 1, + "localName": "p", + "namespaceURI": "http://www.w3.org/1999/xhtml", + "nodeType": 1, + } + } + ]), + ("accessibility", {"role": "banner", "name": "bar"}, [{ + "type": "node", + "sharedId": any_string, + "value": { + "attributes": {"data-class":"one"}, + "childNodeCount": 1, + "localName": "p", + "namespaceURI": "http://www.w3.org/1999/xhtml", + "nodeType": 1, + } + } + ]) ]) @pytest.mark.asyncio async def test_locate_with_context_nodes(bidi_session, inline, top_context, type, value, expected): url = inline("""
-

foo

-

foo

+

foo

+

foo

bar @@ -125,14 +171,23 @@ async def test_locate_with_context_nodes(bidi_session, inline, top_context, type @pytest.mark.parametrize("type,value", [ ("css", "p[data-class='one']"), ("xpath", ".//p[@data-class='one']"), - ("innerText", "foo") + ("innerText", "foo"), + ("accessibility", {"role": "banner"}), + ("accessibility", {"name": "bar"}), + ("accessibility", {"role": "banner", "name": "bar"}), ]) @pytest.mark.asyncio async def test_locate_with_multiple_context_nodes(bidi_session, inline, top_context, type, value): url = inline(""" -

foo

bar

-

foo

bar

- """) +
+

foo

+

bar

+
+
+

foo

+

bar

+
+ """) await bidi_session.browsing_context.navigate( context=top_context["context"], url=url, wait="complete" ) diff --git a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/set_viewport/device_pixel_ratio.py b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/set_viewport/device_pixel_ratio.py index e4db779bd5..88de2de334 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/set_viewport/device_pixel_ratio.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/set_viewport/device_pixel_ratio.py @@ -1,4 +1,5 @@ import pytest +from webdriver.bidi.modules.script import ContextTarget from ... import get_device_pixel_ratio, get_viewport_dimensions @@ -45,6 +46,14 @@ async def test_device_pixel_ratio_with_viewport( assert await get_viewport_dimensions(bidi_session, new_tab) == test_viewport assert await get_device_pixel_ratio(bidi_session, new_tab) == device_pixel_ratio + result = await bidi_session.script.evaluate( + await_promise=False, + expression="window.devicePixelRatio", + target=ContextTarget(new_tab["context"]), + ) + + assert result == {"type": "number", "value": device_pixel_ratio} + @pytest.mark.asyncio async def test_reset_device_pixel_ratio(bidi_session, inline, new_tab): @@ -68,3 +77,47 @@ async def test_reset_device_pixel_ratio(bidi_session, inline, new_tab): device_pixel_ratio=None) assert await get_device_pixel_ratio(bidi_session, new_tab) == original_dpr + + +@pytest.mark.asyncio +@pytest.mark.parametrize("device_pixel_ratio", [0.5, 2]) +@pytest.mark.parametrize( + "use_horizontal_scrollbar, use_vertical_scrollbar", + [ + (True, False), + (False, True), + (True, True), + ], + ids=["horizontal", "vertical", "both"], +) +async def test_device_pixel_ratio_with_scrollbar( + bidi_session, + inline, + new_tab, + device_pixel_ratio, + use_horizontal_scrollbar, + use_vertical_scrollbar, +): + viewport_dimensions = await get_viewport_dimensions(bidi_session, new_tab) + + width = 100 + if use_horizontal_scrollbar: + width = viewport_dimensions["width"] + 100 + + height = 100 + if use_vertical_scrollbar: + height = viewport_dimensions["height"] + 100 + + html = f"""
foo
""" + page_url = inline(html) + + await bidi_session.browsing_context.navigate( + context=new_tab["context"], url=page_url, wait="complete" + ) + + await bidi_session.browsing_context.set_viewport( + context=new_tab["context"], device_pixel_ratio=device_pixel_ratio + ) + + assert await get_device_pixel_ratio(bidi_session, new_tab) == device_pixel_ratio + assert await get_viewport_dimensions(bidi_session, new_tab) == viewport_dimensions diff --git a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/set_viewport/viewport.py b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/set_viewport/viewport.py index 2e8126b1f8..e9ff8517f2 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/set_viewport/viewport.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/set_viewport/viewport.py @@ -243,6 +243,6 @@ async def test_with_scrollbars( # The side which has scrollbar takes up space on the other side # (e.g. if we have a horizontal scroll height is going to be smaller than viewport height) if use_horizontal_scrollbar: - assert viewport_without_scrollbar["height"] < test_viewport["height"] + assert viewport_without_scrollbar["height"] <= test_viewport["height"] if use_vertical_scrollbar: - assert viewport_without_scrollbar["width"] < test_viewport["width"] + assert viewport_without_scrollbar["width"] <= test_viewport["width"] diff --git a/testing/web-platform/tests/webdriver/tests/bidi/external/permissions/set_permission/invalid.py b/testing/web-platform/tests/webdriver/tests/bidi/external/permissions/set_permission/invalid.py index 5397dc7b62..d717216072 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/external/permissions/set_permission/invalid.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/external/permissions/set_permission/invalid.py @@ -4,6 +4,7 @@ from webdriver.bidi.undefined import UNDEFINED pytestmark = pytest.mark.asyncio + @pytest.mark.parametrize("descriptor", [False, "SOME_STRING", 42, {}, [], {"name": 23}, None, UNDEFINED]) async def test_params_descriptor_invalid_type(bidi_session, descriptor): with pytest.raises(error.InvalidArgumentException): @@ -54,8 +55,8 @@ async def test_params_origin_invalid_type(bidi_session, origin): ) -@pytest.mark.parametrize("user_context", [False, 42, {}, [], None]) -async def test_params_origin_invalid_type(bidi_session, user_context): +@pytest.mark.parametrize("user_context", [False, 42, {}, []]) +async def test_params_user_context_invalid_type(bidi_session, user_context): with pytest.raises(error.InvalidArgumentException): await bidi_session.permissions.set_permission( descriptor={"name": "geolocation"}, diff --git a/testing/web-platform/tests/webdriver/tests/bidi/external/permissions/set_permission/set_permission.py b/testing/web-platform/tests/webdriver/tests/bidi/external/permissions/set_permission/set_permission.py index 45c50dbf88..18f8e6fed0 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/external/permissions/set_permission/set_permission.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/external/permissions/set_permission/set_permission.py @@ -1,10 +1,10 @@ import pytest -import webdriver.bidi.error as error from . import get_context_origin, get_permission_state pytestmark = pytest.mark.asyncio + @pytest.mark.asyncio async def test_set_permission(bidi_session, new_tab, url): test_url = url("/common/blank.html", protocol="https") @@ -43,24 +43,6 @@ async def test_set_permission(bidi_session, new_tab, url): assert await get_permission_state(bidi_session, new_tab, "geolocation") == "prompt" -@pytest.mark.asyncio -async def test_set_permission_insecure_context(bidi_session, new_tab, url): - test_url = url("/common/blank.html", protocol="http") - await bidi_session.browsing_context.navigate( - context=new_tab["context"], - url=test_url, - wait="complete", - ) - - origin = await get_context_origin(bidi_session, new_tab) - - with pytest.raises(error.InvalidArgumentException): - await bidi_session.permissions.set_permission( - descriptor={"name": "push"}, - state="granted", - origin=origin, - ) - @pytest.mark.asyncio async def test_set_permission_new_context(bidi_session, new_tab, url): test_url = url("/common/blank.html", protocol="https") diff --git a/testing/web-platform/tests/webdriver/tests/bidi/input/perform_actions/key_events.py b/testing/web-platform/tests/webdriver/tests/bidi/input/perform_actions/key_events.py index e93c132e0a..275b542b11 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/input/perform_actions/key_events.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/input/perform_actions/key_events.py @@ -23,7 +23,7 @@ pytestmark = pytest.mark.asyncio ) async def test_non_printable_key_sends_events( - bidi_session, top_context, key, event + bidi_session, top_context, setup_key_test, key, event ): code = ALL_EVENTS[event]["code"] value = ALL_EVENTS[event]["key"] @@ -142,7 +142,7 @@ async def test_key_printable_key( @pytest.mark.parametrize("use_keyup", [True, False]) -async def test_key_printable_sequence(bidi_session, top_context, use_keyup): +async def test_key_printable_sequence(bidi_session, top_context, setup_key_test, use_keyup): actions = Actions() actions.add_key() if use_keyup: @@ -229,7 +229,7 @@ async def test_key_special_key_sends_keydown( assert len(keys_value) == 0 -async def test_key_space(bidi_session, top_context): +async def test_key_space(bidi_session, top_context, setup_key_test): actions = Actions() ( actions.add_key() @@ -254,7 +254,7 @@ async def test_key_space(bidi_session, top_context): assert events[0] == events[1] -async def test_keyup_only_sends_no_events(bidi_session, top_context): +async def test_keyup_only_sends_no_events(bidi_session, top_context, setup_key_test): actions = Actions() actions.add_key().key_up("a") await bidi_session.input.perform_actions( diff --git a/testing/web-platform/tests/webdriver/tests/bidi/input/perform_actions/wheel.py b/testing/web-platform/tests/webdriver/tests/bidi/input/perform_actions/wheel.py index 4f897479e2..ee0d4d4600 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/input/perform_actions/wheel.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/input/perform_actions/wheel.py @@ -4,6 +4,7 @@ from webdriver.bidi.error import NoSuchFrameException from webdriver.bidi.modules.input import Actions, get_element_origin from webdriver.bidi.modules.script import ContextTarget +from tests.support.keys import Keys from .. import get_events, get_object_from_context from . import get_shadow_root_from_test_page @@ -159,3 +160,28 @@ async def test_scroll_shadow_tree( assert events[0]["deltaX"] >= 5 assert events[0]["deltaY"] >= 10 assert events[0]["target"] == "scrollableShadowTreeContent" + + +async def test_scroll_with_key_pressed( + bidi_session, setup_wheel_test, top_context, get_element +): + scrollable = await get_element("#scrollable") + + actions = Actions() + actions.add_key().key_down(Keys.R_SHIFT) + actions.add_wheel().scroll( + x=0, + y=0, + delta_x=5, + delta_y=10, + origin=get_element_origin(scrollable), + ) + actions.add_key().key_up(Keys.R_SHIFT) + + await bidi_session.input.perform_actions( + actions=actions, context=top_context["context"] + ) + events = await get_events(bidi_session, top_context["context"]) + assert len(events) == 1 + assert events[0]["type"] == "wheel" + assert events[0]["shiftKey"] == True diff --git a/testing/web-platform/tests/webdriver/tests/bidi/network/response_completed/response_completed.py b/testing/web-platform/tests/webdriver/tests/bidi/network/response_completed/response_completed.py index 56b9461642..f17a522766 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/network/response_completed/response_completed.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/network/response_completed/response_completed.py @@ -159,7 +159,7 @@ async def test_load_page_twice( @pytest.mark.parametrize( "status, status_text", - [(status, text) for (status, text) in HTTP_STATUS_AND_STATUS_TEXT if status not in [101, 407]], + HTTP_STATUS_AND_STATUS_TEXT, ) @pytest.mark.asyncio async def test_response_status( diff --git a/testing/web-platform/tests/webdriver/tests/bidi/network/response_completed/response_completed_status.py b/testing/web-platform/tests/webdriver/tests/bidi/network/response_completed/response_completed_status.py deleted file mode 100644 index 36e3da667e..0000000000 --- a/testing/web-platform/tests/webdriver/tests/bidi/network/response_completed/response_completed_status.py +++ /dev/null @@ -1,55 +0,0 @@ -# TODO(#42482): Merge this file with response_completed.py -# -# The status codes in this file are currently problematic in some implementations. -# -# The only mechanism currently provided by WPT to disable subtests with -# expectations is to disable the entire file. As such, this file is a copy of -# response_completed.py with the problematic status codes extracted. -# -# Once it is possible to disable subtests, this file should be merged with -# response_completed.py. - -import pytest - -from .. import ( - assert_response_event, - HTTP_STATUS_AND_STATUS_TEXT, - RESPONSE_COMPLETED_EVENT, -) - - -@pytest.mark.parametrize( - "status, status_text", - [(status, text) for (status, text) in HTTP_STATUS_AND_STATUS_TEXT if status in [101, 407]], -) -@pytest.mark.asyncio -async def test_response_status( - wait_for_event, wait_for_future_safe, url, fetch, setup_network_test, status, status_text -): - status_url = url( - f"/webdriver/tests/support/http_handlers/status.py?status={status}&nocache={RESPONSE_COMPLETED_EVENT}" - ) - - network_events = await setup_network_test(events=[RESPONSE_COMPLETED_EVENT]) - events = network_events[RESPONSE_COMPLETED_EVENT] - - on_response_completed = wait_for_event(RESPONSE_COMPLETED_EVENT) - await fetch(status_url) - await wait_for_future_safe(on_response_completed) - - assert len(events) == 1 - expected_request = {"method": "GET", "url": status_url} - expected_response = { - "url": status_url, - "fromCache": False, - "mimeType": "text/plain", - "status": status, - "statusText": status_text, - "protocol": "http/1.1", - } - assert_response_event( - events[0], - expected_request=expected_request, - expected_response=expected_response, - redirect_count=0, - ) diff --git a/testing/web-platform/tests/webdriver/tests/bidi/network/response_started/response_started.py b/testing/web-platform/tests/webdriver/tests/bidi/network/response_started/response_started.py index 6c10714ca8..9aa77739ab 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/network/response_started/response_started.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/network/response_started/response_started.py @@ -135,6 +135,32 @@ async def test_load_page_twice( ) +@pytest.mark.asyncio +async def test_request_bodysize( + wait_for_event, wait_for_future_safe, url, fetch, setup_network_test +): + html_url = url(PAGE_EMPTY_HTML) + + network_events = await setup_network_test(events=[RESPONSE_STARTED_EVENT]) + events = network_events[RESPONSE_STARTED_EVENT] + + on_before_request_sent = wait_for_event(RESPONSE_STARTED_EVENT) + await fetch(html_url, method="POST", post_data="{'a': 1}") + await wait_for_future_safe(on_before_request_sent) + + assert len(events) == 1 + expected_request = { + "method": "POST", + "url": html_url, + } + assert_response_event( + events[0], + expected_request=expected_request, + redirect_count=0, + ) + assert events[0]["request"]["bodySize"] > 0 + + @pytest.mark.parametrize( "status, status_text", HTTP_STATUS_AND_STATUS_TEXT, diff --git a/testing/web-platform/tests/webdriver/tests/bidi/storage/__init__.py b/testing/web-platform/tests/webdriver/tests/bidi/storage/__init__.py index 4ca0f7bdd7..56ea539914 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/storage/__init__.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/storage/__init__.py @@ -78,7 +78,7 @@ def create_cookie( def generate_expiry_date(day_diff=1): return ( - (datetime.utcnow() + timedelta(days=day_diff)) + (datetime.now(timezone.utc) + timedelta(days=day_diff)) .replace(microsecond=0) .replace(tzinfo=timezone.utc) ) diff --git a/testing/web-platform/tests/webdriver/tests/classic/add_cookie/add.py b/testing/web-platform/tests/webdriver/tests/classic/add_cookie/add.py index 24b71c52fd..60b67d051b 100644 --- a/testing/web-platform/tests/webdriver/tests/classic/add_cookie/add.py +++ b/testing/web-platform/tests/webdriver/tests/classic/add_cookie/add.py @@ -1,6 +1,6 @@ import pytest -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from webdriver.transport import Response @@ -154,7 +154,7 @@ def test_add_cookie_for_ip(session, server_config): def test_add_non_session_cookie(session, url): a_day_from_now = int( - (datetime.utcnow() + timedelta(days=1) - datetime.utcfromtimestamp(0)).total_seconds()) + (datetime.now(timezone.utc) + timedelta(days=1) - datetime.fromtimestamp(0, timezone.utc)).total_seconds()) new_cookie = { "name": "hello", diff --git a/testing/web-platform/tests/webdriver/tests/classic/element_clear/__init__.py b/testing/web-platform/tests/webdriver/tests/classic/element_clear/__init__.py index e69de29bb2..c84215a636 100644 --- a/testing/web-platform/tests/webdriver/tests/classic/element_clear/__init__.py +++ b/testing/web-platform/tests/webdriver/tests/classic/element_clear/__init__.py @@ -0,0 +1,5 @@ +def element_clear(session, element): + return session.transport.send( + "POST", "/session/{session_id}/element/{element_id}/clear".format( + session_id=session.session_id, + element_id=element.id)) diff --git a/testing/web-platform/tests/webdriver/tests/classic/element_clear/clear.py b/testing/web-platform/tests/webdriver/tests/classic/element_clear/clear.py index 9a0549ce4f..0977f60cb6 100644 --- a/testing/web-platform/tests/webdriver/tests/classic/element_clear/clear.py +++ b/testing/web-platform/tests/webdriver/tests/classic/element_clear/clear.py @@ -8,6 +8,8 @@ from tests.support.asserts import ( assert_in_events, assert_success, ) +from tests.support.dom import BUTTON_TYPES +from . import element_clear @pytest.fixture @@ -19,13 +21,6 @@ def tracked_events(): ] -def element_clear(session, element): - return session.transport.send( - "POST", "/session/{session_id}/element/{element_id}/clear".format( - session_id=session.session_id, - element_id=element.id)) - - @pytest.fixture(scope="session") def text_file(tmpdir_factory): fh = tmpdir_factory.mktemp("tmp").join("hello.txt") @@ -179,31 +174,6 @@ def test_input(session, inline, add_event_listeners, tracked_events, type, value assert_element_has_focus(session.execute_script("return document.body")) -@pytest.mark.parametrize("type", - ["number", - "range", - "email", - "password", - "search", - "tel", - "text", - "url", - "color", - "date", - "datetime", - "datetime-local", - "time", - "month", - "week", - "file"]) -def test_input_disabled(session, inline, type): - session.url = inline("" % type) - element = session.find.css("input", all=False) - - response = element_clear(session, element) - assert_error(response, "invalid element state") - - @pytest.mark.parametrize("type", ["number", "range", @@ -241,14 +211,6 @@ def test_textarea(session, inline, add_event_listeners, tracked_events): assert_in_events(session, ["focus", "change", "blur"]) -def test_textarea_disabled(session, inline): - session.url = inline("") - element = session.find.css("textarea", all=False) - - response = element_clear(session, element) - assert_error(response, "invalid element state") - - def test_textarea_readonly(session, inline): session.url = inline("") element = session.find.css("textarea", all=False) @@ -278,26 +240,12 @@ def test_input_file_multiple(session, text_file, inline): assert element.property("value") == "" -def test_select(session, inline): - session.url = inline(""" - - """) - select = session.find.css("select", all=False) - option = session.find.css("option", all=False) +@pytest.mark.parametrize("type", BUTTON_TYPES) +def test_button(session, inline, type): + session.url = inline(f"""") - button = session.find.css("button", all=False) - - response = element_clear(session, button) + response = element_clear(session, element) assert_error(response, "invalid element state") diff --git a/testing/web-platform/tests/webdriver/tests/classic/element_clear/disabled.py b/testing/web-platform/tests/webdriver/tests/classic/element_clear/disabled.py new file mode 100644 index 0000000000..f0d0fcd9aa --- /dev/null +++ b/testing/web-platform/tests/webdriver/tests/classic/element_clear/disabled.py @@ -0,0 +1,113 @@ +import pytest + +from tests.support.asserts import assert_error, assert_success +from tests.support.dom import BUTTON_TYPES, INPUT_TYPES +from . import element_clear + + +@pytest.mark.parametrize("type", BUTTON_TYPES) +def test_button(session, inline, type): + session.url = inline(f"""