| 1 |
import pytest |
| 2 |
|
| 3 |
from .. import using_context |
| 4 |
|
| 5 |
pytestmark = pytest.mark.asyncio |
| 6 |
|
| 7 |
|
| 8 |
# Helper to assert the order of top level browsing contexts. |
| 9 |
# The window used for the assertion is inferred from the first context id of |
| 10 |
# expected_context_ids. |
| 11 |
def assert_tab_order(session, expected_context_ids): |
| 12 |
with using_context(session, "chrome"): |
| 13 |
context_ids = session.execute_script( |
| 14 |
""" |
| 15 |
const contextId = arguments[0]; |
| 16 |
const { TabManager } = |
| 17 |
ChromeUtils.importESModule("chrome://remote/content/shared/TabManager.sys.mjs"); |
| 18 |
const browsingContext = TabManager.getBrowsingContextById(contextId); |
| 19 |
const chromeWindow = browsingContext.embedderElement.ownerGlobal; |
| 20 |
const tabBrowser = TabManager.getTabBrowser(chromeWindow); |
| 21 |
return tabBrowser.browsers.map(browser => TabManager.getIdForBrowser(browser)); |
| 22 |
""", |
| 23 |
args=(expected_context_ids[0],), |
| 24 |
) |
| 25 |
|
| 26 |
assert context_ids == expected_context_ids |
| 27 |
|
| 28 |
|
| 29 |
@pytest.mark.allow_system_access |
| 30 |
async def test_reference_context(bidi_session, current_session): |
| 31 |
# Create a new window with a tab tab1 |
| 32 |
result = await bidi_session.browsing_context.create(type_hint="window") |
| 33 |
tab1_context_id = result["context"] |
| 34 |
|
| 35 |
# Create a second window with a tab tab2 |
| 36 |
result = await bidi_session.browsing_context.create(type_hint="window") |
| 37 |
tab2_context_id = result["context"] |
| 38 |
|
| 39 |
# Create a new tab tab3 next to tab1 |
| 40 |
result = await bidi_session.browsing_context.create( |
| 41 |
type_hint="tab", reference_context=tab1_context_id |
| 42 |
) |
| 43 |
tab3_context_id = result["context"] |
| 44 |
|
| 45 |
# Create a new tab tab4 next to tab2 |
| 46 |
result = await bidi_session.browsing_context.create( |
| 47 |
type_hint="tab", reference_context=tab2_context_id |
| 48 |
) |
| 49 |
tab4_context_id = result["context"] |
| 50 |
|
| 51 |
# Create a new tab tab5 also next to tab2 (should consequently be between |
| 52 |
# tab2 and tab4) |
| 53 |
result = await bidi_session.browsing_context.create( |
| 54 |
type_hint="tab", reference_context=tab2_context_id |
| 55 |
) |
| 56 |
tab5_context_id = result["context"] |
| 57 |
|
| 58 |
# Create a new window, but pass a reference_context from an existing window. |
| 59 |
# The reference context is expected to be ignored here. |
| 60 |
result = await bidi_session.browsing_context.create( |
| 61 |
type_hint="window", reference_context=tab2_context_id |
| 62 |
) |
| 63 |
tab6_context_id = result["context"] |
| 64 |
|
| 65 |
# We expect 3 windows in total, with a specific tab order: |
| 66 |
# - the first window should contain tab1, tab3 |
| 67 |
assert_tab_order(current_session, [tab1_context_id, tab3_context_id]) |
| 68 |
# - the second window should contain tab2, tab5, tab4 |
| 69 |
assert_tab_order( |
| 70 |
current_session, [tab2_context_id, tab5_context_id, tab4_context_id] |
| 71 |
) |
| 72 |
# - the third window should contain tab6 |
| 73 |
assert_tab_order(current_session, [tab6_context_id]) |