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

Side by Side Diff: LayoutTests/http/tests/serviceworker/state.html

Issue 311573002: Add a test, ServiceWorker statechange target is the installing worker. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 <script src="../resources/testharness.js"></script> 2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script> 3 <script src="../resources/testharnessreport.js"></script>
4 <script src="resources/test-helpers.js"></script> 4 <script src="resources/test-helpers.js"></script>
5 <body> 5 <body>
6 <script> 6 <script>
7 (function () { 7 (function () {
8 var t = async_test('Service Worker state property and "statechange" event'); 8 var t = async_test('Service Worker state property and "statechange" event');
9 var currentState = 'test-is-starting'; 9 var currentState = 'test-is-starting';
10 var scope = '/state/*'; 10 var scope = '/state/*';
11 11
12 service_worker_unregister_and_register( 12 service_worker_unregister_and_register(
13 t, 'resources/worker-no-op.js', scope, onRegister); 13 t, 'resources/worker-no-op.js', scope, onRegister);
14 14
15 function onRegister(sw) { 15 function onRegister(sw) {
16 sw.addEventListener('statechange', t.step_func(onStateChange)); 16 sw.addEventListener('statechange', t.step_func(onStateChange(sw)));
17 assert_in_array(sw.state, ['parsed', 'installing'], 17 assert_in_array(sw.state, ['parsed', 'installing'],
18 'the service worker should be in a state up to ' + 18 'the service worker should be in a state up to ' +
19 '"installing".'); 19 '"installing".');
20 checkStateTransition(sw.state); 20 checkStateTransition(sw.state);
21 } 21 }
22 22
23 function checkStateTransition(newState) { 23 function checkStateTransition(newState) {
24 switch (currentState) { 24 switch (currentState) {
25 case 'test-is-starting': 25 case 'test-is-starting':
26 break; // anything goes 26 break; // anything goes
(...skipping 17 matching lines...) Expand all
44 'the "deactivated" state'); 44 'the "deactivated" state');
45 break; 45 break;
46 default: 46 default:
47 assert_unreached('should not transition into unknown state "' + 47 assert_unreached('should not transition into unknown state "' +
48 newState + '"'); 48 newState + '"');
49 break; 49 break;
50 } 50 }
51 currentState = newState; 51 currentState = newState;
52 } 52 }
53 53
54 function onStateChange(event) { 54 function onStateChange(expectedTarget) {
55 assert_true(event.target instanceof ServiceWorker, 55 return function(event) {
56 'the target of the statechange event should be a ' + 56 assert_true(event.target instanceof ServiceWorker,
57 'ServiceWorker.'); 57 'the target of the statechange event should be a ' +
58 assert_equals(event.type, 'statechange', 58 'ServiceWorker.');
59 'the type of the event should be "statechange".'); 59 assert_equals(event.target, expectedTarget,
60 'the target of the statechange event should be ' +
61 'the installing ServiceWorker');
62 assert_equals(event.type, 'statechange',
63 'the type of the event should be "statechange".');
60 64
61 checkStateTransition(event.target.state); 65 checkStateTransition(event.target.state);
62 66
63 if (event.target.state == 'active') 67 if (event.target.state == 'active')
64 service_worker_unregister_and_done(t, scope); 68 service_worker_unregister_and_done(t, scope);
69 };
65 } 70 }
66 }()); 71 }());
67 </script> 72 </script>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698