diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /testing/web-platform/tests/webdriver | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webdriver')
31 files changed, 833 insertions, 249 deletions
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("<div style='background-color: black; width: 100px; height: 100px;'></div>") + 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"""<div style='background-color: black; width: {div_size["width"]*dpr}px; height: {div_size["height"]*dpr}px;'></div>""") + 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"""<div style='background-color: black; width: {div_size["width"]}px; height: {div_size["height"]}px;'></div>""") + 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("""<div data-class="one">foobarBARbaz</div><div data-class="two">foobarBARbaz</div>""") + url = inline(""" + <div data-class="one" role="banner" aria-label="foo">foobarBARbaz</div> + <div data-class="two" role="banner" aria-label="foo">foobarBARbaz</div> + """) 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", + [ + ( + "<article data-class='one'>foo</article><div data-class='two'>bar</div>", + {"role": "article"}, + "article", + ), + ( + "<input role='searchbox' data-class='one' /><input data-class='two' type='text'/>", + {"role": "searchbox"}, + "input", + ), + ( + "<button data-class='one'>Ok</button><button data-class='two'>Cancel</button>", + {"name": "Ok"}, + "button", + ), + ( + "<button data-class='one' aria-labelledby='one two'></button><div id='one'>ok</div><div id='two'>go</div><button data-class='two'>Cancel</button>", + {"name": "ok go"}, + "button", + ), + ( + "<button data-class='one' aria-label='foo'>bar</button><button data-class='two' aria-label='bar'>foo</button>", + {"name": "foo"}, + "button", + ), + ( + "<div role='banner' aria-label='foo' data-class='one'></div><div role='banner' data-class='two'></div><div aria-label='foo' data-class='three'></div>", + {"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("""<div data-class="one">foo</div><div data-class="two">foo</div>""") + url = inline(""" + <div data-class="one" role="banner" aria-label="bar">foo</div> + <div data-class="two" role="banner" aria-label="bar">foo</div> + """) 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("""<div id="parent"> - <p data-class="one">foo</p> - <p data-class="two">foo</p> + <p data-class="one" role="banner" aria-label="bar">foo</p> + <p data-class="two" role="banner">foo</p> <a data-class="three"> <span id="text">bar</span> </a> @@ -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(""" - <div id="parent-one"><p data-class="one">foo</p><p data-class="two">bar</p></div> - <div id="parent-two"><p data-class="one">foo</p><p data-class="two">bar</p></div> - """) + <div id="parent-one"> + <p data-class="one" role="banner" aria-label="bar">foo</p> + <p data-class="two">bar</p> + </div> + <div id="parent-two"> + <p data-class="one" role="banner" aria-label="bar">foo</p> + <p data-class="two">bar</p> + </div> + """) 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"""<div style="width: {width}px; height: {height}px;">foo</div>""" + 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") @@ -44,24 +44,6 @@ async def test_set_permission(bidi_session, new_tab, url): @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") @@ -196,31 +191,6 @@ def test_input(session, inline, add_event_listeners, tracked_events, type, value "month", "week", "file"]) -def test_input_disabled(session, inline, type): - session.url = inline("<input type=%s disabled>" % 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", - "email", - "password", - "search", - "tel", - "text", - "url", - "color", - "date", - "datetime", - "datetime-local", - "time", - "month", - "week", - "file"]) def test_input_readonly(session, inline, type): session.url = inline("<input type=%s readonly>" % type) element = session.find.css("input", all=False) @@ -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("<textarea disabled></textarea>") - 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("<textarea readonly></textarea>") 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> - <option>foo - </select> - """) - 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 type="{type}">""") + element = session.find.css("button", all=False) - response = element_clear(session, select) - assert_error(response, "invalid element state") - response = element_clear(session, option) - assert_error(response, "invalid element state") - - -def test_button(session, inline): - session.url = inline("<button></button>") - 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"""<button type="{type}" disabled>""") + element = session.find.css("button", all=False) + + response = element_clear(session, element) + assert_error(response, "invalid element state") + + +@pytest.mark.parametrize("type", INPUT_TYPES) +def test_input(session, inline, type): + session.url = inline(f"""<input type="{type}" disabled>""") + element = session.find.css("input", all=False) + + response = element_clear(session, element) + assert_error(response, "invalid element state") + + +def test_textarea(session, inline): + session.url = inline("<textarea disabled></textarea>") + element = session.find.css("textarea", all=False) + + response = element_clear(session, element) + assert_error(response, "invalid element state") + + +def test_fieldset_descendant(session, inline): + session.url = inline("<fieldset disabled><input>foo") + element = session.find.css("input", all=False) + + response = element_clear(session, element) + assert_error(response, "invalid element state") + + +def test_fieldset_descendant_first_legend(session, inline): + session.url = inline("<fieldset disabled><legend><input>foo") + element = session.find.css("input", all=False) + + response = element_clear(session, element) + assert_success(response) + + +def test_fieldset_descendant_not_first_legend(session, inline): + session.url = inline("<fieldset disabled><legend></legend><legend><input>foo") + element = session.find.css("input", all=False) + + response = element_clear(session, element) + assert_error(response, "invalid element state") + + +def test_option(session, inline): + session.url = inline("<select><option disabled>foo") + element = session.find.css("option", all=False) + + response = element_clear(session, element) + assert_error(response, "invalid element state") + + +def test_option_optgroup(session, inline): + session.url = inline("<select><optgroup disabled><option>foo") + element = session.find.css("option", all=False) + + response = element_clear(session, element) + assert_error(response, "invalid element state") + + +def test_option_select(session, inline): + session.url = inline("<select disabled><option>foo") + element = session.find.css("option", all=False) + + response = element_clear(session, element) + assert_error(response, "invalid element state") + + +def test_optgroup_select(session, inline): + session.url = inline("<select disabled><optgroup>foo") + element = session.find.css("optgroup", all=False) + + response = element_clear(session, element) + assert_error(response, "invalid element state") + + +def test_select(session, inline): + session.url = inline("<select disabled>") + element = session.find.css("select", all=False) + + response = element_clear(session, element) + assert_error(response, "invalid element state") + + +@pytest.mark.parametrize("tagname", ["button", "input", "select", "textarea"]) +def test_xhtml(session, inline, tagname): + session.url = inline( + f"""<{tagname} disabled="disabled"></{tagname}>""", doctype="xhtml") + element = session.find.css(tagname, all=False) + + result = element_clear(session, element) + assert_error(result, "invalid element state") + + +def test_xml(session, inline): + session.url = inline("""<note></note>""", doctype="xml") + element = session.find.css("note", all=False) + + result = element_clear(session, element) + assert_error(result, "invalid element state") diff --git a/testing/web-platform/tests/webdriver/tests/classic/element_clear/user_prompts.py b/testing/web-platform/tests/webdriver/tests/classic/element_clear/user_prompts.py index 7a8564a684..ccf048bc0a 100644 --- a/testing/web-platform/tests/webdriver/tests/classic/element_clear/user_prompts.py +++ b/testing/web-platform/tests/webdriver/tests/classic/element_clear/user_prompts.py @@ -3,13 +3,7 @@ import pytest from tests.support.asserts import assert_dialog_handled, assert_error, assert_success - - -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)) +from . import element_clear @pytest.fixture diff --git a/testing/web-platform/tests/webdriver/tests/classic/element_click/navigate.py b/testing/web-platform/tests/webdriver/tests/classic/element_click/navigate.py index 6fadee9869..7fbb812f02 100644 --- a/testing/web-platform/tests/webdriver/tests/classic/element_click/navigate.py +++ b/testing/web-platform/tests/webdriver/tests/classic/element_click/navigate.py @@ -36,14 +36,14 @@ def test_multi_line_link(session, inline, url): assert session.url == url(link) -def test_link_unload_event(session, url, server_config, inline): +def test_navigation_retains_input_state(session, url, server_config, inline): link = "/webdriver/tests/classic/element_click/support/input.html" session.url = inline(f""" - <body onunload="checkUnload()"> + <body onpagehide="checkPageHide()"> <a href="{link}">click here</a> <input type="checkbox"> <script> - function checkUnload() {{ + function checkPageHide() {{ document.getElementsByTagName("input")[0].checked = true; }} </script> diff --git a/testing/web-platform/tests/webdriver/tests/classic/get_element_text/get.py b/testing/web-platform/tests/webdriver/tests/classic/get_element_text/get.py index 924a4e8d79..8f832077e1 100644 --- a/testing/web-platform/tests/webdriver/tests/classic/get_element_text/get.py +++ b/testing/web-platform/tests/webdriver/tests/classic/get_element_text/get.py @@ -87,13 +87,6 @@ def test_stale_element_reference(session, stale_element, as_frame): assert_error(response, "stale element reference") -def test_getting_text_of_a_non_existant_element_is_an_error(session, inline): - session.url = inline("""<body>Hello world</body>""") - - result = get_element_text(session, "foo") - assert_error(result, "no such element") - - def test_read_element_text(session, inline): session.url = inline("Before f<span id='id'>oo</span> after") element = session.find.css("#id", all=False) @@ -102,6 +95,20 @@ def test_read_element_text(session, inline): assert_success(result, "oo") +@pytest.mark.parametrize("text, expected", [ + ("foo bar", "Foo Bar"), + ("foo-bar", "Foo-Bar"), + ("foo_bar", "Foo_bar"), +], ids=["space", "dash", "underscore"]) +def test_transform_capitalize(session, inline, text, expected): + session.url = inline( + f"""<div style="text-transform: capitalize;">{text}""") + element = session.find.css("div", all=False) + + result = get_element_text(session, element.id) + assert_success(result, expected) + + @pytest.mark.parametrize("text, inner_html, expected", [ ("cheese", "<slot><span>foo</span>bar</slot>", "cheese"), ("cheese", "<slot><span>foo</span></slot>bar", "cheesebar"), diff --git a/testing/web-platform/tests/webdriver/tests/classic/get_named_cookie/get.py b/testing/web-platform/tests/webdriver/tests/classic/get_named_cookie/get.py index 41426532ef..78418dae93 100644 --- a/testing/web-platform/tests/webdriver/tests/classic/get_named_cookie/get.py +++ b/testing/web-platform/tests/webdriver/tests/classic/get_named_cookie/get.py @@ -1,6 +1,6 @@ import pytest -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from tests.support.asserts import assert_error, assert_success @@ -62,7 +62,7 @@ def test_get_named_cookie(session, url): # same formatting as Date.toUTCString() in javascript utc_string_format = "%a, %d %b %Y %H:%M:%S" - a_day_from_now = (datetime.utcnow() + timedelta(days=1)).strftime(utc_string_format) + a_day_from_now = (datetime.now(timezone.utc) + timedelta(days=1)).strftime(utc_string_format) session.execute_script("document.cookie = 'foo=bar;expires=%s'" % a_day_from_now) result = get_named_cookie(session, "foo") diff --git a/testing/web-platform/tests/webdriver/tests/classic/is_element_enabled/__init__.py b/testing/web-platform/tests/webdriver/tests/classic/is_element_enabled/__init__.py index e69de29bb2..9a6d884000 100644 --- a/testing/web-platform/tests/webdriver/tests/classic/is_element_enabled/__init__.py +++ b/testing/web-platform/tests/webdriver/tests/classic/is_element_enabled/__init__.py @@ -0,0 +1,8 @@ +def is_element_enabled(session, element_id): + return session.transport.send( + "GET", + "session/{session_id}/element/{element_id}/enabled".format( + session_id=session.session_id, + element_id=element_id + ) + ) diff --git a/testing/web-platform/tests/webdriver/tests/classic/is_element_enabled/enabled.py b/testing/web-platform/tests/webdriver/tests/classic/is_element_enabled/enabled.py index 24fc85fdad..9588486dde 100644 --- a/testing/web-platform/tests/webdriver/tests/classic/is_element_enabled/enabled.py +++ b/testing/web-platform/tests/webdriver/tests/classic/is_element_enabled/enabled.py @@ -3,16 +3,8 @@ import pytest from webdriver import WebElement from tests.support.asserts import assert_error, assert_success - - -def is_element_enabled(session, element_id): - return session.transport.send( - "GET", - "session/{session_id}/element/{element_id}/enabled".format( - session_id=session.session_id, - element_id=element_id - ) - ) +from tests.support.dom import BUTTON_TYPES, INPUT_TYPES +from . import is_element_enabled def test_no_top_browsing_context(session, closed_window): @@ -90,80 +82,171 @@ def test_stale_element_reference(session, stale_element, as_frame): assert_error(result, "stale element reference") -@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"]) -def test_form_control_disabled(session, inline, element): - session.url = inline("<{} disabled/>".format(element)) - element = session.find.css(element, all=False) +@pytest.mark.parametrize("status, expected", [ + ("", True), + ("disabled", False), +], ids=["enabled", "disabled"]) +@pytest.mark.parametrize("type", BUTTON_TYPES) +def test_button(session, inline, status, expected, type): + session.url = inline(f"""<button type="{type}" {status}>""") + element = session.find.css("button", all=False) - result = is_element_enabled(session, element.id) - assert_success(result, False) + response = is_element_enabled(session, element.id) + assert_success(response, expected) -@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"]) -def test_form_control_enabled(session, inline, element): - session.url = inline("<{}/>".format(element)) - element = session.find.css(element, all=False) +@pytest.mark.parametrize("status, expected", [ + ("", True), + ("disabled", False), +], ids=["enabled", "disabled"]) +@pytest.mark.parametrize("type", INPUT_TYPES) +def test_input(session, inline, status, expected, type): + session.url = inline(f"""<input type="{type}" {status}>""") + element = session.find.css("input", all=False) result = is_element_enabled(session, element.id) - assert_success(result, True) + assert_success(result, expected) -@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"]) -def test_fieldset_disabled_descendant(session, inline, element): - session.url = inline("<fieldset disabled><{}/></fieldset>".format(element)) - element = session.find.css(element, all=False) +@pytest.mark.parametrize("status, expected", [ + ("", True), + ("disabled", False), +], ids=["enabled", "disabled"]) +def test_textarea(session, inline, status, expected): + session.url = inline(f"<textarea {status}></textarea>") + element = session.find.css("textarea", all=False) - result = is_element_enabled(session, element.id) - assert_success(result, False) + response = is_element_enabled(session, element.id) + assert_success(response, expected) -@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"]) -def test_fieldset_enabled_descendant(session, inline, element): - session.url = inline("<fieldset><{}/></fieldset>".format(element)) - element = session.find.css(element, all=False) +@pytest.mark.parametrize("status, expected", [ + ("", True), + ("disabled", False), +], ids=["enabled", "disabled"]) +def test_fieldset(session, inline, status, expected): + session.url = inline(f"<fieldset {status}><input>foo") + element = session.find.css("input", all=False) - result = is_element_enabled(session, element.id) - assert_success(result, True) + response = is_element_enabled(session, element.id) + assert_success(response, expected) -@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"]) -def test_fieldset_disabled_descendant_legend(session, inline, element): - session.url = inline("<fieldset disabled><legend><{}/></legend></fieldset>".format(element)) - element = session.find.css(element, all=False) +@pytest.mark.parametrize("status, expected", [ + ("", True), + ("disabled", False), +], ids=["enabled", "disabled"]) +def test_fieldset_descendant(session, inline, status, expected): + session.url = inline(f"<fieldset {status}><input>foo") + element = session.find.css("input", all=False) - result = is_element_enabled(session, element.id) - assert_success(result, True) + response = is_element_enabled(session, element.id) + assert_success(response, expected) -@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"]) -def test_fieldset_enabled_descendant_legend(session, inline, element): - session.url = inline("<fieldset><legend><{}/></legend></fieldset>".format(element)) - element = session.find.css(element, all=False) +@pytest.mark.parametrize("status, expected", [ + ("", True), + ("disabled", True), +], ids=["enabled", "disabled"]) +def test_fieldset_descendant_first_legend(session, inline, status, expected): + session.url = inline(f"<fieldset {status}><legend><input>foo") + element = session.find.css("input", all=False) - result = is_element_enabled(session, element.id) - assert_success(result, True) + response = is_element_enabled(session, element.id) + assert_success(response, expected) -@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"]) -def test_xhtml_form_control_disabled(session, inline, element): - session.url = inline("""<{} disabled="disabled"/>""".format(element), - doctype="xhtml") - element = session.find.css(element, all=False) +@pytest.mark.parametrize("status, expected", [ + ("", True), + ("disabled", False), +], ids=["enabled", "disabled"]) +def test_fieldset_descendant_not_first_legend(session, inline, status, expected): + session.url = inline(f"<fieldset {status}><legend></legend><legend><input>foo") + element = session.find.css("input", all=False) - result = is_element_enabled(session, element.id) - assert_success(result, False) + response = is_element_enabled(session, element.id) + assert_success(response, expected) + + +@pytest.mark.parametrize("status, expected", [ + ("", True), + ("disabled", False), +], ids=["enabled", "disabled"]) +def test_option(session, inline, status, expected): + session.url = inline(f"<select><option {status}>foo") + element = session.find.css("option", all=False) + + response = is_element_enabled(session, element.id) + assert_success(response, expected) + + +@pytest.mark.parametrize("status, expected", [ + ("", True), + ("disabled", False), +], ids=["enabled", "disabled"]) +def test_option_with_optgroup(session, inline, status, expected): + session.url = inline(f"<select><optgroup {status}><option>foo") + element = session.find.css("optgroup", all=False) + + response = is_element_enabled(session, element.id) + assert_success(response, expected) + + option = session.find.css("option", all=False) + response = is_element_enabled(session, option.id) + assert_success(response, expected) + + +@pytest.mark.parametrize("status, expected", [ + ("", True), + ("disabled", False), +], ids=["enabled", "disabled"]) +def test_option_with_select(session, inline, status, expected): + session.url = inline(f"<select {status}><option>foo") + + option = session.find.css("option", all=False) + response = is_element_enabled(session, option.id) + assert_success(response, expected) + + +@pytest.mark.parametrize("status, expected", [ + ("", True), + ("disabled", False), +], ids=["enabled", "disabled"]) +def test_optgroup_with_select(session, inline, status, expected): + session.url = inline(f"<select {status}><optgroup>foo") + + option = session.find.css("optgroup", all=False) + response = is_element_enabled(session, option.id) + assert_success(response, expected) + + +@pytest.mark.parametrize("status, expected", [ + ("", True), + ("disabled", False), +], ids=["enabled", "disabled"]) +def test_select(session, inline, status, expected): + session.url = inline(f"<select {status}>") + element = session.find.css("select", all=False) + + response = is_element_enabled(session, element.id) + assert_success(response, expected) -@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"]) -def test_xhtml_form_control_enabled(session, inline, element): - session.url = inline("""<{}/>""".format(element), doctype="xhtml") - element = session.find.css(element, all=False) +@pytest.mark.parametrize("status, expected", [ + ("", True), + ("disabled=\"disabled\"", False), +], ids=["enabled", "disabled"]) +@pytest.mark.parametrize("tagname", ["button", "input", "select", "textarea"]) +def test_xhtml(session, inline, status, expected, tagname): + session.url = inline( + f"""<{tagname} {status}></{tagname}>""", doctype="xhtml") + element = session.find.css(tagname, all=False) result = is_element_enabled(session, element.id) - assert_success(result, True) + assert_success(result, expected) -def test_xml_always_not_enabled(session, inline): +def test_xml(session, inline): session.url = inline("""<note></note>""", doctype="xml") element = session.find.css("note", all=False) diff --git a/testing/web-platform/tests/webdriver/tests/classic/is_element_enabled/user_prompts.py b/testing/web-platform/tests/webdriver/tests/classic/is_element_enabled/user_prompts.py index 5dd7d582bd..a3af947d51 100644 --- a/testing/web-platform/tests/webdriver/tests/classic/is_element_enabled/user_prompts.py +++ b/testing/web-platform/tests/webdriver/tests/classic/is_element_enabled/user_prompts.py @@ -3,16 +3,7 @@ import pytest from tests.support.asserts import assert_error, assert_dialog_handled, assert_success - - -def is_element_enabled(session, element_id): - return session.transport.send( - "GET", - "session/{session_id}/element/{element_id}/enabled".format( - session_id=session.session_id, - element_id=element_id - ) - ) +from . import is_element_enabled @pytest.fixture diff --git a/testing/web-platform/tests/webdriver/tests/classic/perform_actions/wheel.py b/testing/web-platform/tests/webdriver/tests/classic/perform_actions/wheel.py index a75a84378a..6d0f9ddb11 100644 --- a/testing/web-platform/tests/webdriver/tests/classic/perform_actions/wheel.py +++ b/testing/web-platform/tests/webdriver/tests/classic/perform_actions/wheel.py @@ -4,6 +4,7 @@ from webdriver.error import NoSuchWindowException from tests.classic.perform_actions.support.refine import get_events +from tests.support.keys import Keys def test_null_response_value(session, wheel_chain): @@ -111,3 +112,18 @@ def test_scroll_shadow_tree(session, get_test_page, wheel_chain, mode, nested): assert events[0]["deltaX"] == 5 assert events[0]["deltaY"] == 10 assert events[0]["target"] == "scrollableShadowTreeContent" + + +def test_scroll_with_key_pressed( + session, test_actions_scroll_page, key_chain, wheel_chain +): + scrollable = session.find.css("#scrollable", all=False) + + key_chain.key_down(Keys.R_SHIFT).perform() + wheel_chain.scroll(0, 0, 5, 10, origin=scrollable).perform() + key_chain.key_up(Keys.R_SHIFT).perform() + + events = get_events(session) + assert len(events) == 1 + assert events[0]["type"] == "wheel" + assert events[0]["shiftKey"] == True diff --git a/testing/web-platform/tests/webdriver/tests/support/dom.py b/testing/web-platform/tests/webdriver/tests/support/dom.py new file mode 100644 index 0000000000..f77fb49387 --- /dev/null +++ b/testing/web-platform/tests/webdriver/tests/support/dom.py @@ -0,0 +1,29 @@ +BUTTON_TYPES = [ + "button", + "reset", + "submit", +] + +INPUT_TYPES = [ + "button", + "checkbox", + "color", + "date", + "datetime-local", + "email", + "file", + "image", + "month", + "number", + "password", + "radio", + "range", + "reset", + "search", + "submit", + "tel", + "text", + "time", + "url", + "week", +]; diff --git a/testing/web-platform/tests/webdriver/tests/support/fixtures_bidi.py b/testing/web-platform/tests/webdriver/tests/support/fixtures_bidi.py index 32919210bf..c76b369f21 100644 --- a/testing/web-platform/tests/webdriver/tests/support/fixtures_bidi.py +++ b/testing/web-platform/tests/webdriver/tests/support/fixtures_bidi.py @@ -538,7 +538,12 @@ def fetch(bidi_session, top_context, configuration): """ async def fetch( - url, method="GET", headers=None, context=top_context, timeout_in_seconds=3 + url, + method="GET", + headers=None, + post_data=None, + context=top_context, + timeout_in_seconds=3, ): method_arg = f"method: '{method}'," @@ -546,6 +551,10 @@ def fetch(bidi_session, top_context, configuration): if headers is not None: headers_arg = f"headers: {json.dumps(headers)}," + body_arg = "" + if post_data is not None: + body_arg = f"body: {post_data}," + timeout_in_seconds = timeout_in_seconds * configuration["timeout_multiplier"] # Wait for fetch() to resolve a response and for response.text() to # resolve as well to make sure the request/response is completed when @@ -558,6 +567,7 @@ def fetch(bidi_session, top_context, configuration): fetch("{url}", {{ {method_arg} {headers_arg} + {body_arg} signal: controller.signal, }}).then(response => response.text()); }}""", diff --git a/testing/web-platform/tests/webdriver/tests/support/html/test_actions_scroll.html b/testing/web-platform/tests/webdriver/tests/support/html/test_actions_scroll.html index db5952ed74..edeff342fe 100644 --- a/testing/web-platform/tests/webdriver/tests/support/html/test_actions_scroll.html +++ b/testing/web-platform/tests/webdriver/tests/support/html/test_actions_scroll.html @@ -63,6 +63,10 @@ "deltaZ": event.deltaZ, "deltaMode": event.deltaMode, "target": event.target.id, + "altKey": event.altKey, + "ctrlKey": event.ctrlKey, + "metaKey": event.metaKey, + "shiftKey": event.shiftKey, }); addMessage( @@ -75,7 +79,11 @@ "deltaY: " + event.deltaY + ", " + "deltaZ: " + event.deltaZ + ", " + "deltaMode: " + event.deltaMode + ", " + - "target id: " + event.target.id + "target id: " + event.target.id + ", " + + "altKey: " + event.altKey + ", " + + "ctrlKey: " + event.ctrlKey + ", " + + "metaKey: " + event.metaKey + ", " + + "shiftKey: " + event.shiftKey ); } @@ -121,7 +129,11 @@ "deltaY": event.deltaY, "deltaZ": event.deltaZ, "deltaMode": event.deltaMode, - "target": event.target + "target": event.target, + "altKey": event.altKey, + "ctrlKey": event.ctrlKey, + "metaKey": event.metaKey, + "shiftKey": event.shiftKey, }); }); </script> |