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

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

Issue 468753003: SW tests update (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 467133002 and fix test Created 6 years, 4 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
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 async_test(function(t) {
10 var t = async_test('Service Worker responds to fetch event with string');
11 var scope = 'resources/simple.html?string'; 10 var scope = 'resources/simple.html?string';
12 service_worker_unregister_and_register(t, worker, scope) 11 service_worker_unregister_and_register(t, worker, scope)
12 .then(function(registration) {
13 return wait_for_update(t, registration);
14 })
13 .then(t.step_func(function(sw) { 15 .then(t.step_func(function(sw) {
14 return wait_for_state(t, sw, 'activated'); 16 return wait_for_state(t, sw, 'activated');
15 })) 17 }))
16 .then(t.step_func(function() { return with_iframe(scope); })) 18 .then(t.step_func(function() { return with_iframe(scope); }))
17 .then(t.step_func(function(frame) { 19 .then(t.step_func(function(frame) {
18 assert_equals( 20 assert_equals(
19 frame.contentDocument.body.textContent, 21 frame.contentDocument.body.textContent,
20 'Test string', 22 'Test string',
21 'Service Worker should respond to fetch with a test string'); 23 'Service Worker should respond to fetch with a test string');
22 assert_equals( 24 assert_equals(
23 frame.contentDocument.contentType, 25 frame.contentDocument.contentType,
24 'text/plain', 26 'text/plain',
25 'The content type of the response created with a string should be text/plain'); 27 'The content type of the response created with a string should be te xt/plain');
26 assert_equals( 28 assert_equals(
27 frame.contentDocument.characterSet, 29 frame.contentDocument.characterSet,
28 'UTF-8', 30 'UTF-8',
29 'The character set of the response created with a string should be UTF-8'); 31 'The character set of the response created with a string should be U TF-8');
30 return service_worker_unregister_and_done(t, scope); 32 return service_worker_unregister_and_done(t, scope);
31 })) 33 }))
32 .catch(unreached_rejection(t)); 34 .catch(unreached_rejection(t));
33 }()); 35 }, 'Service Worker responds to fetch event with string');
34 36
35 (function() { 37 async_test(function(t) {
36 var t = async_test('Service Worker responds to fetch event with blob body');
37 var scope = 'resources/simple.html?blob'; 38 var scope = 'resources/simple.html?blob';
38 service_worker_unregister_and_register(t, worker, scope) 39 service_worker_unregister_and_register(t, worker, scope)
40 .then(function(registration) {
41 return wait_for_update(t, registration);
42 })
39 .then(t.step_func(function(sw) { 43 .then(t.step_func(function(sw) {
40 return wait_for_state(t, sw, 'activated'); 44 return wait_for_state(t, sw, 'activated');
41 })) 45 }))
42 .then(t.step_func(function() { return with_iframe(scope); })) 46 .then(t.step_func(function() { return with_iframe(scope); }))
43 .then(t.step_func(function(frame) { 47 .then(t.step_func(function(frame) {
44 assert_equals( 48 assert_equals(
45 frame.contentDocument.body.textContent, 49 frame.contentDocument.body.textContent,
46 'Test blob', 50 'Test blob',
47 'Service Worker should respond to fetch with a test string'); 51 'Service Worker should respond to fetch with a test string');
48 return service_worker_unregister_and_done(t, scope); 52 return service_worker_unregister_and_done(t, scope);
49 })) 53 }))
50 .catch(unreached_rejection(t)); 54 .catch(unreached_rejection(t));
51 }()); 55 }, 'Service Worker responds to fetch event with blob body');
52 56
53 (function() { 57 async_test(function(t) {
54 var t = async_test('Service Worker responds to fetch event with the referrer URL');
55 var scope = 'resources/simple.html?referrer'; 58 var scope = 'resources/simple.html?referrer';
56 service_worker_unregister_and_register(t, worker, scope) 59 service_worker_unregister_and_register(t, worker, scope)
60 .then(function(registration) {
61 return wait_for_update(t, registration);
62 })
57 .then(t.step_func(function(sw) { 63 .then(t.step_func(function(sw) {
58 return wait_for_state(t, sw, 'activated'); 64 return wait_for_state(t, sw, 'activated');
59 })) 65 }))
60 .then(t.step_func(function() { return with_iframe(scope); })) 66 .then(t.step_func(function() { return with_iframe(scope); }))
61 .then(t.step_func(function(frame) { 67 .then(t.step_func(function(frame) {
62 assert_equals( 68 assert_equals(
63 frame.contentDocument.body.textContent, 69 frame.contentDocument.body.textContent,
64 'Referrer: ' + document.location.href, 70 'Referrer: ' + document.location.href,
65 'Service Worker should respond to fetch with the referrer URL'); 71 'Service Worker should respond to fetch with the referrer URL');
66 return service_worker_unregister_and_done(t, scope); 72 return service_worker_unregister_and_done(t, scope);
67 })) 73 }))
68 .catch(unreached_rejection(t)); 74 .catch(unreached_rejection(t));
69 }()); 75 }, 'Service Worker responds to fetch event with the referrer URL');
70 76
71 (function() { 77 async_test(function(t) {
72 var t = async_test('Service Worker does not respond to fetch event');
73 var scope = 'resources/simple.html?ignore'; 78 var scope = 'resources/simple.html?ignore';
74 service_worker_unregister_and_register(t, worker, scope) 79 service_worker_unregister_and_register(t, worker, scope)
80 .then(function(registration) {
81 return wait_for_update(t, registration);
82 })
75 .then(t.step_func(function(sw) { 83 .then(t.step_func(function(sw) {
76 return wait_for_state(t, sw, 'activated'); 84 return wait_for_state(t, sw, 'activated');
77 })) 85 }))
78 .then(t.step_func(function() { return with_iframe(scope); })) 86 .then(t.step_func(function() { return with_iframe(scope); }))
79 .then(t.step_func(function(frame) { 87 .then(t.step_func(function(frame) {
80 assert_equals(frame.contentDocument.body.textContent, 88 assert_equals(frame.contentDocument.body.textContent,
81 'Here\'s a simple html file.\n', 89 'Here\'s a simple html file.\n',
82 'Response should come from fallback to native fetch'); 90 'Response should come from fallback to native fetch');
83 return service_worker_unregister_and_done(t, scope); 91 return service_worker_unregister_and_done(t, scope);
84 })) 92 }))
85 .catch(unreached_rejection(t)); 93 .catch(unreached_rejection(t));
86 }()); 94 }, 'Service Worker does not respond to fetch event');
87 95
88 (function() { 96 async_test(function(t) {
89 var t = async_test(
90 'Service Worker responds to fetch event with null response body');
91 var scope = 'resources/simple.html?null'; 97 var scope = 'resources/simple.html?null';
92 service_worker_unregister_and_register(t, worker, scope) 98 service_worker_unregister_and_register(t, worker, scope)
99 .then(function(registration) {
100 return wait_for_update(t, registration);
101 })
93 .then(t.step_func(function(sw) { 102 .then(t.step_func(function(sw) {
94 return wait_for_state(t, sw, 'activated'); 103 return wait_for_state(t, sw, 'activated');
95 })) 104 }))
96 .then(t.step_func(function() { return with_iframe(scope); })) 105 .then(t.step_func(function() { return with_iframe(scope); }))
97 .then(t.step_func(function(frame) { 106 .then(t.step_func(function(frame) {
98 assert_equals(frame.contentDocument.body.textContent, 107 assert_equals(frame.contentDocument.body.textContent,
99 '', 108 '',
100 'Response should be the empty string'); 109 'Response should be the empty string');
101 return service_worker_unregister_and_done(t, scope); 110 return service_worker_unregister_and_done(t, scope);
102 })) 111 }))
103 .catch(unreached_rejection(t)); 112 .catch(unreached_rejection(t));
104 }()); 113 }, 'Service Worker responds to fetch event with null response body');
105 114
106 (function() { 115 async_test(function(t) {
107 var t = async_test('Service Worker rejects fetch event');
108 var scope = 'resources/simple.html?reject'; 116 var scope = 'resources/simple.html?reject';
109 service_worker_unregister_and_register(t, worker, scope) 117 service_worker_unregister_and_register(t, worker, scope)
118 .then(function(registration) {
119 return wait_for_update(t, registration);
120 })
110 .then(t.step_func(function(sw) { 121 .then(t.step_func(function(sw) {
111 return wait_for_state(t, sw, 'activated'); 122 return wait_for_state(t, sw, 'activated');
112 })) 123 }))
113 .then(t.step_func(function() { return with_iframe(scope); })) 124 .then(t.step_func(function() { return with_iframe(scope); }))
114 .then(t.step_func(function(frame) { 125 .then(t.step_func(function(frame) {
115 assert_equals(frame.contentDocument.body.textContent, 126 assert_equals(frame.contentDocument.body.textContent,
116 'Here\'s a simple html file.\n', 127 'Here\'s a simple html file.\n',
117 'Response should come from fallback to native fetch'); 128 'Response should come from fallback to native fetch');
118 return service_worker_unregister_and_done(t, scope); 129 return service_worker_unregister_and_done(t, scope);
119 })) 130 }))
120 .catch(unreached_rejection(t)); 131 .catch(unreached_rejection(t));
121 }()); 132 }, 'Service Worker rejects fetch event');
122 133
123 (function() { 134 async_test(function(t) {
124 var t = async_test('Service Worker fetches other file in fetch event');
125 var scope = 'resources/simple.html?fetch'; 135 var scope = 'resources/simple.html?fetch';
126 service_worker_unregister_and_register(t, worker, scope) 136 service_worker_unregister_and_register(t, worker, scope)
137 .then(function(registration) {
138 return wait_for_update(t, registration);
139 })
127 .then(t.step_func(function(sw) { 140 .then(t.step_func(function(sw) {
128 return wait_for_state(t, sw, 'activated'); 141 return wait_for_state(t, sw, 'activated');
129 })) 142 }))
130 .then(t.step_func(function() { return with_iframe(scope); })) 143 .then(t.step_func(function() { return with_iframe(scope); }))
131 .then(t.step_func(function(frame) { 144 .then(t.step_func(function(frame) {
132 assert_equals(frame.contentDocument.body.textContent, 145 assert_equals(frame.contentDocument.body.textContent,
133 'Here\'s an other html file.\n', 146 'Here\'s an other html file.\n',
134 'Response should come from fetched other file'); 147 'Response should come from fetched other file');
135 return service_worker_unregister_and_done(t, scope); 148 return service_worker_unregister_and_done(t, scope);
136 })) 149 }))
137 .catch(unreached_rejection(t)); 150 .catch(unreached_rejection(t));
138 }()); 151 }, 'Service Worker fetches other file in fetch event');
139 </script> 152 </script>
140 </body> 153 </body>
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/serviceworker/fetch-csp.html ('k') | LayoutTests/http/tests/serviceworker/indexeddb.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698