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

Change behavior of window.open w.r.t. windowPreferences and popups #29334

Merged
merged 1 commit into from
Nov 23, 2021
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,24 @@
<!DOCTYPE html>
<script>
var channelName = window.name;
var channel = new BroadcastChannel(channelName);
const allBarProps = [
window.locationbar.visible,
window.menubar.visible,
window.personalbar.visible,
window.scrollbars.visible,
window.statusbar.visible,
window.toolbar.visible
];
const allTrue = allBarProps.every(x=>x);
const allFalse = allBarProps.every(x=>!x);
channel.postMessage({isPopup: allFalse, mixedState: !allTrue && !allFalse});

// Because messages are not delivered synchronously and because closing a
// browsing context prompts the eventual clearing of all task sources, this
// document should not be closed until the opener document has confirmed
// receipt.
channel.onmessage = function() {
window.close();
};
</script>
51 changes: 51 additions & 0 deletions html/browsers/the-window-object/window-open-popup-behavior.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>Window.open popup behavior</title>
<link rel="author" href="[email protected]">
<link rel="help" href="https://html.spec.whatwg.org/multipage/window-object.html#window-open-steps">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script>
function testOne(windowFeatures, expectPopup) {
const windowName = Math.round(Math.random()*1e12);
const channel = new BroadcastChannel(windowName);
var w;
promise_test(() => {
return new Promise(resolve => {
w = window.open("support/window-open-popup-target.html", windowName, windowFeatures);
channel.addEventListener('message', resolve);
}).then(e => {
// Send message first so if asserts throw the popup is still closed
channel.postMessage(null);
assert_false(e.data.mixedState, "No mixed state");
assert_equals(e.data.isPopup, expectPopup, "Popup state");
});
},`${windowFeatures} (expect ${expectPopup ? "popup" : "tab"})`);
}

// No windowpreferences at all - tab.
testOne(undefined, /*expectPopup=*/false);

// Test all permutations of these properties:
const features = ["location","toolbar","menubar","resizable","scrollbars","status"];
const nProps = features.length;
const skip = 7; // To speed up the test, don't test all values. Skip 7 to pseudo-randomize.
for(let i=0;i<2**nProps;i+=skip) {
const enableVec = Number(i).toString(2).padStart(nProps,'0').split('').map(s => (s==="1"));
let windowFeatures = [];
for(let i=0;i<nProps;++i) {
if (enableVec[i])
windowFeatures.push(features[i] + "=yes");
}
windowFeatures = windowFeatures.join(',');
// We get a popup we got windowFeatures, and any of them are false:
const expectPopup = !!windowFeatures.length && (!(enableVec[0] || enableVec[1]) || !enableVec[2] || !enableVec[3] || !enableVec[4] || !enableVec[5]);
testOne(windowFeatures, expectPopup);
testOne(windowFeatures + ",noopener", /*expectPopup=*/false);
testOne(windowFeatures + ",noreferrer", /*expectPopup=*/false);
testOne(windowFeatures + ",popup", /*expectPopup=*/true); // "popup" feature = popup
testOne(windowFeatures + ",noopener,noreferrer,popup", /*expectPopup=*/false);
}
</script>