Skip to content

Instantly share code, notes, and snippets.

@jugglinmike
Last active March 28, 2017 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jugglinmike/4a5bdf1172a407b730b4f6f5d0881863 to your computer and use it in GitHub Desktop.
Save jugglinmike/4a5bdf1172a407b730b4f6f5d0881863 to your computer and use it in GitHub Desktop.
ServiceWorker migration: controller tests
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/controller-on-load.html b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/controller-on-load.https.html
index 99bdc20..ff3b7ce 100644
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/controller-on-load.html
+++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/controller-on-load.https.html
@@ -1,27 +1,42 @@
<!DOCTYPE html>
<title>Service Worker: Controller on load</title>
-<script src="../resources/testharness.js"></script>
-<script src="../resources/testharnessreport.js"></script>
-<script src="resources/test-helpers.js"></script>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.sub.js"></script>
<body>
<script>
var t = async_test('controller is set for a controlled document');
t.step(function() {
var url = 'resources/empty-worker.js';
var scope = 'resources/blank.html';
+ var registration;
+ var controller;
+ var frame;
service_worker_unregister_and_register(t, url, scope)
- .then(t.step_func(function(registration) {
+ .then(t.step_func(function(swr) {
+ registration = swr;
return wait_for_state(t, registration.installing, 'activated');
}))
.then(t.step_func(function() {
- return with_iframe(scope);
+ return with_iframe(scope)
}))
- .then(t.step_func(function(frame) {
+ .then(t.step_func(function(f) {
+ frame = f;
var w = frame.contentWindow;
- var controller = w.navigator.serviceWorker.controller;
+ controller = w.navigator.serviceWorker.controller;
assert_true(controller instanceof w.ServiceWorker,
'controller should be a ServiceWorker object');
assert_equals(controller.scriptURL, normalizeURL(url));
+
+ // objects from different windows should not be equal
+ assert_not_equals(controller, registration.active);
+
+ return w.navigator.serviceWorker.getRegistration();
+ }))
+ .then(t.step_func(function(frameRegistration) {
+ // SW objects from same window should be equal
+ assert_equals(frameRegistration.active, controller);
+ frame.remove();
service_worker_unregister_and_done(t, scope);
}))
.catch(unreached_rejection(t));
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/controller-on-reload.html b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/controller-on-reload.https.html
index 079476f..e0beb72 100644
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/controller-on-reload.html
+++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/controller-on-reload.https.html
@@ -1,13 +1,16 @@
<!DOCTYPE html>
<title>Service Worker: Controller on reload</title>
-<script src="../resources/testharness.js"></script>
-<script src="../resources/testharnessreport.js"></script>
-<script src="resources/test-helpers.js"></script>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.sub.js"></script>
<body>
<script>
promise_test(function(t) {
- var scope = 'resources/blank.html';
+ const iframe_scope = 'blank.html';
+ const scope = 'resources/' + iframe_scope;
var frame;
+ var registration;
+ var controller;
return service_worker_unregister(t, scope)
.then(function() {
return with_iframe(scope);
@@ -15,9 +18,10 @@ promise_test(function(t) {
.then(function(f) {
frame = f;
return frame.contentWindow.navigator.serviceWorker.register(
- 'empty-worker.js', {scope: 'blank.html'});
+ 'empty-worker.js', {scope: iframe_scope});
})
- .then(function(registration) {
+ .then(function(swr) {
+ registration = swr;
return wait_for_state(t, registration.installing, 'activated');
})
.then(function() {
@@ -32,9 +36,17 @@ promise_test(function(t) {
})
.then(function() {
var w = frame.contentWindow;
- assert_true(
- w.navigator.serviceWorker.controller instanceof w.ServiceWorker,
- 'controller should be a ServiceWorker object upon reload');
+ controller = w.navigator.serviceWorker.controller;
+ assert_true(controller instanceof w.ServiceWorker,
+ 'controller should be a ServiceWorker object upon reload');
+
+ // objects from separate windows should not be equal
+ assert_not_equals(controller, registration.active);
+
+ return w.navigator.serviceWorker.getRegistration(iframe_scope);
+ })
+ .then(function(frameRegistration) {
+ assert_equals(frameRegistration.active, controller);
frame.remove();
service_worker_unregister_and_done(t, scope);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment