Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / security / canvas-remote-read-remote-image-blocked-then-allowed.html
blob1965a2763a7fa7aa100ec1773434bcd4971a6e92
1 <pre id="console"></pre>
2 <script>
3 if (window.testRunner) {
4 testRunner.dumpAsText();
5 testRunner.waitUntilDone();
8 log = function(msg)
10 document.getElementById('console').appendChild(document.createTextNode(msg + "\n"));
13 var image;
14 var url = "http://localhost:8000/security/resources/abe-allow-star.php";
16 function testGetImageData(shouldWork)
18 var canvas = document.createElement("canvas");
19 canvas.width = 100;
20 canvas.height = 100;
21 var context = canvas.getContext("2d");
22 context.drawImage(image, 0, 0, 100, 100);
23 var worked = true;
24 try {
25 context.getImageData(0, 0, 100, 100);
26 } catch (e) {
27 worked = false;
29 if (worked == shouldWork) {
30 if (shouldWork) {
31 log("PASS: image did not taint canvas");
32 } else {
33 log("PASS: image tainted canvas");
35 } else {
36 if (shouldWork) {
37 log("FAIL: image tainted canvas");
38 } else {
39 log("FAIL: image did not taint canvas");
44 function testWithoutCORS()
46 log("Testing uploading without CORS headers");
47 testGetImageData(false);
48 image = new Image();
49 image.onload = testWithCORS;
50 image.crossOrigin = "";
51 image.src = url;
54 function testWithCORS()
56 log("Testing uploading with CORS headers");
57 testGetImageData(true);
58 if (window.testRunner)
59 testRunner.notifyDone();
62 function start()
64 log('Test that if an image is served with "Access-Control-Allow-Origin: *", then loading it first without and then with a CORS request works the second time.');
65 image = new Image();
66 image.onload = testWithoutCORS;
67 image.src = url;
70 start();
71 </script>