зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1589708 - Part 1: Test service worker registration after restart r=dom-workers-and-storage-reviewers,marionette-reviewers,perry,whimboo
This test (which currently fails) verifies that when the browser is configured to delete caches on shutdown, service worker registrations are cleared as well. Differential Revision: https://phabricator.services.mozilla.com/D56421 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
f77c5bb7b9
Коммит
07aa429a11
|
@ -15,3 +15,6 @@
|
|||
|
||||
# autoconfig tests
|
||||
[include:../../../../../extensions/pref/autoconfig/test/marionette/manifest.ini]
|
||||
|
||||
# cleardata tests
|
||||
[include:../../../../../toolkit/components/cleardata/tests/marionette/manifest.ini]
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Install Service Worker</title>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
navigator.serviceWorker.register("serviceworker.js");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
[test_service_worker_at_shutdown.py]
|
||||
fail-if = !release_or_beta
|
|
@ -0,0 +1,53 @@
|
|||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
from marionette_driver import Wait
|
||||
from marionette_harness import MarionetteTestCase
|
||||
|
||||
|
||||
class ServiceWorkerAtShutdownTestCase(MarionetteTestCase):
|
||||
def setUp(self):
|
||||
super(ServiceWorkerAtShutdownTestCase, self).setUp()
|
||||
self.install_service_worker()
|
||||
self.set_pref_to_delete_site_data_on_shutdown()
|
||||
|
||||
def tearDown(self):
|
||||
self.marionette.restart(clean=True)
|
||||
super(ServiceWorkerAtShutdownTestCase, self).tearDown()
|
||||
|
||||
def install_service_worker(self):
|
||||
install_url = self.marionette.absolute_url("serviceworker/install_serviceworker.html")
|
||||
self.marionette.navigate(install_url)
|
||||
Wait(self.marionette).until(lambda _: self.is_service_worker_registered)
|
||||
|
||||
def set_pref_to_delete_site_data_on_shutdown(self):
|
||||
self.marionette.set_pref("network.cookie.lifetimePolicy", 2)
|
||||
|
||||
def test_unregistering_service_worker_when_clearing_data(self):
|
||||
self.marionette.restart(clean=False, in_app=True)
|
||||
self.assertFalse(self.is_service_worker_registered)
|
||||
|
||||
@property
|
||||
def is_service_worker_registered(self):
|
||||
with self.marionette.using_context("chrome"):
|
||||
return self.marionette.execute_script("""
|
||||
let serviceWorkerManager = Cc["@mozilla.org/serviceworkers/manager;1"].getService(
|
||||
Ci.nsIServiceWorkerManager
|
||||
);
|
||||
|
||||
let principal =
|
||||
Services.scriptSecurityManager.createContentPrincipalFromOrigin(arguments[0]);
|
||||
|
||||
let serviceWorkers = serviceWorkerManager.getAllRegistrations();
|
||||
for (let i = 0; i < serviceWorkers.length; i++) {
|
||||
let sw = serviceWorkers.queryElementAt(
|
||||
i,
|
||||
Ci.nsIServiceWorkerRegistrationInfo
|
||||
);
|
||||
if (sw.principal.origin == principal.origin) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
""", script_args=(self.marionette.absolute_url(""),))
|
Загрузка…
Ссылка в новой задаче