зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1383518 - Part 1: Augment test_formSubmission.html test to include ServiceWorker variants. r=bkelly
This test causes the expected serviceworker failure messages in the child process and then hangs the test. --HG-- extra : rebase_source : b1ea1db02d84ce7eb1e7b939cd1ef96825ab8e9f
This commit is contained in:
Родитель
9bd2e89d01
Коммит
792729291f
|
@ -184,6 +184,7 @@ support-files =
|
|||
file_bug1166138_2x.png
|
||||
file_bug1166138_def.png
|
||||
script_fakepath.js
|
||||
sw_formSubmission.js
|
||||
object_bug287465_o1.html
|
||||
object_bug287465_o2.html
|
||||
object_bug556645.html
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* We are used by test_formSubmission.html to immediately activate and start
|
||||
* controlling its page. We operate in 3 modes, conveyed via ?MODE appended to
|
||||
* our URL.
|
||||
*
|
||||
* - "no-fetch": Don't register a fetch listener so that the optimized fetch
|
||||
* event bypass happens.
|
||||
* - "reset-fetch": Do register a fetch listener, reset every interception.
|
||||
* - "proxy-fetch": Do register a fetch listener, resolve every interception
|
||||
* with fetch(event.request).
|
||||
*/
|
||||
|
||||
const mode = location.search.slice(1);
|
||||
|
||||
// Fetch handling.
|
||||
if (mode !== "no-fetch") {
|
||||
addEventListener("fetch", function(event) {
|
||||
if (mode === "reset-fetch") {
|
||||
// Don't invoke respondWith, resetting the interception.
|
||||
return;
|
||||
} else if (mode === "proxy-fetch") {
|
||||
// Per the spec, there's an automatic waitUntil() on this too.
|
||||
event.respondWith(fetch(event.request));
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Go straight to activation, bypassing waiting.
|
||||
addEventListener("install", function(event) {
|
||||
event.waitUntil(skipWaiting());
|
||||
});
|
||||
// Control the test document ASAP.
|
||||
addEventListener("activate", function(event) {
|
||||
event.waitUntil(clients.claim());
|
||||
});
|
|
@ -449,7 +449,7 @@ function onFilesOpened(files) {
|
|||
emptyFile = { name: "", type: "application/octet-stream" };
|
||||
|
||||
// Now, actually run the tests; see below.
|
||||
onFilesSet();
|
||||
runAllTestVariants();
|
||||
};
|
||||
|
||||
var expectedSub = [
|
||||
|
@ -678,13 +678,27 @@ function setDisabled(list, state) {
|
|||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* The below test function uses callbacks that invoke gen.next() rather than
|
||||
* creating and resolving Promises. I'm trying to minimize churn since these
|
||||
* changes want to be uplifted. Some kind soul might want to clean this all up
|
||||
* at some point.
|
||||
*/
|
||||
var gen;
|
||||
function onFilesSet() {
|
||||
gen = runTest();
|
||||
gen.next();
|
||||
$("target_iframe").onload = function() { gen.next(); };
|
||||
// Run the suite of tests for this variant, returning a Promise that will be
|
||||
// resolved when the batch completes. Then and only then runTestVariant may
|
||||
// be invoked to run a different variation.
|
||||
function runTestVariant(variantLabel) {
|
||||
info("starting test variant: " + variantLabel);
|
||||
return new Promise((resolve) => {
|
||||
// Instantiate the generator.
|
||||
gen = runTestVariantUsingWeirdGenDriver(resolve);
|
||||
// Run the generator to the first yield, at which point it is self-driving.
|
||||
gen.next();
|
||||
});
|
||||
}
|
||||
|
||||
function* runTest() {
|
||||
function* runTestVariantUsingWeirdGenDriver(finishedVariant) {
|
||||
// Set up the expectedSub array
|
||||
fileReader1 = new FileReader;
|
||||
fileReader1.readAsBinaryString(myFile1);
|
||||
|
@ -717,9 +731,11 @@ function* runTest() {
|
|||
|
||||
// multipart/form-data
|
||||
var iframe = $("target_iframe");
|
||||
iframe.onload = function() { gen.next(); };
|
||||
|
||||
// Make normal submission
|
||||
form.action = "form_submit_server.sjs";
|
||||
form.method = "POST";
|
||||
form.enctype = "multipart/form-data";
|
||||
form.submit();
|
||||
yield undefined; // Wait for iframe to load as a result of the submission
|
||||
var submission = JSON.parse(iframe.contentDocument.documentElement.textContent);
|
||||
|
@ -812,6 +828,71 @@ function* runTest() {
|
|||
checkMPSubmission(JSON.parse(xhr.responseText),
|
||||
expectedSub.concat(expectedAugment), "send augmented FormData");
|
||||
|
||||
finishedVariant();
|
||||
}
|
||||
|
||||
/**
|
||||
* Install our service-worker (parameterized by appending "?MODE"), which will
|
||||
* invoke skipWaiting() and clients.claim() to begin controlling us ASAP. We
|
||||
* wait on the controllerchange event
|
||||
*/
|
||||
async function installAndBeControlledByServiceWorker(mode) {
|
||||
const scriptURL = "sw_formSubmission.js?" + mode;
|
||||
const controllerChanged = new Promise((resolve) => {
|
||||
navigator.serviceWorker.addEventListener(
|
||||
"controllerchange", () => { resolve(); }, { once: true });
|
||||
});
|
||||
|
||||
info("installing ServiceWorker: " + scriptURL);
|
||||
const swr = await navigator.serviceWorker.register(scriptURL,
|
||||
{ scope: "./" });
|
||||
await controllerChanged;
|
||||
ok(navigator.serviceWorker.controller.scriptURL.endsWith(scriptURL),
|
||||
"controlled by the SW we expected");
|
||||
info("became controlled by ServiceWorker.");
|
||||
|
||||
return swr;
|
||||
}
|
||||
|
||||
async function runAllTestVariants() {
|
||||
// Run the test as it has historically been run, with no ServiceWorkers
|
||||
// anywhere!
|
||||
await runTestVariant("no ServiceWorker");
|
||||
|
||||
// Uncomment the below if something in the test seems broken and you're not
|
||||
// sure whether it's a side-effect of the multiple passes or not.
|
||||
//await runTestVariant("no ServiceWorker second paranoia time");
|
||||
|
||||
// Ensure ServiceWorkers are enabled and that testing mode (which disables
|
||||
// security checks) is on too.
|
||||
await SpecialPowers.pushPrefEnv({"set": [
|
||||
["dom.serviceWorkers.enabled", true],
|
||||
["dom.serviceWorkers.testing.enabled", true]
|
||||
]});
|
||||
|
||||
// Now run the test with a ServiceWorker that covers the scope but has no
|
||||
// fetch handler, so the optimization case will not actually dispatch a
|
||||
// "fetch" event, but some stuff will happen that can change things enough
|
||||
// to break them like in https://bugzilla.mozilla.org/show_bug.cgi?id=1383518.
|
||||
await installAndBeControlledByServiceWorker("no-fetch");
|
||||
await runTestVariant("ServiceWorker that does not listen for fetch events");
|
||||
|
||||
// Now the ServiceWorker does have a "fetch" event listener, but it will reset
|
||||
// interception every time. This is similar to the prior case but different
|
||||
// enough that it could break things in a different exciting way.
|
||||
await installAndBeControlledByServiceWorker("reset-fetch");
|
||||
await runTestVariant("ServiceWorker that resets all fetches");
|
||||
|
||||
// Now the ServiceWorker resolves the fetch event with `fetch(event.request)`
|
||||
// which makes little sense but is a thing that can happen.
|
||||
const swr = await installAndBeControlledByServiceWorker("proxy-fetch");
|
||||
await runTestVariant("ServiceWorker that proxies all fetches");
|
||||
|
||||
// cleanup.
|
||||
info("unregistering ServiceWorker");
|
||||
await swr.unregister();
|
||||
info("ServiceWorker uninstalled");
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче