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

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: Fix indent and add add_completion_callback to reclaim the registration 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 // Tests that ServiceWorker objects representing the same Service Worker 7 // Tests that ServiceWorker objects representing the same Service Worker
8 // entity have the same state. JS object equality is not tested, since the spec 8 // entity have the same state. JS-level equality is now required according to
9 // does not require it. 9 // the spec.
10 promise_test(function(t) { 10 promise_test(function(t) {
11 var scope = 'resources/synced-state'; 11 var scope = 'resources/synced-state';
12 var script = 'resources/empty-worker.js'; 12 var script = 'resources/empty-worker.js';
13 var registration;
13 return service_worker_unregister_and_register(t, script, scope) 14 return service_worker_unregister_and_register(t, script, scope)
14 .then(function(registration) { 15 .then(function(r) {
16 var step = 0;
17 registration = r;
18 add_completion_callback(function() { r.unregister(); });
15 return new Promise(function(resolve) { 19 return new Promise(function(resolve) {
16 var step = 0; 20 r.installing.addEventListener('statechange', function(e) {
17 registration.installing.addEventListener('statechange',
18 function(e) {
19 step++; 21 step++;
20 if (step == 1) { 22 if (step == 1) {
21 assert_equals(e.currentTarget.state, 'installed', 23 assert_equals(e.currentTarget.state, 'installed',
22 'original SW should be installed'); 24 'original SW should be installed');
23 assert_equals(registration.installing, null, 25 assert_equals(r.installing, null,
24 'in installed, .installing should be null'); 26 'in installed, .installing should be null');
25 assert_equals(registration.waiting.state, 'installed', 27 assert_equals(r.waiting.state, 'installed',
26 'in installed, .waiting should be installed'); 28 'in installed, the state of .waiting ' +
27 assert_equals(registration.active, null, 29 'should be installed');
30 assert_equals(r.active, null,
28 'in installed, .active should be null'); 31 'in installed, .active should be null');
32 assert_equals(r.waiting, e.currentTarget,
33 '.waiting should be equal to the original ' +
34 'SW in installed');
29 } else if (step == 2) { 35 } else if (step == 2) {
30 assert_equals(e.currentTarget.state, 'activating', 36 assert_equals(e.currentTarget.state, 'activating',
31 'original SW should be activating'); 37 'original SW should be activating');
32 assert_equals(registration.installing, null, 38 assert_equals(r.installing, null,
33 'in activating, .installing should be null'); 39 'in activating, .installing should be null');
34 assert_equals(registration.waiting, null, 40 assert_equals(r.waiting, null,
35 'in activating, .waiting should be null'); 41 'in activating, .waiting should be null');
36 assert_equals( 42 assert_equals(r.active.state, 'activating',
37 registration.active.state, 'activating', 43 'in activating, the state of .active ' +
38 'in activating, .active should be activating'); 44 'should be activating');
45 assert_equals(r.active, e.currentTarget,
46 '.active should be equal to the original ' +
47 'SW in activating');
39 } else if (step == 3) { 48 } else if (step == 3) {
40 assert_equals(e.currentTarget.state, 'activated', 49 assert_equals(e.currentTarget.state, 'activated',
41 'original SW should be activated'); 50 'original SW should be activated');
42 assert_equals(registration.installing, null, 51 assert_equals(r.installing, null,
43 'in activated, .installing should be null'); 52 'in activated, .installing should be null');
44 assert_equals(registration.waiting, null, 53 assert_equals(r.waiting, null,
45 'in activated, .waiting should be null'); 54 'in activated, .waiting should be null');
46 assert_equals(registration.active.state, 'activated', 55 assert_equals(r.active.state, 'activated',
47 'in activated .active should be activated'); 56 'in activated, the state of .active should ' +
57 'be activated');
58 assert_equals(r.active, e.currentTarget,
59 '.active should be equal to the original ' +
60 'SW in activated');
48 resolve(); 61 resolve();
49 } 62 }
50 }) 63 });
51 }) 64 });
52 }) 65 })
53 .then(function() { 66 .then(function() {
54 return service_worker_unregister_and_done(t, scope); 67 return navigator.serviceWorker.getRegistration(scope);
68 })
69 .then(function(r) {
70 assert_equals(r, registration, 'getRegistration should return the ' +
71 'same object with the registered one');
55 }); 72 });
56 }, 'worker objects for the same entity have the same state'); 73 }, 'worker objects for the same entity have the same state');
57 </script> 74 </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