forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wdspec] Add tests for "browsingContext.traverseHistory".
Differential Revision: https://phabricator.services.mozilla.com/D193897 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1841018 gecko-commit: 8bec1f302a76929843c944e27b75ddcbf1f21954 gecko-reviewers: webdriver-reviewers, whimboo
- Loading branch information
1 parent
f7548c6
commit f91b458
Showing
4 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
webdriver/tests/bidi/browsing_context/traverse_history/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
async def get_url_for_context(bidi_session, context): | ||
contexts = await bidi_session.browsing_context.get_tree(root=context) | ||
|
||
return contexts[0]["url"] |
66 changes: 66 additions & 0 deletions
66
webdriver/tests/bidi/browsing_context/traverse_history/context.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import pytest | ||
|
||
import webdriver.bidi.error as error | ||
|
||
from . import get_url_for_context | ||
|
||
|
||
pytestmark = pytest.mark.asyncio | ||
|
||
|
||
async def test_params_context_invalid_value(bidi_session): | ||
with pytest.raises(error.NoSuchFrameException): | ||
await bidi_session.browsing_context.traverse_history(context="foo", delta=1) | ||
|
||
|
||
async def test_top_level_contexts(bidi_session, top_context, new_tab, inline): | ||
pages = [ | ||
inline("<div>page 1</div>"), | ||
inline("<div>page 2</div>"), | ||
] | ||
for page in pages: | ||
for context in [top_context["context"], new_tab["context"]]: | ||
await bidi_session.browsing_context.navigate( | ||
context=context, url=page, wait="complete" | ||
) | ||
assert await get_url_for_context(bidi_session, context) == page | ||
|
||
await bidi_session.browsing_context.traverse_history( | ||
context=new_tab["context"], delta=-1 | ||
) | ||
|
||
assert await get_url_for_context(bidi_session, top_context["context"]) == pages[1] | ||
assert await get_url_for_context(bidi_session, new_tab["context"]) == pages[0] | ||
|
||
|
||
@pytest.mark.parametrize("domain", ["", "alt"], ids=["same_origin", "cross_origin"]) | ||
async def test_iframe(bidi_session, new_tab, inline, domain): | ||
iframe_url_1 = inline("page 1") | ||
page_url = inline(f"<iframe src='{iframe_url_1}'></iframe>", domain=domain) | ||
|
||
await bidi_session.browsing_context.navigate( | ||
context=new_tab["context"], url=page_url, wait="complete" | ||
) | ||
assert await get_url_for_context(bidi_session, new_tab["context"]) == page_url | ||
|
||
contexts = await bidi_session.browsing_context.get_tree(root=new_tab["context"]) | ||
iframe_context = contexts[0]["children"][0] | ||
|
||
iframe_url_2 = inline("page 2") | ||
await bidi_session.browsing_context.navigate( | ||
context=iframe_context["context"], url=iframe_url_2, wait="complete" | ||
) | ||
assert ( | ||
await get_url_for_context(bidi_session, iframe_context["context"]) | ||
== iframe_url_2 | ||
) | ||
|
||
await bidi_session.browsing_context.traverse_history( | ||
context=iframe_context["context"], delta=-1 | ||
) | ||
|
||
assert await get_url_for_context(bidi_session, new_tab["context"]) == page_url | ||
assert ( | ||
await get_url_for_context(bidi_session, iframe_context["context"]) | ||
== iframe_url_1 | ||
) |
162 changes: 162 additions & 0 deletions
162
webdriver/tests/bidi/browsing_context/traverse_history/delta.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
import webdriver.bidi.error as error | ||
from webdriver.bidi.modules.script import ContextTarget | ||
|
||
from . import get_url_for_context | ||
|
||
|
||
pytestmark = pytest.mark.asyncio | ||
|
||
|
||
@pytest.mark.parametrize("value", [-2, 1]) | ||
async def test_delta_invalid_value(bidi_session, new_tab, inline, value): | ||
page = inline("<div>page 1</div>") | ||
await bidi_session.browsing_context.navigate( | ||
context=new_tab["context"], url=page, wait="complete" | ||
) | ||
assert await get_url_for_context(bidi_session, new_tab["context"]) == page | ||
|
||
with pytest.raises(error.NoSuchHistoryEntryException): | ||
await bidi_session.browsing_context.traverse_history( | ||
context=new_tab["context"], delta=value | ||
) | ||
|
||
|
||
async def test_delta_0(bidi_session, new_tab, inline): | ||
page = inline("<div>page 1</div>") | ||
await bidi_session.browsing_context.navigate( | ||
context=new_tab["context"], url=page, wait="complete" | ||
) | ||
assert await get_url_for_context(bidi_session, new_tab["context"]) == page | ||
|
||
await bidi_session.browsing_context.traverse_history( | ||
context=new_tab["context"], delta=0 | ||
) | ||
|
||
# Check that url didn't change | ||
assert await get_url_for_context(bidi_session, new_tab["context"]) == page | ||
|
||
|
||
async def test_delta_forward_and_back(bidi_session, new_tab, inline): | ||
pages = [ | ||
inline("<div>page 1</div>"), | ||
inline("<div>page 2</div>"), | ||
inline("<div>page 3</div>"), | ||
] | ||
for page in pages: | ||
await bidi_session.browsing_context.navigate( | ||
context=new_tab["context"], url=page, wait="complete" | ||
) | ||
assert await get_url_for_context(bidi_session, new_tab["context"]) == page | ||
|
||
await bidi_session.browsing_context.traverse_history( | ||
context=new_tab["context"], delta=-2 | ||
) | ||
|
||
assert await get_url_for_context(bidi_session, new_tab["context"]) == pages[0] | ||
|
||
await bidi_session.browsing_context.traverse_history( | ||
context=new_tab["context"], delta=2 | ||
) | ||
|
||
assert await get_url_for_context(bidi_session, new_tab["context"]) == pages[2] | ||
|
||
|
||
async def test_navigate_in_the_same_document(bidi_session, new_tab, url): | ||
page_url = "/webdriver/tests/bidi/browsing_context/support/empty.html" | ||
pages = [ | ||
url(page_url), | ||
url(page_url + "#foo"), | ||
url(page_url + "#bar"), | ||
] | ||
for page in pages: | ||
await bidi_session.browsing_context.navigate( | ||
context=new_tab["context"], url=page, wait="complete" | ||
) | ||
assert await get_url_for_context(bidi_session, new_tab["context"]) == page | ||
|
||
await bidi_session.browsing_context.traverse_history( | ||
context=new_tab["context"], delta=-1 | ||
) | ||
|
||
assert await get_url_for_context(bidi_session, new_tab["context"]) == pages[1] | ||
|
||
await bidi_session.browsing_context.traverse_history( | ||
context=new_tab["context"], delta=1 | ||
) | ||
|
||
assert await get_url_for_context(bidi_session, new_tab["context"]) == pages[2] | ||
|
||
|
||
async def test_history_push_state(bidi_session, new_tab, url): | ||
page_url = url("/webdriver/tests/bidi/browsing_context/support/empty.html") | ||
await bidi_session.browsing_context.navigate( | ||
context=new_tab["context"], url=page_url, wait="complete" | ||
) | ||
assert await get_url_for_context(bidi_session, new_tab["context"]) == page_url | ||
|
||
pages = [ | ||
f"{page_url}#foo", | ||
f"{page_url}#bar", | ||
] | ||
for page in pages: | ||
await bidi_session.script.call_function( | ||
function_declaration="""(url) => { | ||
history.pushState(null, null, url); | ||
}""", | ||
arguments=[ | ||
{"type": "string", "value": page}, | ||
], | ||
await_promise=False, | ||
target=ContextTarget(new_tab["context"]), | ||
) | ||
assert await get_url_for_context(bidi_session, new_tab["context"]) == page | ||
|
||
await bidi_session.browsing_context.traverse_history( | ||
context=new_tab["context"], delta=-1 | ||
) | ||
|
||
assert await get_url_for_context(bidi_session, new_tab["context"]) == pages[0] | ||
|
||
await bidi_session.browsing_context.traverse_history( | ||
context=new_tab["context"], delta=1 | ||
) | ||
|
||
assert await get_url_for_context(bidi_session, new_tab["context"]) == pages[1] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"pages", | ||
[ | ||
["data:text/html,<p>foo</p>", "data:text/html,<p>bar</p>"], | ||
[ | ||
f"{Path(__file__).parents[1].as_uri()}/support/empty.html", | ||
f"{Path(__file__).parents[1].as_uri()}/support/other.html", | ||
], | ||
], | ||
ids=[ | ||
"data url", | ||
"file url", | ||
], | ||
) | ||
async def test_navigate_special_protocols(bidi_session, new_tab, pages): | ||
for page in pages: | ||
await bidi_session.browsing_context.navigate( | ||
context=new_tab["context"], url=page, wait="complete" | ||
) | ||
assert await get_url_for_context(bidi_session, new_tab["context"]) == page | ||
|
||
await bidi_session.browsing_context.traverse_history( | ||
context=new_tab["context"], delta=-1 | ||
) | ||
|
||
assert await get_url_for_context(bidi_session, new_tab["context"]) == pages[0] | ||
|
||
await bidi_session.browsing_context.traverse_history( | ||
context=new_tab["context"], delta=1 | ||
) | ||
|
||
assert await get_url_for_context(bidi_session, new_tab["context"]) == pages[1] |
29 changes: 29 additions & 0 deletions
29
webdriver/tests/bidi/browsing_context/traverse_history/invalid.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
|
||
import webdriver.bidi.error as error | ||
|
||
|
||
pytestmark = pytest.mark.asyncio | ||
|
||
|
||
MAX_INT = 9007199254740991 | ||
MIN_INT = -MAX_INT | ||
|
||
|
||
@pytest.mark.parametrize("value", [None, False, 42, {}, []]) | ||
async def test_params_context_invalid_type(bidi_session, value): | ||
with pytest.raises(error.InvalidArgumentException): | ||
await bidi_session.browsing_context.traverse_history( | ||
context=value, | ||
delta=1 | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"value", [None, False, "foo", 1.5, MIN_INT - 1, MAX_INT + 1, {}, []] | ||
) | ||
async def test_params_delta_invalid_type(bidi_session, top_context, value): | ||
with pytest.raises(error.InvalidArgumentException): | ||
await bidi_session.browsing_context.traverse_history( | ||
context=top_context["context"], delta=value | ||
) |