Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WPTs for named window lookup and BCG swap limits #49631

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>