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

Side by Side Diff: LayoutTests/http/tests/serviceworker/resources/fetch-canvas-tainting-iframe.html

Issue 600393004: [ServiceWorker] Set FetchRequestMode and handle wasFetchedViaServiceWorker. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: delete fetch-cors-xhr-expected.txt Created 6 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
1 <script src="test-helpers.js?pipe=sub"></script> 1 <script src="test-helpers.js?pipe=sub"></script>
2 <script> 2 <script>
3 var image_path = base_path() + 'fetch-access-control.php?PNGIMAGE'; 3 var image_path = base_path() + 'fetch-access-control.php?PNGIMAGE';
4 var host_info = get_host_info(); 4 var host_info = get_host_info();
5 5
6 var NOT_TAINTED = 'NOT_TAINTED';
7 var TAINTED = 'TAINTED';
8 var LOAD_ERROR = 'LOAD_ERROR';
9
6 function create_test_case_promise(url, cross_origin) { 10 function create_test_case_promise(url, cross_origin) {
7 return new Promise(function(resolve, reject) { 11 return new Promise(function(resolve) {
8 var img = new Image(); 12 var img = new Image();
9 if (cross_origin) { 13 if (cross_origin != '') {
10 img.crossOrigin = 'anonymous'; 14 img.crossOrigin = cross_origin;
11 } 15 }
12 img.onload = function() { 16 img.onload = function() {
13 try { 17 try {
14 var canvas = document.createElement('canvas'); 18 var canvas = document.createElement('canvas');
15 canvas.width = 100; 19 canvas.width = 100;
16 canvas.height = 100; 20 canvas.height = 100;
17 var context = canvas.getContext('2d'); 21 var context = canvas.getContext('2d');
18 context.drawImage(img, 0, 0); 22 context.drawImage(img, 0, 0);
19 context.getImageData(0, 0, 100, 100); 23 context.getImageData(0, 0, 100, 100);
20 resolve(); 24 resolve(NOT_TAINTED);
21 } catch (e) { 25 } catch (e) {
22 reject(); 26 resolve(TAINTED);
23 } 27 }
24 }; 28 };
29 img.onerror = function() {
30 resolve(LOAD_ERROR);
31 }
25 img.src = url; 32 img.src = url;
26 }); 33 });
27 } 34 }
28 35
29 function create_success_test_promise(url, cross_origin) { 36 function create_test_promise(url, cross_origin, expected_result) {
30 return new Promise(function(resolve, reject) { 37 return new Promise(function(resolve, reject) {
31 create_test_case_promise(url, cross_origin) 38 create_test_case_promise(url, cross_origin)
32 .then(function() { resolve(); }) 39 .then(function(result) {
33 .catch(function() { 40 if (result == expected_result) {
34 reject('Image of ' + url + ' must not taint the canvas.'); 41 resolve();
35 }); 42 } else {
43 reject('Result of url:' + url + ' ' +
44 ' cross_origin: ' + cross_origin + ' must be ' +
45 expected_result + ' but ' + result);
46 }
47 })
36 }); 48 });
37 } 49 }
38 50
39 function create_failure_test_promise(url, cross_origin) {
40 return new Promise(function(resolve, reject) {
41 create_test_case_promise(url, cross_origin)
42 .then(function() {
43 reject('Image of ' + url + ' must taint the canvas.');
44 })
45 .catch(function() { resolve(); });
46 });
47 }
48
49 window.addEventListener('message', function(evt) { 51 window.addEventListener('message', function(evt) {
50 var port = evt.ports[0]; 52 var port = evt.ports[0];
51 create_success_test_promise(host_info['HTTP_ORIGIN'] + image_path, false) 53 var image_url = host_info['HTTP_ORIGIN'] + image_path;
52 .then(function() { 54 var remote_image_url = host_info['HTTP_REMOTE_ORIGIN'] + image_path;
53 return create_failure_test_promise( 55 Promise.all([
54 host_info['HTTP_REMOTE_ORIGIN'] + image_path, 56 // Reject tests
55 false); 57 create_test_promise(image_url + '&reject', '', LOAD_ERROR),
56 }) 58 create_test_promise(image_url + '&reject', 'anonymous', LOAD_ERROR),
57 .then(function() { 59 create_test_promise(
58 return create_success_test_promise( 60 image_url + '&reject', 'use-credentials', LOAD_ERROR),
59 './dummy?url=' + 61 // Fallback tests
60 encodeURIComponent(host_info['HTTP_ORIGIN'] + image_path), 62 create_test_promise(
61 false); 63 image_url + '&ignore',
62 }) 64 '',
63 .then(function() { 65 NOT_TAINTED),
64 return create_failure_test_promise( 66 create_test_promise(
65 './dummy?mode=no-cors&url=' + 67 remote_image_url + '&ignore',
66 encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + image_path), 68 '',
67 false); 69 TAINTED),
68 }) 70 create_test_promise(
69 .then(function() { 71 remote_image_url + '&ignore',
70 return create_success_test_promise( 72 'anonymous',
71 './dummy?mode=no-cors&url=' + 73 LOAD_ERROR),
72 encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + image_path + 74 create_test_promise(
73 '&ACAOrigin=' + host_info['HTTP_ORIGIN']), 75 remote_image_url + '&ACAOrigin=' + host_info['HTTP_ORIGIN'] +
74 true); 76 '&ignore',
75 }) 77 'anonymous',
78 NOT_TAINTED),
79 create_test_promise(
80 remote_image_url + '&ignore',
81 'use-credentials',
82 LOAD_ERROR),
83 create_test_promise(
84 remote_image_url + '&ACAOrigin=' + host_info['HTTP_ORIGIN'] +
85 '&ignore',
86 'use-credentials',
87 LOAD_ERROR),
88 create_test_promise(
89 remote_image_url + '&ACAOrigin=' + host_info['HTTP_ORIGIN'] +
90 '&ACACredentials=true&ignore',
91 'use-credentials',
92 NOT_TAINTED),
93
94 // Credential test (fallback)
95 create_test_promise(
96 image_url + '&Auth&ignore',
97 '',
98 NOT_TAINTED),
99 create_test_promise(
100 remote_image_url + '&Auth&ignore',
101 '',
102 TAINTED),
103 create_test_promise(
104 remote_image_url + '&Auth&ignore',
105 'anonymous',
106 LOAD_ERROR),
107 create_test_promise(
108 remote_image_url + '&Auth&ignore',
109 'use-credentials',
110 LOAD_ERROR),
111 create_test_promise(
112 remote_image_url + '&Auth&ACAOrigin=' + host_info['HTTP_ORIGIN'] +
113 '&ignore',
114 'use-credentials',
115 LOAD_ERROR),
116 create_test_promise(
117 remote_image_url + '&Auth&ACAOrigin=' + host_info['HTTP_ORIGIN'] +
118 '&ACACredentials=true&ignore',
119 'use-credentials',
120 NOT_TAINTED),
121
122 // Basic response
123 create_test_promise(
124 image_url +
125 '&mode=same-origin&url=' + encodeURIComponent(image_url),
126 '',
127 NOT_TAINTED),
128 create_test_promise(
129 image_url +
130 '&mode=same-origin&url=' + encodeURIComponent(image_url),
131 'anonymous',
132 NOT_TAINTED),
133 create_test_promise(
134 image_url +
135 '&mode=same-origin&url=' + encodeURIComponent(image_url),
136 'use-credentials',
137 NOT_TAINTED),
138 create_test_promise(
139 remote_image_url +
140 '&mode=same-origin&url=' + encodeURIComponent(image_url),
141 '',
142 NOT_TAINTED),
143 create_test_promise(
144 remote_image_url +
145 '&mode=same-origin&url=' + encodeURIComponent(image_url),
146 'anonymous',
147 NOT_TAINTED),
148 create_test_promise(
149 remote_image_url +
150 '&mode=same-origin&url=' + encodeURIComponent(image_url),
151 'use-credentials',
152 NOT_TAINTED),
153
154 // Opaque response
155 create_test_promise(
156 image_url +
157 '&mode=no-cors&url=' + encodeURIComponent(remote_image_url),
158 '',
159 TAINTED),
160 create_test_promise(
161 image_url +
162 '&mode=no-cors&url=' + encodeURIComponent(remote_image_url),
163 'anonymous',
164 LOAD_ERROR),
165 create_test_promise(
166 image_url +
167 '&mode=no-cors&url=' + encodeURIComponent(remote_image_url),
168 'use-credentials',
169 LOAD_ERROR),
170 create_test_promise(
171 remote_image_url +
172 '&mode=no-cors&url=' + encodeURIComponent(remote_image_url),
173 '',
174 TAINTED),
175 create_test_promise(
176 remote_image_url +
177 '&mode=no-cors&url=' + encodeURIComponent(remote_image_url),
178 'anonymous',
179 LOAD_ERROR),
180 create_test_promise(
181 remote_image_url +
182 '&mode=no-cors&url=' + encodeURIComponent(remote_image_url),
183 'use-credentials',
184 LOAD_ERROR),
185
186 // CORS response
187 create_test_promise(
188 image_url +
189 '&mode=cors&url=' +
190 encodeURIComponent(remote_image_url +
191 '&ACAOrigin=' + host_info['HTTP_ORIGIN']),
192 '',
193 TAINTED), // FIXME: This should be NOT_TAINTED.
194 create_test_promise(
195 image_url +
196 '&mode=cors&url=' +
197 encodeURIComponent(remote_image_url +
198 '&ACAOrigin=' + host_info['HTTP_ORIGIN']),
199 'anonymous',
200 NOT_TAINTED),
201 create_test_promise(
202 image_url +
203 '&mode=cors&url=' +
204 encodeURIComponent(remote_image_url +
205 '&ACAOrigin=' + host_info['HTTP_ORIGIN']),
206 'use-credentials',
207 TAINTED), // FIXME: This should be NOT_TAINTED.
208 create_test_promise(
209 image_url +
210 '&mode=cors&url=' +
211 encodeURIComponent(
212 remote_image_url +
213 '&ACACredentials=true&ACAOrigin=' + host_info['HTTP_ORIGIN']),
214 'use-credentials',
215 NOT_TAINTED),
216 create_test_promise(
217 remote_image_url +
218 '&mode=cors&url=' +
219 encodeURIComponent(remote_image_url +
220 '&ACAOrigin=' + host_info['HTTP_ORIGIN']),
221 '',
222 TAINTED), // FIXME: This should be NOT_TAINTED.
223 create_test_promise(
224 remote_image_url +
225 '&mode=cors&url=' +
226 encodeURIComponent(remote_image_url +
227 '&ACAOrigin=' + host_info['HTTP_ORIGIN']),
228 'anonymous',
229 NOT_TAINTED),
230 create_test_promise(
231 remote_image_url +
232 '&mode=cors&url=' +
233 encodeURIComponent(remote_image_url +
234 '&ACAOrigin=' + host_info['HTTP_ORIGIN']),
235 'use-credentials',
236 TAINTED), // FIXME: This should be NOT_TAINTED.
237 create_test_promise(
238 remote_image_url +
239 '&mode=cors&url=' +
240 encodeURIComponent(
241 remote_image_url +
242 '&ACACredentials=true&ACAOrigin=' + host_info['HTTP_ORIGIN']),
243 'use-credentials',
244 NOT_TAINTED)
245 ])
76 .then(function() { 246 .then(function() {
77 port.postMessage({results: 'finish'}); 247 port.postMessage({results: 'finish'});
78 }) 248 })
79 .catch(function(e) { 249 .catch(function(e) {
80 port.postMessage({results: 'failure:' + e}); 250 port.postMessage({results: 'failure:' + e});
81 }); 251 });
82 }, false); 252 }, false);
83 </script> 253 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698