OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <script src="../resources/testharness.js"></script> | |
3 <script src="../resources/testharnessreport.js"></script> | |
4 <script src="resources/test-helpers.js"></script> | |
5 <body> | |
6 <script> | |
7 // FIXME: When request.url is implemented (crbug.com/377373), move all these | |
8 // tests into a single Service Worker. The Service Worker can respond | |
9 // differently depending on the request URL, allowing for different test cases. | |
10 (function () { | |
11 var t = async_test('Service Worker responds to fetch event with blob body'); | |
12 var scope = '/helloworld/*'; | |
13 | |
14 service_worker_unregister_and_register( | |
15 t, 'resources/hello-world-worker.js', scope, onRegister); | |
16 | |
17 function onRegister(sw) { | |
18 sw.addEventListener('statechange', t.step_func(onStateChange)); | |
19 } | |
20 | |
21 function onStateChange(event) { | |
22 if (event.target.state != 'active') | |
23 return; | |
24 with_iframe('/helloworld/hello', t.step_func(function(frame) { | |
25 assert_equals(frame.contentDocument.body.textContent, 'hello, world' , | |
26 'Service Worker should respond to fetch with a fixed-s tring body'); | |
27 service_worker_unregister_and_done(t, scope); | |
28 })); | |
29 } | |
30 }()); | |
31 | |
32 (function () { | |
33 function fallback_to_network_test(t, worker) { | |
34 return new Promise(function(resolve, reject) { | |
35 var scope = 'resources/simple.html'; | |
36 t.step(doTest); | |
37 | |
38 function doTest() { | |
39 service_worker_unregister_and_register( | |
40 t, worker, scope, onRegister); | |
41 } | |
42 | |
43 function onRegister(sw) { | |
44 sw.addEventListener('statechange', t.step_func(onStateChange)); | |
45 } | |
46 | |
47 function onStateChange(event) { | |
48 if (event.target.state != 'active') | |
49 return; | |
50 with_iframe(scope, t.step_func(function(frame) { | |
51 assert_equals(frame.contentDocument.body.textContent, "Here' s a simple html file.\n", | |
52 'Response should come from fallback to native fetch'); | |
53 navigator.serviceWorker.unregister(scope).then( | |
54 t.step_func(onUnregister), | |
55 unreached_rejection(t, 'Unregister should not fail') | |
56 ); | |
57 })); | |
58 } | |
59 | |
60 function onUnregister() { | |
61 t.done(); | |
62 resolve(); | |
63 } | |
64 }); | |
65 } | |
66 | |
67 var tests = [{ name: 'Service Worker does not respond to fetch event', worke r: 'resources/empty-worker.js' }, | |
68 { name: 'Service Worker rejects fetch event', worker: 'resource s/reject-fetch-event-worker.js' }]; | |
69 var sequence = Promise.resolve(); | |
70 tests.forEach(function(test) { | |
71 sequence = sequence.then(fallback_to_network_test(async_test(test.name), test.worker)); | |
72 }); | |
73 }()); | |
74 | |
75 (function () { | |
76 var t = async_test('Service Worker responds to fetch event with null respons e body'); | |
77 // Use an actual file (test-helpers.js) to show we're not just defaulting to empty string on | |
78 // a non-existent file. simple.html would be better but this test runs concu rrently with | |
jsbell
2014/06/03 17:51:26
Would 'resources/simple.html?null' work? I'm not 1
| |
79 // other tests that use simple.html, and it'd be a race over which SW is use d. | |
80 // (This is moot when the tests are migrated to a single SW). | |
81 var scope = 'resources/test-helpers.js'; | |
82 | |
83 service_worker_unregister_and_register( | |
84 t, 'resources/null-response-body-worker.js', scope, onRegister); | |
85 | |
86 function onRegister(sw) { | |
87 sw.addEventListener('statechange', t.step_func(onStateChange)); | |
88 } | |
89 | |
90 function onStateChange(event) { | |
91 if (event.target.state != 'active') | |
92 return; | |
93 with_iframe(scope, t.step_func(function(frame) { | |
94 assert_equals(frame.contentDocument.body.textContent, "", | |
95 'Response should be the empty string'); | |
96 service_worker_unregister_and_done(t, scope); | |
97 })); | |
98 } | |
99 }()); | |
100 </script> | |
101 </body> | |
OLD | NEW |