Skip to content

Commit

Permalink
Bug 1936441 [wpt PR 49631] - Add WPTs for named window lookup and BCG…
Browse files Browse the repository at this point in the history
… swap limits, a=testonly

Automatic update from web-platform-tests
Add WPTs for named window lookup and BCG swap limits

These tests verify the behaviour discussed here:
whatwg/html#10818

While there is some implementation defined behaviour, we can add tests
for the behaviour that's consistent between the major implementations,
namely that proactive browsing context group swaps can't be done while
another context exists in the group, that named lookups are scoped to
browsing context groups, and the lookup order in the case of multiple
contexts with the same name.

Bug: None
Change-Id: I515f527fb94a711bdd8eeb6610df2127571dcc3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6081814
Reviewed-by: Domenic Denicola <[email protected]>
Commit-Queue: Kevin McNee <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1394596}

--

wpt-commits: 1f7679ad01691ea3885537b8b19e1b88a0e7f152
wpt-pr: 49631
  • Loading branch information
kjmcnee authored and moz-wptsync-bot committed Dec 13, 2024
1 parent 809bb64 commit 8c1538d
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<title>Named lookup scoped to browsing context group</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js"></script>

<body>
<script>

promise_test(async t => {
const rcHelper = new RemoteContextHelper();
// This test harness cannot be in the same browsing context group as the
// popup.
const rcPopup1 = await rcHelper.addWindow(undefined, { features: 'noopener' });

await rcPopup1.executeScript(() => {
window.name = 'my_popup';
window.firstPopup = true;
});
assert_equals(window.open('', 'my_popup').firstPopup, undefined,
'cannot lookup across browsing context groups');
}, 'named lookup scoped to browsing context group');

</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<title>No proactive browsing context group changes when other contexts in group</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js"></script>

<body>
<script>

promise_test(async t => {
const rcHelper = new RemoteContextHelper();
const rcPopup1 = await rcHelper.addWindow(undefined, { target: 'my_popup' });

await rcPopup1.executeScript(() => {
window.intendedTarget1 = true;
});
assert_true(window.open('', 'my_popup').intendedTarget1,
'lookup by name');

// There is no security reason (e.g. COOP) to change browsing context groups
// for this navigation. Some implementations perform BCG swaps for performance
// reasons, but they cannot do so in this case, as this test harness page and
// the popup are in the same browsing context group.
const rcPopup2 = await rcPopup1.navigateToNew();

// In order to find the popup by name, the popup and this opener must be in
// the same browsing context group.
await rcPopup2.executeScript(() => {
window.intendedTarget2 = true;
});
assert_true(window.open('', 'my_popup').intendedTarget2,
'lookup by name after navigation');
}, 'no proactive browsing context group change when other contexts in group');

</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<title>Duplicate name lookup order</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js"></script>

<body>
<script>

promise_test(async t => {
const rcHelper = new RemoteContextHelper();
const rcMain = await rcHelper.addWindow();

const rcPopupA = await rcHelper.addWindow(undefined, { target: 'A' });
const rcPopupB = await rcHelper.addWindow(undefined, { target: 'B' });
const rcPopupC = await rcHelper.addWindow(undefined, { target: 'C' });

const rcSiblingA = await rcMain.addIframe(undefined, { name: 'A' });
const rcSiblingB = await rcMain.addIframe(undefined, { name: 'B' });

const rcRequestor = await rcMain.addIframe();

const rcChildA = await rcRequestor.addIframe(undefined, { name: 'A' });

const windowIdentifiers = {
'Main': rcMain,
'PopupA': rcPopupA,
'PopupB': rcPopupB,
'PopupC': rcPopupC,
'SiblingA': rcSiblingA,
'SiblingB': rcSiblingB,
'Requestor': rcRequestor,
'ChildA': rcChildA,
};
for (const [windowIdentifier, remote] of Object.entries(windowIdentifiers)) {
await remote.executeScript((windowIdentifier) => {
window.windowIdentifier = windowIdentifier;
}, [windowIdentifier]);
}

function performLookup(targetName) {
return rcRequestor.executeScript((targetName) => {
return window.open('', targetName).windowIdentifier;
}, [targetName]);
}

assert_equals(await performLookup('A'), 'ChildA', 'subtree first');
assert_equals(await performLookup('B'), 'SiblingB', 'then the rest of the tree');
assert_equals(await performLookup('C'), 'PopupC', 'then other pages');
}, 'Duplicate name lookup order');

</script>
</body>

0 comments on commit 8c1538d

Please sign in to comment.