Bug 1809518 - Update test_fetch_event* related tests based on the status of the ORB r=farre

These tests involve a bunch of no-cors fetch requests which use
`file_CrossSiteXHR_server.sjs` for sending the response back.
Depends on the request's URL, the response can possibly be

```
  response.setHeader("Content-Type", "application/xml", false);
  response.write("<res>hello pass</res>\n");
```

which will make JS validator to run and blocks.

The fix here is to toggle the pref of ORB when running the tests,
so we test both with ORB and without ORB behaviors, with different
expectations.

Differential Revision: https://phabricator.services.mozilla.com/D169276
This commit is contained in:
Sean Feng 2023-02-28 19:46:09 +00:00
parent 81c8e77c0d
commit 82e4a40be5
7 changed files with 198 additions and 6 deletions

View File

@ -453,6 +453,10 @@ fetch(
{ mode: "no-cors" }
).then(
function(res) {
my_ok(
!new URLSearchParams(location.search).has("orbEnabled"),
"no-cors Fetch request with invalid javascript content should be blocked if ORB is enabled"
);
my_ok(res.type == "opaque", "Response type should be opaque");
my_ok(res.status == 0, "Status should be 0");
res.text().then(function(body) {
@ -461,7 +465,10 @@ fetch(
});
},
function(e) {
my_ok(false, "no-cors Fetch failed");
my_ok(
new URLSearchParams(location.search).has("orbEnabled"),
"no-cors Fetch request with invalid javascript content should not be blocked if ORB disabled"
);
finish();
}
);
@ -487,6 +494,10 @@ fetch("opaque-on-same-origin").then(
expectAsyncResult();
fetch("http://example.com/opaque-no-cors", { mode: "no-cors" }).then(
function(res) {
my_ok(
!new URLSearchParams(location.search).has("orbEnabled"),
"intercepted opaque response for no-cors request with invalid javascript content should be blocked when ORB is enabled."
);
my_ok(
res.type == "opaque",
"intercepted opaque response for no-cors request should have type opaque."
@ -495,8 +506,8 @@ fetch("http://example.com/opaque-no-cors", { mode: "no-cors" }).then(
},
function(e) {
my_ok(
false,
"intercepted opaque response for no-cors request should pass."
new URLSearchParams(location.search).has("orbEnabled"),
"intercepted opaque response for no-cors request wth invalid javascript content should not be blocked when ORB is disabled."
);
finish();
}

View File

@ -172,7 +172,13 @@
};
gExpected++;
var worker = new Worker('fetch_worker_script.js');
var fetch_worker_script_url = 'fetch_worker_script.js';
const params = new URLSearchParams(window.location.search);
if (params.has("orbEnabled")) {
fetch_worker_script_url += "?orbEnabled";
}
var worker = new Worker(fetch_worker_script_url);
worker.onmessage = function(e) {
if (e.data == "finish") {
finish();

View File

@ -245,8 +245,12 @@ skip-if = serviceworker_e10s
skip-if = (os == "win" && processor == "aarch64") #bug 1535784
[test_fetch_event.html]
skip-if = debug # Bug 1262224
[test_fetch_event_no_orb.html]
skip-if = debug # Bug 1262224
[test_fetch_event_with_thirdpartypref.html]
skip-if = debug # Bug 1262224
[test_fetch_event_with_thirdpartypref_no_orb.html]
skip-if = debug # Bug 1262224
[test_fetch_integrity.html]
skip-if = serviceworker_e10s
support-files = console_monitor.js

View File

@ -47,7 +47,7 @@
}
});
var w = window.open("fetch/index.html");
var w = window.open("fetch/index.html?orbEnabled");
return p;
}
@ -68,6 +68,8 @@
["dom.serviceWorkers.exemptFromPerDomainMax", true],
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true],
["browser.opaqueResponseBlocking", true],
["browser.opaqueResponseBlocking.javascriptValidator", true]
]}, runTest);
</script>
</pre>

View File

@ -0,0 +1,76 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Bug 94048 - test install event.</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<script src="utils.js"></script>
<script class="testbody" type="text/javascript">
SimpleTest.requestCompleteLog();
var registration;
function simpleRegister() {
return navigator.serviceWorker.register("fetch_event_worker.js", { scope: "./fetch" })
.then(swr => {
registration = swr;
return waitForState(swr.installing, 'activated');
});
}
function unregister() {
return registration.unregister().then(function(success) {
ok(success, "Service worker should be unregistered successfully");
}, function(e) {
dump("SW unregistration error: " + e + "\n");
});
}
function testController() {
var p = new Promise(function(resolve, reject) {
window.onmessage = function(e) {
if (e.data.status == "ok") {
ok(e.data.result, e.data.message);
} else if (e.data.status == "done") {
window.onmessage = null;
w.close();
resolve();
}
}
});
var w = window.open("fetch/index.html");
return p;
}
function runTest() {
simpleRegister()
.then(testController)
.then(unregister)
.then(function() {
SimpleTest.finish();
}).catch(function(e) {
ok(false, "Some test failed with error " + e);
SimpleTest.finish();
});
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [
["dom.serviceWorkers.exemptFromPerDomainMax", true],
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true],
["browser.opaqueResponseBlocking", false],
]}, runTest);
</script>
</pre>
</body>
</html>

View File

@ -59,7 +59,7 @@
}
});
var w = window.open("fetch/index.html");
var w = window.open("fetch/index.html?orbEnabled");
return p;
}
@ -83,6 +83,8 @@
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true],
["network.cookie.cookieBehavior", COOKIE_BEHAVIOR_REJECTFOREIGN],
["browser.opaqueResponseBlocking", true],
["browser.opaqueResponseBlocking.javascriptValidator", true]
]}, runTest);
</script>
</pre>

View File

@ -0,0 +1,91 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Bug 94048 - test install event.</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<script src="utils.js"></script>
<script class="testbody" type="text/javascript">
// NOTE: This is just test_fetch_event.html but with an alternate cookie
// mode preference set to make sure that setting the preference does
// not break interception as observed in bug 1336364.
// TODO: Refactor this test so it doesn't duplicate so much code logic.
SimpleTest.requestCompleteLog();
var registration;
function simpleRegister() {
return navigator.serviceWorker.register("fetch_event_worker.js", { scope: "./fetch" })
.then(swr => {
registration = swr;
return waitForState(swr.installing, 'activated');
});
}
function unregister() {
return registration.unregister().then(function(success) {
ok(success, "Service worker should be unregistered successfully");
}, function(e) {
dump("SW unregistration error: " + e + "\n");
});
}
function testController() {
var p = new Promise(function(resolve, reject) {
var reloaded = false;
window.onmessage = function(e) {
if (e.data.status == "ok") {
ok(e.data.result, e.data.message);
} else if (e.data.status == "done") {
if (reloaded) {
window.onmessage = null;
w.close();
resolve();
} else {
w.location.reload();
reloaded = true;
}
}
}
});
var w = window.open("fetch/index.html");
return p;
}
function runTest() {
simpleRegister()
.then(testController)
.then(unregister)
.then(function() {
SimpleTest.finish();
}).catch(function(e) {
ok(false, "Some test failed with error " + e);
SimpleTest.finish();
});
}
const COOKIE_BEHAVIOR_REJECTFOREIGN = 1;
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [
["dom.serviceWorkers.exemptFromPerDomainMax", true],
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true],
["network.cookie.cookieBehavior", COOKIE_BEHAVIOR_REJECTFOREIGN],
["browser.opaqueResponseBlocking", false],
]}, runTest);
</script>
</pre>
</body>
</html>