| <!DOCTYPE html> |
| <html> |
| <body> |
| <canvas id="canvas"> |
| <img id="img" onload="drawInCanvas()"></img> |
| <script> |
| var test = JSON.parse(decodeURIComponent(location.hash.substring(1))); |
| |
| function logError() |
| { |
| parent.postMessage((!test.shouldPass ? "PASS": "FAIL") + ": The image is not same-origin with this document.", "*"); |
| } |
| |
| function logPass() |
| { |
| parent.postMessage((test.shouldPass ? "PASS": "FAIL") + ": Successfully retrieved image data.", "*"); |
| } |
| |
| function drawInCanvas() |
| { |
| var canvas = document.getElementById('canvas'); |
| var ctx = canvas.getContext('2d'); |
| ctx.drawImage(document.getElementById('img'), 0, 0); |
| |
| // Grab a pixel to verify that the image is same-origin: |
| try { |
| var pixel = ctx.getImageData(0, 0, 1, 1); |
| logPass(); |
| } catch (e) { |
| logError(); |
| } |
| } |
| |
| var node = document.getElementById(test.node); |
| node.src = test.url; |
| </script> |
| </body> |
| </html> |