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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/claim-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 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 <script>
7
8 promise_test(function(t) {
9 var scope = 'resources/';
10 var frame_url = 'resources/blank.html?using-different-registration';
11 var url1 = 'resources/empty.js';
12 var url2 = 'resources/claim-worker.js';
13 var worker, sw_registration, frame;
14 return service_worker_unregister_and_register(t, url1, scope)
15 .then(function(registration) {
16 return wait_for_state(t, registration.installing, 'activated');
17 })
18 .then(function() {
19 return with_iframe(frame_url);
20 })
21 .then(function(f) {
22 frame = f;
23 return navigator.serviceWorker.register(url2, {scope: frame_url});
24 })
25 .then(function(registration) {
26 worker = registration.installing;
27 sw_registration = registration;
28 return wait_for_state(t, registration.installing, 'activated');
29 })
30 .then(function() {
31 var saw_controllerchanged = new Promise(function(resolve) {
32 frame.contentWindow.navigator.serviceWorker.oncontrollerchange =
33 function() { resolve(); }
34 });
35 var channel = new MessageChannel();
36 var saw_message = new Promise(function(resolve) {
37 channel.port1.onmessage = t.step_func(function(e) {
38 assert_equals(e.data, 'PASS',
39 'Worker call to claim() should fulfill.');
40 resolve();
41 });
42 });
43 worker.postMessage({port: channel.port2}, [channel.port2]);
44 return Promise.all([saw_controllerchanged, saw_message]);
45 })
46 .then(function() {
47 assert_equals(
48 frame.contentWindow.navigator.serviceWorker.controller.scriptURL,
49 normalizeURL(url2),
50 'Frame1 controller scriptURL should be changed to url2');
51 frame.remove();
52 return sw_registration.unregister();
53 })
54 .then(function() {
55 return service_worker_unregister_and_done(t, scope);
56 });
57 }, 'Test worker claims client which is using another registration');
58
59 promise_test(function(t) {
60 var scope = 'resources/blank.html?using-same-registration';
61 var url1 = 'resources/empty.js';
62 var url2 = 'resources/claim-worker.js';
63 var frame, worker;
64 return service_worker_unregister_and_register(t, url1, scope)
65 .then(function(registration) {
66 return wait_for_state(t, registration.installing, 'activated');
67 })
68 .then(function() {
69 return with_iframe(scope);
70 })
71 .then(function(f) {
72 frame = f;
73 return navigator.serviceWorker.register(url2, {scope: scope});
74 })
75 .then(function(registration) {
76 worker = registration.installing;
77 return wait_for_state(t, registration.installing, 'installed');
78 })
79 .then(function() {
80 var channel = new MessageChannel();
81 var saw_message = new Promise(function(resolve) {
82 channel.port1.onmessage = t.step_func(function(e) {
83 assert_equals(e.data, 'FAIL: exception: InvalidStateError',
84 'Worker call to claim() should reject with ' +
85 'InvalidStateError');
86 resolve();
87 });
88 });
89 worker.postMessage({port: channel.port2}, [channel.port2]);
90 return saw_message;
91 })
92 .then(function() {
93 frame.remove();
94 return service_worker_unregister_and_done(t, scope);
95 });
96 }, 'Test for the waiting worker claims a client which is using the the ' +
97 'same registration');
98
99 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698