Bug 1527584 [wpt PR 15352] - HTML: window.open("", "", "noreferrer"), a=testonly
authorAnne van Kesteren <annevk@annevk.nl>
Wed, 06 Mar 2019 16:53:08 +0000
changeset 506480 154f3e3e9fc6ad51a59f20321925a6bcbc14a6d8
parent 506479 06a6b851f49054688f2a26f10d38c74206212250
child 506481 b58846c0e583fc323c5958484ad4d4909490f727
push id138
push usermtabara@mozilla.com
push dateWed, 20 Mar 2019 18:12:49 +0000
reviewerstestonly
bugs1527584, 15352
milestone67.0a1
Bug 1527584 [wpt PR 15352] - HTML: window.open("", "", "noreferrer"), a=testonly Automatic update from web-platform-tests HTML: window.open("", "", "noreferrer") For https://github.com/whatwg/html/pull/4331. -- wpt-commits: 22abb9c5c4a78f5deecc49417f5e57ba27f404cb wpt-pr: 15352
testing/web-platform/tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/open-features-tokenization-noopener.html
testing/web-platform/tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/open-features-tokenization-noreferrer.html
testing/web-platform/tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/resources/tokenization-noopener-noreferrer.js
testing/web-platform/tests/html/browsers/the-window-object/support/noreferrer-target.html
testing/web-platform/tests/html/browsers/the-window-object/window-open-noreferrer.html
--- a/testing/web-platform/tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/open-features-tokenization-noopener.html
+++ b/testing/web-platform/tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/open-features-tokenization-noopener.html
@@ -1,162 +1,11 @@
 <!DOCTYPE html>
 <meta charset="utf-8">
 <title>HTML: window.open `features`: tokenization -- `noopener`</title>
 <meta name=timeout content=long>
 <link rel="help" href="https://html.spec.whatwg.org/multipage/#apis-for-creating-and-navigating-browsing-contexts-by-name">
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
+<script src="resources/tokenization-noopener-noreferrer.js"></script>
 <script>
-var windowURL = 'resources/close-self.html';
-
-// Tests for how windows features are tokenized into 'name', 'value'
-// window features separators are ASCII whitespace, '=' and  ','
-
-test (t => {
-  // Tokenizing `name`: initial window features separators are ignored
-  // Each of these variants should tokenize to ('noopener', '')
-  var featureVariants = [
-    ' noopener',
-    '=noopener',
-    ',,noopener',
-    ',=, noopener',
-    '\n=noopener=',
-    '\tnoopener',
-    '\r,,,=noopener',
-    '\u000Cnoopener'
-  ];
-  featureVariants.forEach(feature => {
-    var win = window.open(windowURL, '', feature);
-    assert_equals(win, null, `"${feature}" should activate feature "noopener"`);
-  });
-}, 'tokenization should skip window features separators before `name`');
-
-test (t => {
-  // Tokenizing `name`: lowercase conversion
-  // Each of these variants should tokenize as feature ('noopener', '')
-  // except where indicated
-  // Note also that `value` is lowercased during tokenization
-  var featureVariants = [
-    'NOOPENER',
-    'noOpenER',
-    '  NOopener',
-    '=NOOPENER',
-    'noopener=1',
-    'NOOPENER=1',
-    'NOOPENER=yes',
-    'noopener=YES',
-  ];
-  featureVariants.forEach(feature => {
-    var win = window.open(windowURL, '', feature);
-    assert_equals(win, null, `"${feature}" should activate feature "noopener"`);
-  });
-}, 'feature `name` should be converted to ASCII lowercase');
-
-test (t => {
-  // After `name` has been collected, ignore any window features separators until '='
-  // except ',' OR a non-window-features-separator — break in those cases
-  // i.e. ignore whitespace until '=' unless a ',' is encountered first
-  // Each of these variants should tokenize as feature ('noopener', '')
-  var featureVariants = [
-    'noopener',
-    ' noopener\r',
-    'noopener\n =',
-    'noopener,',
-    'noopener  =,',
-    ', noopener   =',
-    'noopener,=',
-    'noopener foo', // => ('noopener', ''), ('foo', '')
-    'foo noopener=1', // => ('foo', ''), ('noopener', '1')
-    'foo=\u000Cbar\u000Cnoopener' // => ('foo', 'bar'), ('noopener', '')
-  ];
-  featureVariants.forEach(feature => {
-    var win = window.open(windowURL, '', feature);
-    assert_equals(win, null, `"${feature}" should activate feature "noopener"`);
-  });
-}, 'after `name`, tokenization should skip window features separators that are not "=" or ","');
-
-test (t => {
-  // After initial '=', tokenizing should ignore all separators except ','
-  // before collecting `value`
-  // Each of these variants should tokenize as feature ('noopener', '')
-  // Except where indicated
-  var featureVariants = [
-    'noopener=  yes', // => ('noopener', 'yes')
-    'noopener==,',
-    'noopener=\n ,',
-    'noopener = \t ,',
-    'noopener\n=\r 1,', // => ('noopener', '1')
-    'noopener=,yes', // => ('noopener'), ('yes')
-    'noopener= yes=,', // => ('noopener', 'yes')
-    'noopener = \u000Cyes' // => ('noopener', 'yes')
-  ];
-  featureVariants.forEach(feature => {
-    var win = window.open(windowURL, '', feature);
-    assert_equals(win, null, `"${feature}" should activate feature "noopener"`);
-  });
-}, 'Tokenizing should ignore window feature separators except "," after initial "=" and before value');
-
-test (t => {
-  // Tokenizing `value` should collect any non-separator code points until first separator
-  var featureVariants = [
-    'noopener=1', // => ('noopener', 'noopener')
-    'noopener=yes', // => ('noopener', 'yes')
-    'noopener = yes ,', // => ('noopener', 'yes')
-    'noopener=\nyes  ,', // => ('noopener', 'yes')
-    'noopener=yes yes', // => ('noopener', 'yes'), ('yes', '')
-    'noopener=yes\ts', // => ('noopener', 'yes'), ('s', '')
-    'noopener==', // => ('noopener', '')
-    'noopener=1\n,', // => ('noopener', '1')
-    '==noopener===', // => ('noopener', '')
-    'noopener==\u000C' // => ('noopener', '')
-  ];
-  featureVariants.forEach(feature => {
-    var win = window.open(windowURL, '', feature);
-    assert_equals(win, null, `"${feature}" should set "noopener"`);
-  });
-}, 'Tokenizing should read characters until first window feature separator as `value`');
-
-test (t => {
-  var featureVariants = [
-    'noopener=1',
-    'noopener=2',
-    'noopener=12345',
-    'noopener=1.5',
-    'noopener=-1',
-  ];
-  featureVariants.forEach(feature => {
-    var win = window.open(windowURL, '', feature);
-    assert_equals(win, null, `"${feature}" should activate feature "noopener"`);
-  });
-}, 'Integer values other than 0 should activate the feature');
-
-test (t => {
-  var featureVariants = [
-    'noopener=0',
-    'noopener=0.5',
-    'noopener=error',
-  ];
-  featureVariants.forEach(feature => {
-    var win = window.open(windowURL, '', feature);
-    assert_not_equals(win, null, `"${feature}" should NOT activate feature "noopener"`);
-  });
-}, 'Integer value of 0 should not activate the feature');
-
-test (t => {
-  var invalidFeatureVariants = [
-    '-noopener', //     => ('-noopener', '')
-    'NOOPENERRRR', //   => ('noopenerrr', '')
-    'noOpenErR', //     => ('noopenerr', '')
-    'no_opener', //     => ('no_opener', '')
-    ' no opener', //    => ('no', ''), ('opener', '')
-    'no\nopener', //    => ('no', ''), ('opener', '')
-    'no,opener', //     => ('no', ''), ('opener', '')
-    '\0noopener', //    => ('\0noopener', '')
-    'noopener\u0000=yes', // => ('noopener\0', 'yes')
-    'foo=\u000Cnoopener' // => ('foo', 'noopener')
-  ];
-  invalidFeatureVariants.forEach(feature => {
-    var win = window.open(windowURL, '', feature);
-    assert_not_equals(win, null, `"${feature}" should NOT activate feature "noopener"`);
-  });
-}, 'invalid feature names should not tokenize as "noopener"');
+  booleanTests("noopener");
 </script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/open-features-tokenization-noreferrer.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>HTML: window.open `features`: tokenization -- `noreferrer`</title>
+<meta name=timeout content=long>
+<link rel="help" href="https://html.spec.whatwg.org/multipage/#apis-for-creating-and-navigating-browsing-contexts-by-name">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/tokenization-noopener-noreferrer.js"></script>
+<script>
+  booleanTests("noreferrer");
+</script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/resources/tokenization-noopener-noreferrer.js
@@ -0,0 +1,152 @@
+function booleanTests(feature) {
+  const windowURL = 'resources/close-self.html';
+  // Tests for how windows features are tokenized into 'name', 'value'
+  // window features separators are ASCII whitespace, '=' and  ','
+
+  const featureUpper = feature.toUpperCase(),
+        featureSplitBegin = feature.slice(0, 2),
+        featureSplitEnd = feature.slice(2),
+        featureMixedCase = featureSplitBegin.toUpperCase() + featureSplitEnd;
+        featureMixedCase2 = featureSplitBegin + featureSplitEnd.toUpperCase();
+
+  test (t => {
+    // Tokenizing `name`: initial window features separators are ignored
+    // Each of these variants should tokenize to (`${feature}`, '')
+    [
+      ` ${feature}`,
+      `=${feature}`,
+      `,,${feature}`,
+      `,=, ${feature}`,
+      `\n=${feature}=`,
+      `\t${feature}`,
+      `\r,,,=${feature}`,
+      `\u000C${feature}`
+    ].forEach(variant => {
+      const win = window.open(windowURL, "", variant);
+      assert_equals(win, null, `"${variant}" should activate feature "${feature}"`);
+    });
+  }, `Tokenization of "${feature}" should skip window features separators before feature`);
+
+  test (t => {
+    // Tokenizing `name`: lowercase conversion
+    // Each of these variants should tokenize as feature (`${feature}`, '')
+    // except where indicated
+    // Note also that `value` is lowercased during tokenization
+    [
+      `${featureUpper}`,
+      `${featureMixedCase}`,
+      `  ${featureMixedCase2}`,
+      `=${featureUpper}`,
+      `${featureUpper}=1`,
+      `${featureUpper}=1`,
+      `${featureUpper}=yes`,
+      `${feature}=YES`,
+    ].forEach(variant => {
+      const win = window.open(windowURL, '', variant);
+      assert_equals(win, null, `"${variant}" should activate feature "${feature}"`);
+    });
+  }, `Feature "${feature}" should be converted to ASCII lowercase`);
+
+  test (t => {
+    // After `name` has been collected, ignore any window features separators until '='
+    // except ',' OR a non-window-features-separator — break in those cases
+    // i.e. ignore whitespace until '=' unless a ',' is encountered first
+    // Each of these variants should tokenize as feature ('noopener', '')
+    [
+      `${feature}`,
+      ` ${feature}\r`,
+      `${feature}\n =`,
+      `${feature},`,
+      `${feature}  =,`,
+      `, ${feature}   =`,
+      `${feature},=`,
+      `${feature} foo`,
+      `foo ${feature}=1`,
+      `foo=\u000Cbar\u000C${feature}`
+    ].forEach(variant => {
+      const win = window.open(windowURL, '', variant);
+      assert_equals(win, null, `"${variant}" should activate feature "${feature}"`);
+    });
+  }, `After "${feature}", tokenization should skip window features separators that are not "=" or ","`);
+
+  test (t => {
+    // After initial '=', tokenizing should ignore all separators except ','
+    // before collecting `value`
+    // Each of these variants should tokenize as feature ('noopener', '')
+    // Except where indicated
+    [
+      `${feature}=  yes`,
+      `${feature}==,`,
+      `${feature}=\n ,`,
+      `${feature} = \t ,`,
+      `${feature}\n=\r 1,`,
+      `${feature}=,yes`,
+      `${feature}= yes=,`,
+      `${feature} = \u000Cyes`
+    ].forEach(variant => {
+      const win = window.open(windowURL, '', variant);
+      assert_equals(win, null, `"${variant}" should activate feature "${feature}"`);
+    });
+  }, `Tokenizing "${feature}" should ignore window feature separators except "," after initial "=" and before value`);
+
+  test (t => {
+    // Tokenizing `value` should collect any non-separator code points until first separator
+    [
+      `${feature}=1`,
+      `${feature}=yes`,
+      `${feature} = yes ,`,
+      `${feature}=\nyes  ,`,
+      `${feature}=yes yes`,
+      `${feature}=yes\ts`,
+      `${feature}==`,
+      `${feature}=1\n,`,
+      `==${feature}===`,
+      `${feature}==\u000C`
+    ].forEach(variant => {
+      const win = window.open(windowURL, '', variant);
+      assert_equals(win, null, `"${variant}" should set "${feature}"`);
+    });
+  }, `Tokenizing "${feature}" should read characters until first window feature separator as \`value\``);
+
+  test (t => {
+    [
+      `${feature}=1`,
+      `${feature}=2`,
+      `${feature}=12345`,
+      `${feature}=1.5`,
+      `${feature}=-1`,
+    ].forEach(variant => {
+      const win = window.open(windowURL, '', variant);
+      assert_equals(win, null, `"${variant}" should activate feature "${feature}"`);
+    });
+  }, 'Integer values other than 0 should activate the feature');
+
+  test (t => {
+    [
+      `${feature}=0`,
+      `${feature}=0.5`,
+      `${feature}=error`,
+    ].forEach(variant => {
+      const win = window.open(windowURL, '', variant);
+      assert_not_equals(win, null, `"${variant}" should NOT activate feature "${feature}"`);
+    });
+  }, `Integer value of 0 should not activate "${feature}"`);
+
+  test (t => {
+    [
+      `-${feature}`,
+      `${featureUpper}RRR`,
+      `${featureMixedCase}R`,
+      `${featureSplitBegin}_${featureSplitEnd}`,
+      ` ${featureSplitBegin} ${featureSplitEnd}`,
+      `${featureSplitBegin}\n${featureSplitEnd}`,
+      `${featureSplitBegin},${featureSplitEnd}`,
+      `\0${feature}`,
+      `${feature}\u0000=yes`,
+      `foo=\u000C${feature}`
+    ].forEach(variant => {
+      const win = window.open(windowURL, '', variant);
+      assert_not_equals(win, null, `"${variant}" should NOT activate feature "${feature}"`);
+    });
+  }, `Invalid feature names should not tokenize as "${feature}"`);
+}
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/the-window-object/support/noreferrer-target.html
@@ -0,0 +1,13 @@
+<script>
+  const channelName = location.search.substr(1),
+        channel = new BroadcastChannel(channelName);
+  channel.postMessage({ name: window.name,
+                        haveOpener: window.opener !== null,
+                        referrer: document.referrer });
+
+  // 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 = () => window.close();
+</script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/browsers/the-window-object/window-open-noreferrer.html
@@ -0,0 +1,20 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>window.open() with "noreferrer" tests</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script>
+async_test(t => {
+  const channelName = "343243423432",
+        channel = new BroadcastChannel(channelName);
+  window.open("support/noreferrer-target.html?" + channelName, "", "noreferrer");
+  channel.onmessage = t.step_func_done(e => {
+    // Send message first so if asserts throw the popup is still closed
+    channel.postMessage(null);
+
+    assert_equals(e.data.name, "");
+    assert_equals(e.data.referrer, "");
+    assert_equals(e.data.haveOpener, false);
+  });
+});
+</script>