Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=743615 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <meta charset="utf-8"> |
michael@0 | 8 | <title>Test for Bug 743615</title> |
michael@0 | 9 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 10 | <script type="application/javascript" src="utils_bug743615.js"></script> |
michael@0 | 11 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 12 | </head> |
michael@0 | 13 | <body> |
michael@0 | 14 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=743615">Mozilla Bug 743615</a> |
michael@0 | 15 | <p id="display"></p> |
michael@0 | 16 | <div id="content" style="display: none"> |
michael@0 | 17 | <canvas id="c" width="200" height="200"><canvas> |
michael@0 | 18 | </div> |
michael@0 | 19 | <pre id="test"> |
michael@0 | 20 | <script type="application/javascript"> |
michael@0 | 21 | |
michael@0 | 22 | /** Test for structured cloning ImageData. **/ |
michael@0 | 23 | |
michael@0 | 24 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 25 | window.addEventListener('message', windowMessage); |
michael@0 | 26 | startTest(); |
michael@0 | 27 | |
michael@0 | 28 | function startTest() { |
michael@0 | 29 | // Make an ImageData. |
michael@0 | 30 | var ctx = document.getElementById('c').getContext('2d'); |
michael@0 | 31 | ctx.fillStyle = 'rgb('; |
michael@0 | 32 | ctx.fillRect(30, 30, 50, 50); |
michael@0 | 33 | |
michael@0 | 34 | // Make a blank ImageData. |
michael@0 | 35 | var imageData = ctx.createImageData(200, 200); |
michael@0 | 36 | is(imageData.data.length, imageData.width * imageData.height * 4, |
michael@0 | 37 | 'right size for data'); |
michael@0 | 38 | |
michael@0 | 39 | // Write some things into it. |
michael@0 | 40 | var pattern = makePattern(imageData.data.length, 42, 7); |
michael@0 | 41 | setPattern(imageData, pattern); |
michael@0 | 42 | ok(checkPattern(imageData, pattern), 'Can read it back before sending'); |
michael@0 | 43 | |
michael@0 | 44 | // PostMessage it to ourselves. |
michael@0 | 45 | window.postMessage({ imageData: imageData, |
michael@0 | 46 | pattern: pattern, |
michael@0 | 47 | dataRef: imageData.data }, '*'); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function windowMessage(evt) { |
michael@0 | 51 | // Check the pattern we received. |
michael@0 | 52 | var imageData = evt.data.imageData; |
michael@0 | 53 | var pattern = evt.data.pattern; |
michael@0 | 54 | ok(checkPattern(imageData, pattern), |
michael@0 | 55 | 'postMessage from self worked correctly'); |
michael@0 | 56 | |
michael@0 | 57 | // We're not spec compliant on this yet. |
michael@0 | 58 | todo_is(imageData.data, evt.data.dataRef, |
michael@0 | 59 | 'Should have backrefs for imagedata buffer'); |
michael@0 | 60 | |
michael@0 | 61 | // Make a new pattern, and send it to a worker. |
michael@0 | 62 | pattern = makePattern(imageData.data.length, 4, 3); |
michael@0 | 63 | setPattern(imageData, pattern); |
michael@0 | 64 | var worker = new Worker('worker_bug743615.js'); |
michael@0 | 65 | worker.onmessage = workerMessage; |
michael@0 | 66 | worker.postMessage( {imageData: imageData, pattern: pattern }); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | function workerMessage(evt) { |
michael@0 | 70 | // Relay the results of the worker-side tests. |
michael@0 | 71 | is(evt.data.statusMessage, 'PASS', evt.data.statusMessage); |
michael@0 | 72 | |
michael@0 | 73 | // Test what the worker sent us. |
michael@0 | 74 | ok(checkPattern(evt.data.imageData, evt.data.pattern), |
michael@0 | 75 | 'postMessage from worker worked correctly'); |
michael@0 | 76 | |
michael@0 | 77 | // All done. |
michael@0 | 78 | SimpleTest.finish(); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | </script> |
michael@0 | 82 | </pre> |
michael@0 | 83 | </body> |
michael@0 | 84 | </html> |