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

Side by Side Diff: LayoutTests/http/tests/serviceworker/fetch-event.html

Issue 354953002: Promisify Service Worker test unregister_and_register helper function (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: patch for landing 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
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 var worker = 'resources/fetch-event-test-worker.js'; 7 var worker = 'resources/fetch-event-test-worker.js';
8 8
9 (function() { 9 (function() {
10 var t = async_test('Service Worker responds to fetch event with blob body'); 10 var t = async_test('Service Worker responds to fetch event with blob body');
11 var scope = 'helloworld'; 11 var scope = 'helloworld';
12 service_worker_unregister_and_register(t, worker, scope, onRegister); 12 service_worker_unregister_and_register(t, worker, scope).then(t.step_func(on Register));
13 13
14 function onRegister(sw) { 14 function onRegister(sw) {
15 sw.addEventListener('statechange', t.step_func(onStateChange)); 15 sw.addEventListener('statechange', t.step_func(onStateChange));
16 } 16 }
17 17
18 function onStateChange(event) { 18 function onStateChange(event) {
19 if (event.target.state != 'active') 19 if (event.target.state != 'active')
20 return; 20 return;
21 with_iframe(scope, t.step_func(function(frame) { 21 with_iframe(scope, t.step_func(function(frame) {
22 assert_equals(frame.contentDocument.body.textContent, 'hello, world' , 22 assert_equals(frame.contentDocument.body.textContent, 'hello, world' ,
23 'Service Worker should respond to fetch with a fixed-s tring body'); 23 'Service Worker should respond to fetch with a fixed-s tring body');
24 service_worker_unregister_and_done(t, scope); 24 service_worker_unregister_and_done(t, scope);
25 })); 25 }));
26 } 26 }
27 }()); 27 }());
28 28
29 (function() { 29 (function() {
30 var t = async_test('Service Worker does not respond to fetch event'); 30 var t = async_test('Service Worker does not respond to fetch event');
31 var scope = 'resources/simple.html?ignore'; 31 var scope = 'resources/simple.html?ignore';
32 service_worker_unregister_and_register(t, worker, scope, onRegister); 32 service_worker_unregister_and_register(t, worker, scope).then(t.step_func(on Register));
33 33
34 function onRegister(sw) { 34 function onRegister(sw) {
35 sw.addEventListener('statechange', t.step_func(onStateChange)); 35 sw.addEventListener('statechange', t.step_func(onStateChange));
36 } 36 }
37 37
38 function onStateChange(event) { 38 function onStateChange(event) {
39 if (event.target.state != 'active') 39 if (event.target.state != 'active')
40 return; 40 return;
41 with_iframe(scope, t.step_func(function(frame) { 41 with_iframe(scope, t.step_func(function(frame) {
42 assert_equals(frame.contentDocument.body.textContent, 'Here\'s a sim ple html file.\n', 42 assert_equals(frame.contentDocument.body.textContent, 'Here\'s a sim ple html file.\n',
43 'Response should come from fallback to native fetch'); 43 'Response should come from fallback to native fetch');
44 service_worker_unregister_and_done(t, scope); 44 service_worker_unregister_and_done(t, scope);
45 })); 45 }));
46 } 46 }
47 }()); 47 }());
48 48
49 (function() { 49 (function() {
50 var t = async_test('Service Worker responds to fetch event with null respons e body'); 50 var t = async_test('Service Worker responds to fetch event with null respons e body');
51 var scope = 'resources/simple.html?null'; 51 var scope = 'resources/simple.html?null';
52 service_worker_unregister_and_register(t, worker, scope, onRegister); 52 service_worker_unregister_and_register(t, worker, scope).then(t.step_func(on Register));
53 53
54 function onRegister(sw) { 54 function onRegister(sw) {
55 sw.addEventListener('statechange', t.step_func(onStateChange)); 55 sw.addEventListener('statechange', t.step_func(onStateChange));
56 } 56 }
57 57
58 function onStateChange(event) { 58 function onStateChange(event) {
59 if (event.target.state != 'active') 59 if (event.target.state != 'active')
60 return; 60 return;
61 with_iframe(scope, t.step_func(function(frame) { 61 with_iframe(scope, t.step_func(function(frame) {
62 assert_equals(frame.contentDocument.body.textContent, '', 62 assert_equals(frame.contentDocument.body.textContent, '',
63 'Response should be the empty string'); 63 'Response should be the empty string');
64 service_worker_unregister_and_done(t, scope); 64 service_worker_unregister_and_done(t, scope);
65 })); 65 }));
66 } 66 }
67 }()); 67 }());
68 68
69 (function() { 69 (function() {
70 var t = async_test('Service Worker rejects fetch event'); 70 var t = async_test('Service Worker rejects fetch event');
71 var scope = 'resources/simple.html?reject'; 71 var scope = 'resources/simple.html?reject';
72 service_worker_unregister_and_register(t, worker, scope, onRegister); 72 service_worker_unregister_and_register(t, worker, scope).then(t.step_func(on Register));
73 73
74 function onRegister(sw) { 74 function onRegister(sw) {
75 sw.addEventListener('statechange', t.step_func(onStateChange)); 75 sw.addEventListener('statechange', t.step_func(onStateChange));
76 } 76 }
77 77
78 function onStateChange(event) { 78 function onStateChange(event) {
79 if (event.target.state != 'active') 79 if (event.target.state != 'active')
80 return; 80 return;
81 with_iframe(scope, t.step_func(function(frame) { 81 with_iframe(scope, t.step_func(function(frame) {
82 assert_equals(frame.contentDocument.body.textContent, 'Here\'s a sim ple html file.\n', 82 assert_equals(frame.contentDocument.body.textContent, 'Here\'s a sim ple html file.\n',
83 'Response should come from fallback to native fetch'); 83 'Response should come from fallback to native fetch');
84 service_worker_unregister_and_done(t, scope); 84 service_worker_unregister_and_done(t, scope);
85 })); 85 }));
86 } 86 }
87 }()); 87 }());
88 88
89 (function() { 89 (function() {
90 var t = async_test('Service Worker fetches other file in fetch event'); 90 var t = async_test('Service Worker fetches other file in fetch event');
91 var scope = 'resources/simple.html?fetch'; 91 var scope = 'resources/simple.html?fetch';
92 service_worker_unregister_and_register(t, worker, scope, onRegister); 92 service_worker_unregister_and_register(t, worker, scope).then(t.step_func(on Register));
93 93
94 function onRegister(sw) { 94 function onRegister(sw) {
95 sw.addEventListener('statechange', t.step_func(onStateChange)); 95 sw.addEventListener('statechange', t.step_func(onStateChange));
96 } 96 }
97 97
98 function onStateChange(event) { 98 function onStateChange(event) {
99 if (event.target.state != 'active') 99 if (event.target.state != 'active')
100 return; 100 return;
101 with_iframe(scope, t.step_func(function(frame) { 101 with_iframe(scope, t.step_func(function(frame) {
102 assert_equals(frame.contentDocument.body.textContent, 'Here\'s an ot her html file.\n', 102 assert_equals(frame.contentDocument.body.textContent, 'Here\'s an ot her html file.\n',
103 'Response should come from fetched other file'); 103 'Response should come from fetched other file');
104 service_worker_unregister_and_done(t, scope); 104 service_worker_unregister_and_done(t, scope);
105 })); 105 }));
106 } 106 }
107 }()); 107 }());
108 </script> 108 </script>
109 </body> 109 </body>
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/serviceworker/fetch.html ('k') | LayoutTests/http/tests/serviceworker/indexeddb.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698