summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/navigate/frame.py
blob: 4dcd88dfdb8513968a16ec21e4657e852e9785d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import pytest

from . import navigate_and_assert

pytestmark = pytest.mark.asyncio

PAGE_CONTENT = "<div>foo</div>"


@pytest.mark.parametrize("domain", ["", "alt"], ids=["same_origin", "cross_origin"])
async def test_origin(bidi_session, new_tab, inline, domain):
    frame_start_url = inline("frame")
    url_before = inline(f"<iframe src='{frame_start_url}'></iframe>", domain=domain)
    contexts = await navigate_and_assert(bidi_session, new_tab, url_before)

    assert len(contexts[0]["children"]) == 1
    frame = contexts[0]["children"][0]
    assert frame["url"] == frame_start_url

    await navigate_and_assert(bidi_session, frame, inline(PAGE_CONTENT))


async def test_multiple_frames(
    bidi_session, new_tab, test_page_multiple_frames, test_page, test_page2, inline
):
    contexts = await navigate_and_assert(
        bidi_session, new_tab, test_page_multiple_frames
    )

    assert len(contexts[0]["children"]) == 2
    frame = contexts[0]["children"][0]
    assert frame["url"] == test_page

    await navigate_and_assert(bidi_session, frame, inline(PAGE_CONTENT))

    # Make sure that the second frame hasn't been navigated
    contexts = await bidi_session.browsing_context.get_tree(root=new_tab["context"])
    assert contexts[0]["children"][1]["url"] == test_page2


async def test_nested_frames(
    bidi_session,
    new_tab,
    inline,
    test_page_nested_frames,
    test_page_same_origin_frame,
    test_page,
):
    contexts = await navigate_and_assert(bidi_session, new_tab, test_page_nested_frames)

    assert len(contexts[0]["children"]) == 1
    frame_level_1 = contexts[0]["children"][0]
    assert frame_level_1["url"] == test_page_same_origin_frame

    assert len(frame_level_1["children"]) == 1
    frame_level_2 = frame_level_1["children"][0]
    assert frame_level_2["url"] == test_page

    await navigate_and_assert(bidi_session, frame_level_2, inline(PAGE_CONTENT))