Skip to content

Commit

Permalink
Move COOP parsing tests to the dispatcher. (web-platform-tests#33909)
Browse files Browse the repository at this point in the history
Similar to what was done for other COOP tests in
https://chromium-review.googlesource.com/c/chromium/src/+/3593078

Tests use a complex postMessage flow today, that can be replaced by
simple and more readable code using dispatcher.js

Bug: 1318373
Change-Id: I0e5f261ded77fbf07a25f2f45380d4e9522e7934
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3620319
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Arthur Hemery <ahemery@chromium.org>
Cr-Commit-Position: refs/heads/main@{#999403}

Co-authored-by: Arthur Hemery <ahemery@chromium.org>
  • Loading branch information
2 people authored and pull[bot] committed Nov 16, 2023
1 parent 2ef72f8 commit 1473779
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 52 deletions.
85 changes: 85 additions & 0 deletions html/cross-origin-opener-policy/header-parsing-failures.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!doctype html>
<meta charset=utf-8>
<meta name=timeout content=long>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="resources/common.js"></script>
<script src="resources/popup-test.js"></script>
<script>

[
// None of the following should be recognized as "same-origin" (hence the
// preserved opener).
{
"title": "coop with semi-column",
"coop": "same-origin;",
},
{
"title": "coop with vertical tab",
"coop": "\u000bsame-origin\u000b",
},
{
"title": "coop with form feed",
"coop": "\u000csame-origin\u000c",
},
{
"title": "coop with carriage return",
"coop": "\u000dsame-origin\u000d",
},
{
"title": "coop with capital letter",
"coop": "Same-origin",
},
{
"title": "coop with bad structured header 1",
"coop": "same-origin;\tfoo=bar",
},
{
"title": "coop with bad structured header 2",
"coop": "same-origin ;foo=bar",
},
{
"title": "coop with bad structured header 3",
"coop": "same-origin; foo=bar;",
},
{
"title": "coop as a structured header 'string' item",
"coop": "\"same-origin\"",
},
{
"title": "coop as a structured header 'byte sequence' item",
"coop": ":c2FtZS1vcmlnaW4=:",
},
{
"title": "coop as a structured header 'boolean' item",
"coop": "?1",
},
{
"title": "coop as a structured header 'integer or decimal' item",
"coop": "1",
},
{
"title": "coop as an unrecognized structured header type",
"coop": "$same-origin",
},
{
"title": "coop with duplicate value",
"coop": "same-origin same-origin",
},
{
// Note: comma must be escaped here to not mess with the WPT pipe function.
"title": "coop with duplicate value, separated by a comma",
"coop": "same-origin\\,same-origin",
},
{
"title": "coop with preceding asterisk character",
"coop": "*same-origin ",
}
].forEach(variant => {
popup_test(`Parsing ${variant.title}`, SAME_ORIGIN, variant.coop, "preserved");
});

</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<meta charset=utf-8>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="resources/common.js"></script>
<script src="resources/popup-test.js"></script>
<script>
popup_test(
`Simple document with non-ascii COOP header opening a same-origin popup`,
SAME_ORIGIN,
"unsafe-none",
"preserved");
</script>

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cross-Origin-Opener-Policy: same%FForigin
16 changes: 16 additions & 0 deletions html/cross-origin-opener-policy/header-parsing-repeated.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<meta charset=utf-8>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="resources/common.js"></script>
<script src="resources/popup-test.js"></script>
<script>
popup_test(
`Simple document with duplicated COOP header opening a same-origin popup`,
SAME_ORIGIN,
"unsafe-none",
"preserved");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Opener-Policy: same-origin
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!doctype html>
<meta charset=utf-8>
<meta name=timeout content=long>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="resources/common.js"></script>
<script src="resources/popup-test.js"></script>
<script>

[
// All of the following should be recognized as "same-origin" (hence the
// severed opener link).
{
"title": "coop with leading space",
"coop": " same-origin",
},
{
"title": "coop with trailing space",
"coop": "same-origin ",
},
{
"title": "coop with leading tab",
"coop": "\tsame-origin",
},
{
"title": "coop with trailing tab",
"coop": "same-origin\t",
},
{
"title": "coop with duplicate value, separated by semi-column",
"coop": "same-origin;same-origin",
},
{
"title": "coop with valid structured header",
"coop": "same-origin; foo=bar",
}
].forEach(variant => {
popup_test(`Parsing ${variant.title}`, SAME_ORIGIN, variant.coop, "severed");
});

</script>
52 changes: 0 additions & 52 deletions html/cross-origin-opener-policy/header-parsing.https.html

This file was deleted.

0 comments on commit 1473779

Please sign in to comment.