summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/browsers/the-window-object/window-open-popup-behavior.html
blob: 258698d94d9ad2414344d29b0128c52937923890 (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
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>Window.open popup behavior</title>
<link rel="author" href="masonf@chromium.org">
<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>