OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <body> | 3 <body> |
4 <script src="/js-test-resources/js-test.js"></script> | 4 <script src="/js-test-resources/js-test.js"></script> |
5 <script> | 5 <script> |
6 description("The image bitmap factories should not throw exceptions on cross-ori
gin access."); | 6 description("The image bitmap factories should throw exceptions on cross-origin
access."); |
7 | 7 |
8 window.jsTestIsAsync = true; | 8 window.jsTestIsAsync = true; |
9 var reason; | 9 var reason; |
10 | 10 |
11 function shouldBeAcceptedAndTainted(promise, message) { | 11 function shouldBeRejected(promise, message) { |
12 return promise.then(function(imageBitmap) { | 12 return promise.then(function() { |
13 testPassed('Resolved as expected: ' + message); | 13 testFailed('Resolved unexpectedly: ' + message); |
14 shouldBeTainted(imageBitmap); | |
15 }, function(e) { | 14 }, function(e) { |
16 reason = e; | 15 reason = e; |
17 testFailed('Rejected unexpectedly: ' + message); | 16 testPassed('Rejected as expected: ' + message); |
18 shouldBeTrue('reason instanceof Error'); | 17 shouldBeTrue('reason instanceof Error'); |
19 debug(e); | 18 debug(e); |
20 }); | 19 }); |
21 } | 20 } |
22 | 21 |
23 function shouldBeTainted(imageBitmap) { | 22 Promise.resolve().then(function() { |
24 var canvas = document.createElement("canvas"); | 23 return new Promise(function(resolve, reject) { |
25 canvas.width = 10; | 24 var image = document.createElement('img'); |
26 canvas.height = 10; | 25 image.addEventListener('load', resolve.bind(undefined, image)); |
27 var context = canvas.getContext("2d"); | 26 image.src = 'http://localhost:8080/security/resources/abe.png'; |
28 context.drawImage(imageBitmap, 0, 0, 10, 10); | 27 document.body.appendChild(image); |
29 try { | 28 }).then(function(image) { |
30 var imageData = context.getImageData(0, 0, 10, 10); | 29 return shouldBeRejected(createImageBitmap(image, 0, 0, 10, 10), 'image')
; |
31 testFailed("ImageBitmap is not tainted."); | 30 }); |
32 } catch (e) { | 31 }).then(function() { |
33 testPassed("ImageBitmap is tainted. Threw error: " + e); | 32 return new Promise(function(resolve, reject) { |
34 } | 33 var video = document.createElement('video'); |
35 } | 34 video.src = 'http://localhost:8080/media/resources/load-video.php?name=t
est.ogv&type=video/ogv'; |
36 | 35 video.addEventListener('playing', resolve.bind(undefined, video)); |
37 var image = document.createElement('img'); | 36 document.body.appendChild(video); |
38 image.src = 'http://localhost:8080/security/resources/abe.png'; | 37 video.play(); |
39 var video = document.createElement('video'); | 38 }).then(function(video) { |
40 video.src = 'http://localhost:8080/media/resources/load-video.php?name=test.ogv&
amp;type=video/ogv'; | 39 return shouldBeRejected(createImageBitmap(video, 0, 0, 10, 10), 'video')
; |
41 | 40 }); |
42 image.addEventListener('load', function() { | 41 }).catch(function(e) { |
43 document.body.appendChild(image); | 42 testFailed('Unexpected rejection: ' + e); |
44 shouldBeAcceptedAndTainted(createImageBitmap(image, 0, 0, 10, 10), 'image') | 43 }).then(finishJSTest, finishJSTest); |
45 .then(function() { | |
46 var canvas = document.createElement("canvas"); | |
47 canvas.width = 10; | |
48 canvas.height = 10; | |
49 var context = canvas.getContext("2d"); | |
50 // taint the canvas | |
51 context.drawImage(image, 0, 0, 10, 10); | |
52 shouldBeAcceptedAndTainted(createImageBitmap(canvas, 0, 0, 10, 10), 'canvas'
) | |
53 .then(function() { | |
54 createImageBitmap(image).then(imageBitmap => { | |
55 shouldBeAcceptedAndTainted(createImageBitmap(imageBitmap, 0, 0, 10, 10), 'im
ageBitmap') | |
56 .then(function() { | |
57 document.body.appendChild(video); | |
58 video.play(); | |
59 video.addEventListener('playing', function() { | |
60 shouldBeAcceptedAndTainted(createImageBitmap(video, 0, 0, 10, 10), 'video'
) | |
61 .then(finishJSTest, ()=> { | |
62 testFailed("Unexpected failure"); | |
63 finishJSTest(); | |
64 }); | |
65 }); | |
66 }, ()=> { | |
67 testFailed("Unexpected failure"); | |
68 finishJSTest(); | |
69 }); | |
70 }); | |
71 }, ()=> { | |
72 testFailed("Unexpected failure"); | |
73 finishJSTest(); | |
74 }); | |
75 }, ()=> { | |
76 testFailed("Unexpected failure"); | |
77 finishJSTest(); | |
78 }); | |
79 }); | |
80 </script> | 44 </script> |
81 </body> | 45 </body> |
82 </html> | 46 </html> |
OLD | NEW |