Truly independent web browser
Tests/LibWeb: Import WPT tests for window.open() feature tokenization
Andreas Kling8fda4c454f98
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/the-window-object/open-close/open-features-tokenization-noopener.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/the-window-object/open-close/open-features-tokenization-noopener.txtnew file mode 100644index 00000000000..16c4e09f6b4--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/the-window-object/open-close/open-features-tokenization-noopener.txt@@ -0,0 +1,14 @@+Harness status: OK++Found 8 tests++6 Pass+2 Fail+Pass Tokenization of "noopener" should skip window features separators before feature+Pass Feature "noopener" should be converted to ASCII lowercase+Fail After "noopener", tokenization should skip window features separators that are not "=" or ","+Pass Tokenizing "noopener" should ignore window feature separators except "," after initial "=" and before value+Pass Tokenizing "noopener" should read characters until first window feature separator as `value`+Fail Integer values other than 0 should activate the feature+Pass Integer value of 0 should not activate "noopener"+Pass Invalid feature names should not tokenize as "noopener"\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/the-window-object/open-close/open-features-tokenization-noreferrer.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/the-window-object/open-close/open-features-tokenization-noreferrer.txtnew file mode 100644index 00000000000..da44a2c5bfc--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/the-window-object/open-close/open-features-tokenization-noreferrer.txt@@ -0,0 +1,14 @@+Harness status: OK++Found 8 tests++6 Pass+2 Fail+Pass Tokenization of "noreferrer" should skip window features separators before feature+Pass Feature "noreferrer" should be converted to ASCII lowercase+Fail After "noreferrer", tokenization should skip window features separators that are not "=" or ","+Pass Tokenizing "noreferrer" should ignore window feature separators except "," after initial "=" and before value+Pass Tokenizing "noreferrer" should read characters until first window feature separator as `value`+Fail Integer values other than 0 should activate the feature+Pass Integer value of 0 should not activate "noreferrer"+Pass Invalid feature names should not tokenize as "noreferrer"\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/the-window-object/open-close/open-features-tokenization-noopener.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/the-window-object/open-close/open-features-tokenization-noopener.htmlnew file mode 100644index 00000000000..3cbc277afcb--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/the-window-object/open-close/open-features-tokenization-noopener.html@@ -0,0 +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>+ booleanTests("noopener");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/the-window-object/open-close/open-features-tokenization-noreferrer.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/the-window-object/open-close/open-features-tokenization-noreferrer.htmlnew file mode 100644index 00000000000..40c044186db--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/the-window-object/open-close/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>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/the-window-object/open-close/resources/close-self.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/the-window-object/open-close/resources/close-self.htmlnew file mode 100644index 00000000000..0c0cf9fc491--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/the-window-object/open-close/resources/close-self.html@@ -0,0 +1,3 @@+<script>+ window.close();+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/the-window-object/open-close/resources/tokenization-noopener-noreferrer.js b/Tests/LibWeb/Text/input/wpt-import/html/browsers/the-window-object/open-close/resources/tokenization-noopener-noreferrer.jsnew file mode 100644index 00000000000..58610b607ec--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/the-window-object/open-close/resources/tokenization-noopener-noreferrer.js@@ -0,0 +1,153 @@+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}`,+ `\u000B${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}"`);+}