Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Unified Diff: LayoutTests/http/tests/serviceworker/claim-using-registration.html

Issue 872593002: ServiceWorker: add ServiceWorkerClients.claim() support (3/3). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: change error type Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/http/tests/serviceworker/claim-using-registration.html
diff --git a/LayoutTests/http/tests/serviceworker/claim-using-registration.html b/LayoutTests/http/tests/serviceworker/claim-using-registration.html
new file mode 100644
index 0000000000000000000000000000000000000000..6809cce642d310d13e937af5aa185bc9cbfdf203
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/claim-using-registration.html
@@ -0,0 +1,97 @@
+<!DOCTYPE html>
+<title>Service Worker: claim client using registration</title>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharness-helpers.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.js"></script>
+<script>
+
+promise_test(function(t) {
+ var scope = 'resources/';
+ var frame_url = 'resources/blank.html';
+ var url1 = 'resources/empty.js';
+ var url2 = 'resources/claim-worker.js';
+ var worker, sw_registration, frame;
+ return service_worker_unregister_and_register(t, url1, scope)
+ .then(function(registration) {
+ return wait_for_state(t, registration.installing, 'activated');
+ })
+ .then(function() {
+ return with_iframe(frame_url);
+ })
+ .then(function(f) {
+ frame = f;
+ return navigator.serviceWorker.register(url2, {scope: frame_url});
+ })
+ .then(function(registration) {
+ worker = registration.installing;
+ sw_registration = registration;
+ return wait_for_state(t, registration.installing, 'activated');
+ })
+ .then(function() {
+ var saw_controllerchanged = new Promise(function(resolve) {
+ frame.contentWindow.navigator.serviceWorker.oncontrollerchange =
+ function() { resolve(); }
+ });
+ var channel = new MessageChannel();
+ var saw_message = new Promise(function(resolve) {
+ channel.port1.onmessage = t.step_func(function(e) {
+ assert_equals(e.data, 'PASS');
jsbell 2015/01/24 01:09:38 Can you add a message to this assertion? e.g. 'Wor
xiang 2015/01/26 07:19:16 Done.
+ resolve();
+ });
+ });
+ worker.postMessage({port: channel.port2}, [channel.port2]);
+ return Promise.all([saw_controllerchanged, saw_message]);
+ })
+ .then(function() {
+ assert_equals(
+ frame.contentWindow.navigator.serviceWorker.controller.scriptURL,
+ normalizeURL(url2),
+ 'Frame1 controller scriptURL should be changed to url2');
+ frame.remove();
+ return sw_registration.unregister();
+ })
+ .then(function() {
+ return service_worker_unregister_and_done(t, scope);
+ });
+ }, 'Test worker claim client which is using another registration');
+
+promise_test(function(t) {
+ var scope = 'resources/other.html';
+ var url1 = 'resources/empty.js';
+ var url2 = 'resources/claim-worker.js';
+ var frame, worker;
+ return service_worker_unregister_and_register(t, url1, scope)
+ .then(function(registration) {
+ return wait_for_state(t, registration.installing, 'activated');
+ })
+ .then(function() {
+ return with_iframe(scope);
+ })
+ .then(function(f) {
+ frame = f;
+ return navigator.serviceWorker.register(url2, {scope: scope});
+ })
+ .then(function(registration) {
+ worker = registration.installing;
+ return wait_for_state(t, registration.installing, 'installed');
+ })
+ .then(function() {
+ var channel = new MessageChannel();
+ var saw_message = new Promise(function(resolve) {
+ channel.port1.onmessage = t.step_func(function(e) {
+ assert_equals(e.data, 'FAIL: exception: InvalidStateError: ' +
jsbell 2015/01/24 01:09:38 Can you add a message to this assertion? e.g. 'Wor
xiang 2015/01/26 07:19:16 Done.
+ 'Only active worker can claim clients.');
jsbell 2015/01/24 01:09:38 Where is this message ("Only active worker...") co
xiang 2015/01/26 07:19:16 The message defined in https://codereview.chromium
+ resolve();
+ });
+ });
+ worker.postMessage({port: channel.port2}, [channel.port2]);
+ return saw_message;
+ })
+ .then(function() {
+ frame.remove();
+ return service_worker_unregister_and_done(t, scope);
+ });
+ }, 'Test installed worker claim client which is using the same registration');
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698