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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/claim-not-using-registration.html

Issue 2763123002: Upstream service worker `claim` tests to WPT (Closed)
Patch Set: Persist Chromium-specific version of test Created 3 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <title>Service Worker: claim client not using registration</title>
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script>
5 <script src="resources/test-helpers.js"></script>
6 <body>
7 <script>
8
9 promise_test(function(t) {
10 var init_scope = 'resources/blank.html?not-using-init';
11 var claim_scope = 'resources/blank.html?not-using';
12 var init_worker_url = 'resources/empty.js';
13 var claim_worker_url = 'resources/claim-worker.js';
14 var claim_worker, claim_registration, frame1, frame2;
15 return service_worker_unregister_and_register(
16 t, init_worker_url, init_scope)
17 .then(function(registration) {
18 return wait_for_state(t, registration.installing, 'activated');
19 })
20 .then(function() {
21 return Promise.all(
22 [with_iframe(init_scope), with_iframe(claim_scope)]);
23 })
24 .then(function(frames) {
25 frame1 = frames[0];
26 frame2 = frames[1];
27 assert_equals(
28 frame1.contentWindow.navigator.serviceWorker.controller.scriptURL,
29 normalizeURL(init_worker_url),
30 'Frame1 controller should not be null');
31 assert_equals(
32 frame2.contentWindow.navigator.serviceWorker.controller, null,
33 'Frame2 controller should be null');
34 return navigator.serviceWorker.register(claim_worker_url,
35 {scope: claim_scope});
36 })
37 .then(function(registration) {
38 claim_worker = registration.installing;
39 claim_registration = registration;
40 return wait_for_state(t, registration.installing, 'activated');
41 })
42 .then(function() {
43 var saw_controllerchanged = new Promise(function(resolve) {
44 frame2.contentWindow.navigator.serviceWorker.oncontrollerchange =
45 function() { resolve(); }
46 });
47 var channel = new MessageChannel();
48 var saw_message = new Promise(function(resolve) {
49 channel.port1.onmessage = t.step_func(function(e) {
50 assert_equals(e.data, 'PASS',
51 'Worker call to claim() should fulfill.');
52 resolve();
53 });
54 });
55 claim_worker.postMessage({port: channel.port2}, [channel.port2]);
56 return Promise.all([saw_controllerchanged, saw_message]);
57 })
58 .then(function() {
59 assert_equals(
60 frame1.contentWindow.navigator.serviceWorker.controller.scriptURL,
61 normalizeURL(init_worker_url),
62 'Frame1 should not be influenced');
63 assert_equals(
64 frame2.contentWindow.navigator.serviceWorker.controller.scriptURL,
65 normalizeURL(claim_worker_url),
66 'Frame2 should be controlled by the new registration');
67 frame1.remove();
68 frame2.remove();
69 return claim_registration.unregister();
70 })
71 .then(function() {
72 return service_worker_unregister_and_done(t, init_scope);
73 });
74 }, 'Test claim client which is not using registration');
75
76 promise_test(function(t) {
77 var scope = 'resources/blank.html?longer-matched';
78 var claim_scope = 'resources/blank.html?longer';
79 var claim_worker_url = 'resources/claim-worker.js';
80 var installing_worker_url = 'resources/empty-worker.js';
81 var frame, claim_worker;
82 return with_iframe(scope)
83 .then(function(f) {
84 frame = f;
85 return navigator.serviceWorker.register(
86 claim_worker_url, {scope: claim_scope});
87 })
88 .then(function(registration) {
89 claim_worker = registration.installing;
90 return wait_for_state(t, registration.installing, 'activated');
91 })
92 .then(function() {
93 return navigator.serviceWorker.register(
94 installing_worker_url, {scope: scope});
95 })
96 .then(function() {
97 var channel = new MessageChannel();
98 var saw_message = new Promise(function(resolve) {
99 channel.port1.onmessage = t.step_func(function(e) {
100 assert_equals(e.data, 'PASS',
101 'Worker call to claim() should fulfill.');
102 resolve();
103 });
104 });
105 claim_worker.postMessage({port: channel.port2}, [channel.port2]);
106 return saw_message;
107 })
108 .then(function() {
109 assert_equals(
110 frame.contentWindow.navigator.serviceWorker.controller, null,
111 'Frame should not be claimed when a longer-matched ' +
112 'registration exists');
113 frame.remove();
114 return service_worker_unregister(t, claim_scope);
115 })
116 .then(function() {
117 return service_worker_unregister_and_done(t, scope);
118 });
119 }, 'Test claim client when there\'s a longer-matched registration not ' +
120 'already used by the page');
121
122 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698