2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script>
4 <script src="resources/test-helpers.js"></script>
7 // Temporary measure to diagnose timeouts on Win XP. Let the W3C harness
8 // timeout before run-webkit-tests does, so it can report the particular
9 // test that timed out.
10 // FIXME: Remove after the cause of timeout is fixed.
11 var properties = {timeout: 5500};
13 var worker = 'resources/fetch-event-test-worker.js';
15 async_test(function(t) {
16 var scope = 'resources/simple.html?string';
17 service_worker_unregister_and_register(t, worker, scope)
18 .then(function(reg) { return wait_for_activated(t, reg); })
19 .then(function() { return with_iframe(scope); })
20 .then(function(frame) {
22 frame.contentDocument.body.textContent,
24 'Service Worker should respond to fetch with a test string');
26 frame.contentDocument.contentType,
28 'The content type of the response created with a string should be text/plain');
30 frame.contentDocument.characterSet,
32 'The character set of the response created with a string should be UTF-8');
34 return service_worker_unregister_and_done(t, scope);
36 .catch(unreached_rejection(t));
37 }, 'Service Worker responds to fetch event with string', properties);
39 async_test(function(t) {
40 var scope = 'resources/simple.html?blob';
41 service_worker_unregister_and_register(t, worker, scope)
42 .then(function(reg) { return wait_for_activated(t, reg); })
43 .then(function() { return with_iframe(scope); })
44 .then(function(frame) {
46 frame.contentDocument.body.textContent,
48 'Service Worker should respond to fetch with a test string');
50 return service_worker_unregister_and_done(t, scope);
52 .catch(unreached_rejection(t));
53 }, 'Service Worker responds to fetch event with blob body', properties);
55 async_test(function(t) {
56 var scope = 'resources/simple.html?referrer';
57 service_worker_unregister_and_register(t, worker, scope)
58 .then(function(reg) { return wait_for_activated(t, reg); })
59 .then(function() { return with_iframe(scope); })
60 .then(function(frame) {
62 frame.contentDocument.body.textContent,
63 'Referrer: ' + document.location.href,
64 'Service Worker should respond to fetch with the referrer URL');
66 return service_worker_unregister_and_done(t, scope);
68 .catch(unreached_rejection(t));
69 }, 'Service Worker responds to fetch event with the referrer URL', properties);
71 async_test(function(t) {
72 var scope = 'resources/simple.html?ignore';
73 service_worker_unregister_and_register(t, worker, scope)
74 .then(function(reg) { return wait_for_activated(t, reg); })
75 .then(function() { return with_iframe(scope); })
76 .then(function(frame) {
77 assert_equals(frame.contentDocument.body.textContent,
78 'Here\'s a simple html file.\n',
79 'Response should come from fallback to native fetch');
81 return service_worker_unregister_and_done(t, scope);
83 .catch(unreached_rejection(t));
84 }, 'Service Worker does not respond to fetch event', properties);
86 async_test(function(t) {
87 var scope = 'resources/simple.html?null';
88 service_worker_unregister_and_register(t, worker, scope)
89 .then(function(reg) { return wait_for_activated(t, reg); })
90 .then(function() { return with_iframe(scope); })
91 .then(function(frame) {
92 assert_equals(frame.contentDocument.body.textContent,
94 'Response should be the empty string');
96 return service_worker_unregister_and_done(t, scope);
98 .catch(unreached_rejection(t));
99 }, 'Service Worker responds to fetch event with null response body', properties);
101 async_test(function(t) {
102 var scope = 'resources/simple.html?fetch';
103 service_worker_unregister_and_register(t, worker, scope)
104 .then(function(reg) { return wait_for_activated(t, reg); })
105 .then(function() { return with_iframe(scope); })
106 .then(function(frame) {
107 assert_equals(frame.contentDocument.body.textContent,
108 'Here\'s an other html file.\n',
109 'Response should come from fetched other file');
110 unload_iframe(frame);
111 return service_worker_unregister_and_done(t, scope);
113 .catch(unreached_rejection(t));
114 }, 'Service Worker fetches other file in fetch event', properties);
116 async_test(function(t) {
117 var scope = 'resources/simple.html?form-post';
118 var frame_name = 'xhr-post-frame';
119 service_worker_unregister_and_register(t, worker, scope)
120 .then(function(reg) { return wait_for_activated(t, reg); })
122 return new Promise(function(resolve) {
123 var frame = document.createElement('iframe');
124 frame.name = frame_name;
125 document.body.appendChild(frame);
126 var form = document.createElement('form');
127 form.target = frame_name;
129 form.method = 'post';
130 var input1 = document.createElement('input');
131 input1.type = 'text';
132 input1.value = 'testValue1';
133 input1.name = 'testName1'
134 form.appendChild(input1);
135 var input2 = document.createElement('input');
136 input2.type = 'text';
137 input2.value = 'testValue2';
138 input2.name = 'testName2'
139 form.appendChild(input2);
140 document.body.appendChild(form);
141 frame.onload = function() {
142 document.body.removeChild(form);
148 .then(function(frame) {
149 assert_equals(frame.contentDocument.body.textContent,
150 'POST:testName1=testValue1&testName2=testValue2');
151 document.body.removeChild(frame);
152 return service_worker_unregister_and_done(t, scope);
154 .catch(unreached_rejection(t));
155 }, 'Service Worker responds to fetch event with POST form', properties);
157 async_test(function(t) {
158 var scope = 'resources/simple.html?multiple-respond-with';
159 service_worker_unregister_and_register(t, worker, scope)
160 .then(function(reg) { return wait_for_activated(t, reg); })
161 .then(function() { return with_iframe(scope); })
162 .then(function(frame) {
164 frame.contentDocument.body.textContent,
166 'Response should be the argument of the first respondWith() call.');
167 unload_iframe(frame);
168 return with_iframe(scope);
170 .then(function(frame) {
172 frame.contentDocument.body.textContent,
173 '(0)(1)[InvalidStateError](2)[InvalidStateError](0)',
174 'Multiple calls of respondWith must throw InvalidStateErrors.');
175 unload_iframe(frame);
176 return service_worker_unregister_and_done(t, scope);
178 .catch(unreached_rejection(t));
179 }, 'Multiple calls of respondWith must throw InvalidStateErrors', properties);