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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/synced-state.https.html

Issue 2899343003: Upstream service worker "statechange" tests to WPT (Closed)
Patch Set: Introduce additional assertions from Chromium Created 3 years, 6 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 | « no previous file | third_party/WebKit/LayoutTests/http/tests/serviceworker/state.html » ('j') | 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.sub.js"></script> 5 <script src="resources/test-helpers.sub.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 'use strict';
11
12 function nextChange(worker) {
13 return new Promise(function(resolve, reject) {
14 worker.addEventListener('statechange', function handler(event) {
15 try {
16 worker.removeEventListener('statechange', handler);
17 resolve(event.currentTarget.state);
18 } catch (err) {
19 reject(err);
20 }
21 });
22 });
23 }
24
10 promise_test(function(t) { 25 promise_test(function(t) {
11 var scope = 'resources/synced-state'; 26 var scope = 'resources/synced-state';
12 var script = 'resources/empty-worker.js'; 27 var script = 'resources/empty-worker.js';
28 var registration, worker;
29
13 return service_worker_unregister_and_register(t, script, scope) 30 return service_worker_unregister_and_register(t, script, scope)
14 .then(function(registration) { 31 .then(function(r) {
15 return new Promise(function(resolve) { 32 registration = r;
16 var step = 0; 33 worker = registration.installing;
17 registration.installing.addEventListener('statechange', 34
18 function(e) { 35 t.add_cleanup(function() {
19 step++; 36 r.unregister();
20 if (step == 1) { 37 });
21 assert_equals(e.currentTarget.state, 'installed', 38
22 'original SW should be installed'); 39 return nextChange(worker);
23 assert_equals(registration.installing, null, 40 })
24 'in installed, .installing should be null'); 41 .then(function(state) {
25 // The Activate algorithm may have cleared the waiting worke r 42 assert_equals(state, 'installed',
26 // by now. 43 'original SW should be installed');
27 if (registration.waiting) { 44 assert_equals(registration.installing, null,
28 assert_equals(registration.waiting.state, 'installed', 45 'in installed, .installing should be null');
29 'in installed, .waiting should be installed' ); 46 assert_equals(registration.waiting, worker,
30 assert_equals(registration.active, null, 47 'in installed, .waiting should be equal to the ' +
31 'in installed, .active should be null'); 48 'original worker');
32 } else { 49 assert_equals(registration.waiting.state, 'installed',
33 assert_equals(registration.active.state, 'activating', 50 'in installed, .waiting should be installed');
34 'in installed, .active should be activating' ); 51 assert_equals(registration.active, null,
35 } 52 'in installed, .active should be null');
36 } else if (step == 2) { 53
37 assert_equals(e.currentTarget.state, 'activating', 54 return nextChange(worker);
38 'original SW should be activating'); 55 })
39 assert_equals(registration.installing, null, 56 .then(function(state) {
40 'in activating, .installing should be null'); 57 assert_equals(state, 'activating',
41 assert_equals(registration.waiting, null, 58 'original SW should be activating');
42 'in activating, .waiting should be null'); 59 assert_equals(registration.installing, null,
43 assert_equals( 60 'in activating, .installing should be null');
44 registration.active.state, 'activating', 61 assert_equals(registration.waiting, null,
45 'in activating, .active should be activating'); 62 'in activating, .waiting should be null');
46 } else if (step == 3) { 63 assert_equals(registration.active, worker,
47 assert_equals(e.currentTarget.state, 'activated', 64 'in activating, .active should be equal to the ' +
48 'original SW should be activated'); 65 'original worker');
49 assert_equals(registration.installing, null, 66 assert_equals(
50 'in activated, .installing should be null'); 67 registration.active.state, 'activating',
51 assert_equals(registration.waiting, null, 68 'in activating, .active should be activating');
52 'in activated, .waiting should be null'); 69
53 assert_equals(registration.active.state, 'activated', 70 return nextChange(worker);
54 'in activated .active should be activated'); 71 })
55 resolve(); 72 .then(function(state) {
56 } 73 assert_equals(state, 'activated',
57 }) 74 'original SW should be activated');
58 }) 75 assert_equals(registration.installing, null,
76 'in activated, .installing should be null');
77 assert_equals(registration.waiting, null,
78 'in activated, .waiting should be null');
79 assert_equals(registration.active, worker,
80 'in activated, .active should be equal to the ' +
81 'original worker');
82 assert_equals(registration.active.state, 'activated',
83 'in activated .active should be activated');
59 }) 84 })
60 .then(function() { 85 .then(function() {
61 return service_worker_unregister_and_done(t, scope); 86 return navigator.serviceWorker.getRegistration(scope);
87 })
88 .then(function(r) {
89 assert_equals(r, registration, 'getRegistration should return the ' +
90 'same object');
62 }); 91 });
63 }, 'worker objects for the same entity have the same state'); 92 }, 'worker objects for the same entity have the same state');
64 </script> 93 </script>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/http/tests/serviceworker/state.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698