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