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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/synced-state.html

Issue 1872243002: ServiceWorker: Check the equality of JS-level SW/SWR objects (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unnecessary logs, fix messages and resolve the race condition Created 4 years, 8 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
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/serviceworker/registration-service-worker-attributes.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!doctype html> 1 <!doctype html>
2 <title>ServiceWorker: worker objects have synced state</title> 2 <title>ServiceWorker: worker objects have synced state</title>
3 <script src="../resources/testharness.js"></script> 3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script> 4 <script src="../resources/testharnessreport.js"></script>
5 <script src="resources/test-helpers.js"></script> 5 <script src="resources/test-helpers.js"></script>
6 <script> 6 <script>
7
8 function multiple_resolver(num_of_waiter, resolve) {
nhiroki 2016/04/13 05:44:10 Optional: 'barrier' (barrier_resolver?) would be c
shimazu (google) 2016/04/15 05:19:03 Done.
9 var counter = 0;
10 return function() {
11 counter++;
12 if (counter === num_of_waiter)
13 resolve();
14 }
15 }
16
7 // Tests that ServiceWorker objects representing the same Service Worker 17 // Tests that ServiceWorker objects representing the same Service Worker
8 // entity have the same state. JS object equality is not tested, since the spec 18 // entity have the same state. JS-level equality is now required according to
9 // does not require it. 19 // the spec.
10 promise_test(function(t) { 20 promise_test(function(t) {
11 var scope = 'resources/synced-state'; 21 var scope = 'resources/synced-state';
12 var script = 'resources/empty-worker.js'; 22 var script = 'resources/empty-worker.js';
13 return service_worker_unregister_and_register(t, script, scope) 23 return service_worker_unregister_and_register(t, script, scope)
14 .then(function(registration) { 24 .then(function(registration) {
nhiroki 2016/04/13 05:44:10 Can you add this? add_completion_callback(funct
shimazu (google) 2016/04/15 05:19:03 Done.
15 return new Promise(function(resolve) { 25 return new Promise(function(resolve) {
16 var step = 0; 26 var step = 0;
17 registration.installing.addEventListener('statechange', 27 var multiple_resolve = multiple_resolver(2, resolve);
18 function(e) { 28 registration.installing.addEventListener(
29 'statechange', function(e) {
30 navigator.serviceWorker.getRegistration(scope)
31 .then(function(r) {
32 assert_equals(r, registration,
33 'Equality of registration should ' +
34 'be kept all the time: ' + step);
nhiroki 2016/04/13 05:44:10 Hmm... this should work, but I'd prefer not to hav
shimazu (google) 2016/04/15 05:19:03 Done.
35 if (step == 3)
36 multiple_resolve();
37 });
19 step++; 38 step++;
20 if (step == 1) { 39 if (step == 1) {
21 assert_equals(e.currentTarget.state, 'installed', 40 assert_equals(e.currentTarget.state, 'installed',
22 'original SW should be installed'); 41 'original SW should be installed');
23 assert_equals(registration.installing, null, 42 assert_equals(registration.installing, null,
24 'in installed, .installing should be null'); 43 'in installed, .installing should be null');
25 assert_equals(registration.waiting.state, 'installed', 44 assert_equals(registration.waiting.state, 'installed',
26 'in installed, .waiting should be installed'); 45 'in installed, the state of .waiting ' +
46 'should be installed');
27 assert_equals(registration.active, null, 47 assert_equals(registration.active, null,
28 'in installed, .active should be null'); 48 'in installed, .active should be null');
49 assert_equals(registration.waiting, e.currentTarget,
50 '.waiting should be equal to the original ' +
51 'SW in installed');
29 } else if (step == 2) { 52 } else if (step == 2) {
30 assert_equals(e.currentTarget.state, 'activating', 53 assert_equals(e.currentTarget.state, 'activating',
31 'original SW should be activating'); 54 'original SW should be activating');
32 assert_equals(registration.installing, null, 55 assert_equals(registration.installing, null,
33 'in activating, .installing should be null'); 56 'in activating, .installing should be null');
34 assert_equals(registration.waiting, null, 57 assert_equals(registration.waiting, null,
35 'in activating, .waiting should be null'); 58 'in activating, .waiting should be null');
36 assert_equals( 59 assert_equals(registration.active.state, 'activating',
37 registration.active.state, 'activating', 60 'in activating, the state of .active ' +
38 'in activating, .active should be activating'); 61 'should be activating');
62 assert_equals(registration.active, e.currentTarget,
63 '.active should be equal to the original ' +
64 'SW in activating');
39 } else if (step == 3) { 65 } else if (step == 3) {
40 assert_equals(e.currentTarget.state, 'activated', 66 assert_equals(e.currentTarget.state, 'activated',
41 'original SW should be activated'); 67 'original SW should be activated');
42 assert_equals(registration.installing, null, 68 assert_equals(registration.installing, null,
43 'in activated, .installing should be null'); 69 'in activated, .installing should be null');
44 assert_equals(registration.waiting, null, 70 assert_equals(registration.waiting, null,
45 'in activated, .waiting should be null'); 71 'in activated, .waiting should be null');
46 assert_equals(registration.active.state, 'activated', 72 assert_equals(registration.active.state, 'activated',
47 'in activated .active should be activated'); 73 'in activated, the state of .active should ' +
48 resolve(); 74 'be activated');
75 assert_equals(registration.active, e.currentTarget,
76 '.active should be equal to the original ' +
77 'SW in activated');
78 multiple_resolve();
49 } 79 }
50 }) 80 });
51 }) 81 });
52 }) 82 })
53 .then(function() { 83 .then(function() {
54 return service_worker_unregister_and_done(t, scope); 84 return service_worker_unregister_and_done(t, scope);
nhiroki 2016/04/13 05:44:10 (Not related to your changes) We don't have to ca
shimazu (google) 2016/04/15 05:19:03 Done.
55 }); 85 });
56 }, 'worker objects for the same entity have the same state'); 86 }, 'worker objects for the same entity have the same state');
57 </script> 87 </script>
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/serviceworker/registration-service-worker-attributes.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698