Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/security/cross-origin-createImageBitmap.html |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/security/cross-origin-createImageBitmap.html b/third_party/WebKit/LayoutTests/http/tests/security/cross-origin-createImageBitmap.html |
| index b5b56246330c1651dda1cd7b99ac56b1721b2f14..f608a10a4a1626567bf882e4557010a68d165ebf 100644 |
| --- a/third_party/WebKit/LayoutTests/http/tests/security/cross-origin-createImageBitmap.html |
| +++ b/third_party/WebKit/LayoutTests/http/tests/security/cross-origin-createImageBitmap.html |
| @@ -3,44 +3,66 @@ |
| <body> |
| <script src="/js-test-resources/js-test.js"></script> |
| <script> |
| -description("The image bitmap factories should throw exceptions on cross-origin access."); |
| +description("The image bitmap factories should not throw exceptions on cross-origin access."); |
| window.jsTestIsAsync = true; |
| var reason; |
| -function shouldBeRejected(promise, message) { |
| - return promise.then(function() { |
| - testFailed('Resolved unexpectedly: ' + message); |
| +function shouldBeAcceptedAndTainted(promise, message) { |
| + return promise.then(function(imageBitmap) { |
| + testPassed('Resolved as expected: ' + message); |
| + shouldBeTainted(imageBitmap); |
| }, function(e) { |
| reason = e; |
| - testPassed('Rejected as expected: ' + message); |
| + testFailed('Rejected unexpectedly: ' + message); |
| shouldBeTrue('reason instanceof Error'); |
| debug(e); |
| }); |
| } |
| -Promise.resolve().then(function() { |
| - return new Promise(function(resolve, reject) { |
| - var image = document.createElement('img'); |
| - image.addEventListener('load', resolve.bind(undefined, image)); |
| - image.src = 'http://localhost:8080/security/resources/abe.png'; |
| - document.body.appendChild(image); |
| - }).then(function(image) { |
| - return shouldBeRejected(createImageBitmap(image, 0, 0, 10, 10), 'image'); |
| +function shouldBeTainted(imageBitmap) { |
| + var canvas = document.createElement("canvas"); |
| + canvas.width = 10; |
| + canvas.height = 10; |
| + var context = canvas.getContext("2d"); |
| + context.drawImage(imageBitmap, 0, 0, 10, 10); |
| + try { |
| + var imageData = context.getImageData(0, 0, 10, 10); |
| + testFailed("FAIL: ImageBitmap is not tainted."); |
| + } catch (e) { |
| + testPassed("PASS: ImageBitmap is tainted. Threw error: " + e); |
| + } |
| +} |
| + |
| +var image = document.createElement('img'); |
| +image.src = 'http://localhost:8080/security/resources/abe.png'; |
| +var video = document.createElement('video'); |
| +video.src = 'http://localhost:8080/media/resources/load-video.php?name=test.ogv&type=video/ogv'; |
| +var p1, p2, p3, p4; |
| + |
| +image.addEventListener('load', function() { |
| + document.body.appendChild(image); |
| + p1 = shouldBeAcceptedAndTainted(createImageBitmap(image, 0, 0, 10, 10), 'image'); |
| + var canvas = document.createElement("canvas"); |
| + canvas.width = 10; |
| + canvas.height = 10; |
| + var context = canvas.getContext("2d"); |
| + context.drawImage(image, 0, 0, 10, 10); |
|
Justin Novosad
2015/12/30 20:42:18
Add a comment that this is to taint the canvas
xidachen
2015/12/31 03:37:01
Done.
|
| + p2 = shouldBeAcceptedAndTainted(createImageBitmap(canvas, 0, 0, 10, 10), 'canvas'); |
| + createImageBitmap(image).then(imageBitmap => { |
| + p3 = shouldBeAcceptedAndTainted(createImageBitmap(imageBitmap, 0, 0, 10, 10), 'imageBitmap'); |
| }); |
| -}).then(function() { |
| - return new Promise(function(resolve, reject) { |
| - var video = document.createElement('video'); |
| - video.src = 'http://localhost:8080/media/resources/load-video.php?name=test.ogv&type=video/ogv'; |
| - video.addEventListener('playing', resolve.bind(undefined, video)); |
| + Promise.all([p1, p2, p3]).then(function() { |
|
Justin Novosad
2015/12/30 20:42:18
Although this is clean and concise, it makes execu
xidachen
2015/12/31 03:37:01
Done.
|
| document.body.appendChild(video); |
| video.play(); |
| - }).then(function(video) { |
| - return shouldBeRejected(createImageBitmap(video, 0, 0, 10, 10), 'video'); |
| + video.addEventListener('playing', function() { |
| + p4 = shouldBeAcceptedAndTainted(createImageBitmap(video, 0, 0, 10, 10), 'video'); |
| + p4.then(finishJSTest, finishJSTest); |
| + }); |
| + }, function() { |
| + finishJSTest(); |
| }); |
| -}).catch(function(e) { |
| - testFailed('Unexpected rejection: ' + e); |
| -}).then(finishJSTest, finishJSTest); |
| +}); |
| </script> |
| </body> |
| </html> |