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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/service-workers/service-worker/fetch-frame-resource.https.html

Issue 2415873002: Import w3c tests for the service workers (Closed)
Patch Set: Rebase Created 4 years, 2 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
(Empty)
1 <!DOCTYPE html>
2 <title>Service Worker: Fetch for the frame loading.</title>
3 <meta name=timeout content=long>
4 <script src="/resources/testharness.js"></script>
5 <script src="/resources/testharnessreport.js"></script>
6 <script src="resources/get-host-info.sub.js"></script>
7 <script src="resources/test-helpers.sub.js"></script>
8 <body>
9 <script>
10 var worker = 'resources/fetch-rewrite-worker.js';
11 var path = base_path() + 'resources/fetch-access-control.py';
12 var host_info = get_host_info();
13
14 if (window.testRunner) {
15 testRunner.setCanOpenWindows();
16 }
17
18 function getLoadedObject(win, contentFunc, closeFunc) {
19 return new Promise(function(resolve) {
20 function done(contentString) {
21 var result = null;
22 // fetch-access-control.py returns a string like "report( <json> )".
23 // Eval the returned string with a report functionto get the json
24 // object.
25 try {
26 function report(obj) { result = obj };
27 eval(contentString);
28 } catch(e) {
29 // just resolve null if we get unexpected page content
30 }
31 closeFunc(win);
32 resolve(result);
33 }
34
35 // We can't catch the network error on window. So we use the timer.
36 var timeout = setTimeout(function() {
37 // Failure pages are considered cross-origin in some browsers. This
38 // means you cannot even .resolve() the window because the check for
39 // the .then property will throw. Instead, treat cross-origin
40 // failure pages as the empty string which will fail to parse as the
41 // expected json result.
42 var content = '';
43 try {
44 content = contentFunc(win);
45 } catch(e) {
46 // use default empty string for cross-domain window
47 }
48 done(content);
49 }, 10000);
50
51 win.onload = function() {
52 clearTimeout(timeout);
53 var content = contentFunc(win);
54 done(content);
55 };
56 });
57 }
58
59 function getLoadedFrameAsObject(frame) {
60 return getLoadedObject(frame, function(f) {
61 return f.contentDocument.body.textContent;
62 }, function(f) {
63 f.parentNode.removeChild(f);
64 });
65 }
66
67 function getLoadedWindowAsObject(win) {
68 return getLoadedObject(win, function(w) {
69 return w.document.body.textContent
70 }, function(w) {
71 w.close();
72 });
73 }
74
75 async_test(function(t) {
76 var scope = 'resources/fetch-frame-resource/frame-basic';
77 var frame;
78 service_worker_unregister_and_register(t, worker, scope)
79 .then(function(reg) {
80 return wait_for_state(t, reg.installing, 'activated');
81 })
82 .then(function() {
83 frame = document.createElement('iframe');
84 frame.src =
85 scope + '?url=' +
86 encodeURIComponent(host_info['HTTPS_ORIGIN'] + path);
87 document.body.appendChild(frame);
88 return getLoadedFrameAsObject(frame);
89 })
90 .then(function(result) {
91 assert_equals(
92 result.jsonpResult,
93 'success',
94 'Basic type response could be loaded in the iframe.');
95 frame.remove();
96 return service_worker_unregister_and_done(t, scope);
97 })
98 .catch(unreached_rejection(t));
99 }, 'Basic type response could be loaded in the iframe.');
100
101 async_test(function(t) {
102 var scope = 'resources/fetch-frame-resource/frame-cors';
103 var frame;
104 service_worker_unregister_and_register(t, worker, scope)
105 .then(function(reg) {
106 return wait_for_state(t, reg.installing, 'activated');
107 })
108 .then(function() {
109 frame = document.createElement('iframe');
110 frame.src =
111 scope + '?mode=cors&url=' +
112 encodeURIComponent(host_info['HTTPS_REMOTE_ORIGIN'] + path +
113 '?ACAOrigin=' + host_info['HTTPS_ORIGIN']);
114 document.body.appendChild(frame);
115 return getLoadedFrameAsObject(frame);
116 })
117 .then(function(result) {
118 assert_equals(
119 result.jsonpResult,
120 'success',
121 'CORS type response could be loaded in the iframe.');
122 frame.remove();
123 return service_worker_unregister_and_done(t, scope);
124 })
125 .catch(unreached_rejection(t));
126 }, 'CORS type response could be loaded in the iframe.');
127
128 async_test(function(t) {
129 var scope = 'resources/fetch-frame-resource/frame-opaque';
130 var frame;
131 service_worker_unregister_and_register(t, worker, scope)
132 .then(function(reg) {
133 return wait_for_state(t, reg.installing, 'activated');
134 })
135 .then(function() {
136 frame = document.createElement('iframe');
137 frame.src =
138 scope + '?mode=no-cors&url=' +
139 encodeURIComponent(host_info['HTTPS_REMOTE_ORIGIN'] + path);
140 document.body.appendChild(frame);
141 return getLoadedFrameAsObject(frame);
142 })
143 .then(function(result) {
144 assert_equals(
145 result,
146 null,
147 'Opaque type response could not be loaded in the iframe.');
148 frame.remove();
149 return service_worker_unregister_and_done(t, scope);
150 })
151 .catch(unreached_rejection(t));
152 }, 'Opaque type response could not be loaded in the iframe.');
153
154 async_test(function(t) {
155 var scope = 'resources/fetch-frame-resource/window-basic';
156 service_worker_unregister_and_register(t, worker, scope)
157 .then(function(reg) {
158 return wait_for_state(t, reg.installing, 'activated');
159 })
160 .then(function() {
161 var win = window.open(
162 scope + '?url=' +
163 encodeURIComponent(host_info['HTTPS_ORIGIN'] + path));
164 return getLoadedWindowAsObject(win);
165 })
166 .then(function(result) {
167 assert_equals(
168 result.jsonpResult,
169 'success',
170 'Basic type response could be loaded in the new window.');
171 return service_worker_unregister_and_done(t, scope);
172 })
173 .catch(unreached_rejection(t));
174 }, 'Basic type response could be loaded in the new window.');
175
176 async_test(function(t) {
177 var scope = 'resources/fetch-frame-resource/window-cors';
178 service_worker_unregister_and_register(t, worker, scope)
179 .then(function(reg) {
180 return wait_for_state(t, reg.installing, 'activated');
181 })
182 .then(function() {
183 var win = window.open(
184 scope + '?mode=cors&url=' +
185 encodeURIComponent(host_info['HTTPS_REMOTE_ORIGIN'] + path +
186 '?ACAOrigin=' + host_info['HTTPS_ORIGIN']));
187 return getLoadedWindowAsObject(win);
188 })
189 .then(function(result) {
190 assert_equals(
191 result.jsonpResult,
192 'success',
193 'CORS type response could be loaded in the new window.');
194 return service_worker_unregister_and_done(t, scope);
195 })
196 .catch(unreached_rejection(t));
197 }, 'CORS type response could be loaded in the new window.');
198
199 async_test(function(t) {
200 var scope = 'resources/fetch-frame-resource/window-opaque';
201 service_worker_unregister_and_register(t, worker, scope)
202 .then(function(reg) {
203 return wait_for_state(t, reg.installing, 'activated');
204 })
205 .then(function() {
206 var win = window.open(
207 scope + '?mode=no-cors&url=' +
208 encodeURIComponent(host_info['HTTPS_REMOTE_ORIGIN'] + path));
209 return getLoadedWindowAsObject(win);
210 })
211 .then(function(result) {
212 assert_equals(
213 result,
214 null,
215 'Opaque type response could not be loaded in the new window.');
216 return service_worker_unregister_and_done(t, scope);
217 })
218 .catch(unreached_rejection(t));
219 }, 'Opaque type response could not be loaded in the new window.');
220 </script>
221 </body>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698