1 <script src=
"../../resources/get-host-info.js"></script>
2 <script src=
"test-helpers.js?pipe=sub"></script>
4 var image_path
= base_path() + 'fetch-access-control.php?PNGIMAGE';
5 var host_info
= get_host_info();
7 var NOT_TAINTED
= 'NOT_TAINTED';
8 var TAINTED
= 'TAINTED';
9 var LOAD_ERROR
= 'LOAD_ERROR';
11 function create_test_case_promise(url
, cross_origin
) {
12 return new Promise(function(resolve
) {
13 var img
= new Image();
14 if (cross_origin
!= '') {
15 img
.crossOrigin
= cross_origin
;
17 img
.onload = function() {
19 var canvas
= document
.createElement('canvas');
22 var context
= canvas
.getContext('2d');
23 context
.drawImage(img
, 0, 0);
24 context
.getImageData(0, 0, 100, 100);
30 img
.onerror = function() {
37 function create_test_promise(url
, cross_origin
, expected_result
) {
38 return new Promise(function(resolve
, reject
) {
39 create_test_case_promise(url
, cross_origin
)
40 .then(function(result
) {
41 if (result
== expected_result
) {
44 reject('Result of url:' + url
+ ' ' +
45 ' cross_origin: ' + cross_origin
+ ' must be ' +
46 expected_result
+ ' but ' + result
);
52 window
.addEventListener('message', function(evt
) {
53 var port
= evt
.ports
[0];
54 var image_url
= host_info
['HTTP_ORIGIN'] + image_path
;
55 var remote_image_url
= host_info
['HTTP_REMOTE_ORIGIN'] + image_path
;
58 create_test_promise(image_url
+ '&reject', '', LOAD_ERROR
),
59 create_test_promise(image_url
+ '&reject', 'anonymous', LOAD_ERROR
),
61 image_url
+ '&reject', 'use-credentials', LOAD_ERROR
),
64 image_url
+ '&ignore',
68 remote_image_url
+ '&ignore',
72 remote_image_url
+ '&ignore',
76 remote_image_url
+ '&ACAOrigin=' + host_info
['HTTP_ORIGIN'] +
81 remote_image_url
+ '&ignore',
85 remote_image_url
+ '&ACAOrigin=' + host_info
['HTTP_ORIGIN'] +
90 remote_image_url
+ '&ACAOrigin=' + host_info
['HTTP_ORIGIN'] +
91 '&ACACredentials=true&ignore',
95 // Credential test (fallback)
97 image_url
+ '&Auth&ignore',
101 remote_image_url
+ '&Auth&ignore',
105 remote_image_url
+ '&Auth&ignore',
109 remote_image_url
+ '&Auth&ignore',
113 remote_image_url
+ '&Auth&ACAOrigin=' + host_info
['HTTP_ORIGIN'] +
118 remote_image_url
+ '&Auth&ACAOrigin=' + host_info
['HTTP_ORIGIN'] +
119 '&ACACredentials=true&ignore',
126 '&mode=same-origin&url=' + encodeURIComponent(image_url
),
131 '&mode=same-origin&url=' + encodeURIComponent(image_url
),
136 '&mode=same-origin&url=' + encodeURIComponent(image_url
),
141 '&mode=same-origin&url=' + encodeURIComponent(image_url
),
146 '&mode=same-origin&url=' + encodeURIComponent(image_url
),
151 '&mode=same-origin&url=' + encodeURIComponent(image_url
),
158 '&mode=no-cors&url=' + encodeURIComponent(remote_image_url
),
163 '&mode=no-cors&url=' + encodeURIComponent(remote_image_url
),
168 '&mode=no-cors&url=' + encodeURIComponent(remote_image_url
),
173 '&mode=no-cors&url=' + encodeURIComponent(remote_image_url
),
178 '&mode=no-cors&url=' + encodeURIComponent(remote_image_url
),
183 '&mode=no-cors&url=' + encodeURIComponent(remote_image_url
),
191 encodeURIComponent(remote_image_url
+
192 '&ACAOrigin=' + host_info
['HTTP_ORIGIN']),
198 encodeURIComponent(remote_image_url
+
199 '&ACAOrigin=' + host_info
['HTTP_ORIGIN']),
205 encodeURIComponent(remote_image_url
+
206 '&ACAOrigin=' + host_info
['HTTP_ORIGIN']),
214 '&ACACredentials=true&ACAOrigin=' + host_info
['HTTP_ORIGIN']),
220 encodeURIComponent(remote_image_url
+
221 '&ACAOrigin=' + host_info
['HTTP_ORIGIN']),
227 encodeURIComponent(remote_image_url
+
228 '&ACAOrigin=' + host_info
['HTTP_ORIGIN']),
234 encodeURIComponent(remote_image_url
+
235 '&ACAOrigin=' + host_info
['HTTP_ORIGIN']),
243 '&ACACredentials=true&ACAOrigin=' + host_info
['HTTP_ORIGIN']),
248 port
.postMessage({results
: 'finish'});
251 port
.postMessage({results
: 'failure:' + e
});