Bug 1587794 - Add a test that verifies we don't crash on a disconnected global. r=perry

Because this seems fairly Gecko-specific, I've put this in our mozilla-specific
WPT dir.  This is as opposed to writing this as a mochitest.

If I run this test without the fix, the browser crashes.  If I run it with the fix, we
pass.

I run the test via
./mach wpt testing/web-platform/mozilla/tests/service-workers/update_completes_in_disconnected_global.https.html

Note that currently because of https://bugzilla.mozilla.org/show_bug.cgi?id=1587463#c13
I had to comment out the lsan_dir lines I refer to there locally to get the
test to run.

Depends on D49671

Differential Revision: https://phabricator.services.mozilla.com/D49672

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrew Sutherland 2019-10-17 22:56:31 +00:00
Родитель cb0f2f4a10
Коммит c5ea460d53
3 изменённых файлов: 65 добавлений и 0 удалений

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

@ -0,0 +1,2 @@
<!DOCTYPE html>
<title>Empty doc</title>

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

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

@ -0,0 +1,63 @@
<!DOCTYPE html>
<title>Service Worker: Disconnected Global Update()</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
<script>
'use strict';
/**
* Gecko-only pseudo-crash-test to verify that if we call
* ServiceWorkerRegistration.update() from a global that will be destroyed
* before any IPC call could return that we don't crash.
*
* We use an iframe to create a global that we can destroy on demand.
*/
promise_test(async function(t) {
const scope = 'resources/blank.html';
const sw_url = 'resources/empty.js';
let reg = await service_worker_unregister_and_register(t, sw_url, scope);
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});
// Wait for the worker to be activated so that we are in a known state.
await wait_for_state(t, reg.installing, 'activated');
let f = await with_iframe(scope);
let f_global = f.contentWindow;
// The frame should be controlled, although it's not necessary for the test.
assert_true(!!f_global.navigator.serviceWorker.controller);
t.add_cleanup(function() {
if (f) {
f.remove();
}
});
// Get a registration object that lives in the iframe's global.
let f_reg = await f_global.navigator.serviceWorker.getRegistration(reg.scope);
assert_true(!!f_reg, 'got registration');
assert_equals(reg.scope, f_reg.scope, 'Right registration');
// Trigger the update and destroy the global.
let update_resolved = false;
let update_rejected = false;
let update_promise = f_reg.update();
update_promise.then(
() => { update_resolved = true; }, () => { update_rejected = true; });
f.remove();
f = null;
f_global = null;
// Now we want to wait on an update call that should fire strictly after the
// update call above.
await reg.update();
assert_false(update_resolved, "frame update() should not have resolved");
assert_true(update_rejected, "frame update() should have rejected");
}, 'ServiceWorkerRegistration.update() concluding in a disconnected global');
</script>