Bug 1664542 - Part 2: Test client.openWindow/COOP+COEP, r=asuth

Differential Revision: https://phabricator.services.mozilla.com/D90624
This commit is contained in:
Nika Layzell 2020-09-24 16:34:28 +00:00
Родитель 3feec09438
Коммит 028b755895
6 изменённых файлов: 117 добавлений и 67 удалений

Просмотреть файл

@ -196,7 +196,7 @@ support-files =
header_checker.sjs
openWindow_worker.js
redirect.sjs
open_window/client.html
open_window/client.sjs
lorem_script.js
file_blob_response_worker.js
file_js_cache_cleanup.js

Просмотреть файл

@ -2,7 +2,9 @@
// the timeout values.
var client;
var window_count = 0;
var expected_window_count = 7;
var expected_window_count = 9;
var isolated_window_count = 0;
var expected_isolated_window_count = 2;
var resolve_got_all_windows = null;
var got_all_windows = new Promise(function(res, rej) {
resolve_got_all_windows = res;
@ -71,8 +73,12 @@ onmessage = function(event) {
})
);
}
if (event.data == "NEW_WINDOW") {
if (event.data == "NEW_WINDOW" || event.data == "NEW_ISOLATED_WINDOW") {
window_count += 1;
if (event.data == "NEW_ISOLATED_WINDOW") {
isolated_window_count += 1;
}
if (window_count == expected_window_count) {
resolve_got_all_windows();
}
@ -85,10 +91,16 @@ onmessage = function(event) {
return clients.matchAll();
})
.then(function(cl) {
event.source.postMessage({
result: cl.length == expected_window_count,
message: "The number of windows is correct.",
});
event.source.postMessage([
{
result: cl.length == expected_window_count,
message: `The number of windows is correct. ${cl.length} == ${expected_window_count}`,
},
{
result: isolated_window_count == expected_isolated_window_count,
message: `The number of isolated windows is correct. ${isolated_window_count} == ${expected_isolated_window_count}`,
},
]);
for (i = 0; i < cl.length; i++) {
cl[i].postMessage("CLOSE");
}
@ -106,21 +118,21 @@ onnotificationclick = function(e) {
var redirect_xorigin =
"http://example.com/tests/dom/serviceworkers/test/redirect.sjs?";
var same_origin =
"http://mochi.test:8888/tests/dom/serviceworkers/test/open_window/client.html";
"http://mochi.test:8888/tests/dom/serviceworkers/test/open_window/client.sjs";
var different_origin =
"http://example.com/tests/dom/serviceworkers/test/open_window/client.html";
"http://example.com/tests/dom/serviceworkers/test/open_window/client.sjs";
promises.push(testForUrl("about:blank", "TypeError", null, results));
promises.push(testForUrl(different_origin, null, null, results));
promises.push(testForUrl(same_origin, null, { url: same_origin }, results));
promises.push(
testForUrl("open_window/client.html", null, { url: same_origin }, results)
testForUrl("open_window/client.sjs", null, { url: same_origin }, results)
);
// redirect tests
promises.push(
testForUrl(
redirect + "open_window/client.html",
redirect + "open_window/client.sjs",
null,
{ url: same_origin },
results
@ -129,12 +141,7 @@ onnotificationclick = function(e) {
promises.push(testForUrl(redirect + different_origin, null, null, results));
promises.push(
testForUrl(
redirect_xorigin + "open_window/client.html",
null,
null,
results
)
testForUrl(redirect_xorigin + "open_window/client.sjs", null, null, results)
);
promises.push(
testForUrl(
@ -145,6 +152,24 @@ onnotificationclick = function(e) {
)
);
// coop+coep tests
promises.push(
testForUrl(
same_origin + "?crossOriginIsolated=true",
null,
{ url: same_origin + "?crossOriginIsolated=true" },
results
)
);
promises.push(
testForUrl(
different_origin + "?crossOriginIsolated=true",
null,
null,
results
)
);
e.waitUntil(
Promise.all(promises).then(function() {
client.postMessage(results);

Просмотреть файл

@ -1,48 +0,0 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Bug 1172870 - page opened by ServiceWorkerClients.OpenWindow</title>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<script class="testbody" type="text/javascript">
window.onload = function() {
if (window.location == "http://mochi.test:8888/tests/dom/serviceworkers/test/open_window/client.html") {
navigator.serviceWorker.ready.then(function(result) {
navigator.serviceWorker.onmessage = function(event) {
if (event.data !== "CLOSE") {
dump("ERROR: unexepected reply from the service worker.\n");
}
if (parent) {
parent.postMessage("CLOSE", "*");
}
window.close();
}
navigator.serviceWorker.controller.postMessage("NEW_WINDOW");
})
} else {
window.onmessage = function(event) {
if (event.data !== "CLOSE") {
dump("ERROR: unexepected reply from the iframe.\n");
}
window.close();
}
var iframe = document.createElement('iframe');
iframe.src = "http://mochi.test:8888/tests/dom/serviceworkers/test/open_window/client.html";
document.body.appendChild(iframe);
}
}
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -0,0 +1,69 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const RESPONSE = `
<!DOCTYPE HTML>
<html>
<head>
<title>Bug 1172870 - page opened by ServiceWorkerClients.OpenWindow</title>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<h1>client.sjs</h1>
<script class="testbody" type="text/javascript">
window.onload = function() {
if (document.domain === "mochi.test") {
navigator.serviceWorker.ready.then(function(result) {
navigator.serviceWorker.onmessage = function(event) {
if (event.data !== "CLOSE") {
dump("ERROR: unexepected reply from the service worker.\\n");
}
if (parent) {
parent.postMessage("CLOSE", "*");
}
window.close();
}
let message = window.crossOriginIsolated ? "NEW_ISOLATED_WINDOW" : "NEW_WINDOW";
navigator.serviceWorker.controller.postMessage(message);
})
} else {
window.onmessage = function(event) {
if (event.data !== "CLOSE") {
dump("ERROR: unexepected reply from the iframe.\\n");
}
window.close();
}
var iframe = document.createElement('iframe');
iframe.src = "http://mochi.test:8888/tests/dom/serviceworkers/test/open_window/client.sjs";
document.body.appendChild(iframe);
}
}
</script>
</pre>
</body>
</html>
`;
function handleRequest(request, response) {
Components.utils.importGlobalProperties(["URLSearchParams"]);
let query = new URLSearchParams(request.queryString);
// If the request has been marked to be isolated with COOP+COEP, set the appropriate headers.
if (query.get("crossOriginIsolated") == "true") {
response.setHeader("Cross-Origin-Opener-Policy", "same-origin", false);
}
// Always set the COEP and CORP headers, so that this document can be framed
// by a document which has also set COEP to require-corp.
response.setHeader("Cross-Origin-Embedder-Policy", "require-corp", false);
response.setHeader("Cross-Origin-Resource-Policy", "cross-origin", false);
response.setHeader("Content-Type", "text/html", false);
response.write(RESPONSE);
}

Просмотреть файл

@ -63,7 +63,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1172870
return new Promise(function(res, rej) {
navigator.serviceWorker.onmessage = function(event) {
navigator.serviceWorker.onmessage = null;
ok(event.data.result, event.data.message);
for (i = 0; i < event.data.length; i++) {
ok(event.data[i].result, event.data[i].message);
}
res(ctx);
}
ctx.registration.active.postMessage("CHECK_NUMBER_OF_WINDOWS");
@ -102,7 +104,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1172870
["notification.prompt.testing", true],
["dom.serviceWorkers.disable_open_click_delay", 1000],
["dom.serviceWorkers.idle_timeout", 299999],
["dom.serviceWorkers.idle_extended_timeout", 299999]
["dom.serviceWorkers.idle_extended_timeout", 299999],
["dom.securecontext.whitelist", "mochi.test,example.com"],
]}, runTest);
</script>
</body>

Просмотреть файл

@ -153,6 +153,7 @@ avoid-blacklist-and-whitelist:
- dom/security/test/csp/test_worker_src.html
- dom/security/test/unit/test_isOriginPotentiallyTrustworthy.js
- dom/serviceworkers/test/test_error_reporting.html
- dom/serviceworkers/test/test_openWindow.html
- dom/smil/SMILTimeValueSpec.cpp
- dom/smil/SMILTimeValueSpec.h
- dom/tests/mochitest/dom-level0/idn_child.html