dom/tests/mochitest/bugs/test_bug743615.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/bugs/test_bug743615.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=743615
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Test for Bug 743615</title>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <script type="application/javascript" src="utils_bug743615.js"></script>
    1.14 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.15 +</head>
    1.16 +<body>
    1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=743615">Mozilla Bug 743615</a>
    1.18 +<p id="display"></p>
    1.19 +<div id="content" style="display: none">
    1.20 +<canvas id="c" width="200" height="200"><canvas>
    1.21 +</div>
    1.22 +<pre id="test">
    1.23 +<script type="application/javascript">
    1.24 +
    1.25 +/** Test for structured cloning ImageData. **/
    1.26 +
    1.27 +SimpleTest.waitForExplicitFinish();
    1.28 +window.addEventListener('message', windowMessage);
    1.29 +startTest();
    1.30 +
    1.31 +function startTest() {
    1.32 +  // Make an ImageData.
    1.33 +  var ctx = document.getElementById('c').getContext('2d');
    1.34 +  ctx.fillStyle = 'rgb(';
    1.35 +  ctx.fillRect(30, 30, 50, 50);
    1.36 +
    1.37 +  // Make a blank ImageData.
    1.38 +  var imageData = ctx.createImageData(200, 200);
    1.39 +  is(imageData.data.length, imageData.width * imageData.height * 4,
    1.40 +   'right size for data');
    1.41 +
    1.42 +  // Write some things into it.
    1.43 +  var pattern = makePattern(imageData.data.length, 42, 7);
    1.44 +  setPattern(imageData, pattern);
    1.45 +  ok(checkPattern(imageData, pattern), 'Can read it back before sending');
    1.46 +
    1.47 +  // PostMessage it to ourselves.
    1.48 +  window.postMessage({ imageData: imageData,
    1.49 +                       pattern: pattern,
    1.50 +                       dataRef: imageData.data }, '*');
    1.51 +}
    1.52 +
    1.53 +function windowMessage(evt) {
    1.54 +  // Check the pattern we received.
    1.55 +  var imageData = evt.data.imageData;
    1.56 +  var pattern = evt.data.pattern;
    1.57 +  ok(checkPattern(imageData, pattern),
    1.58 +     'postMessage from self worked correctly');
    1.59 +
    1.60 +  // We're not spec compliant on this yet.
    1.61 +  todo_is(imageData.data, evt.data.dataRef,
    1.62 +          'Should have backrefs for imagedata buffer');
    1.63 +
    1.64 +  // Make a new pattern, and send it to a worker.
    1.65 +  pattern = makePattern(imageData.data.length, 4, 3);
    1.66 +  setPattern(imageData, pattern);
    1.67 +  var worker = new Worker('worker_bug743615.js');
    1.68 +  worker.onmessage = workerMessage;
    1.69 +  worker.postMessage( {imageData: imageData, pattern: pattern });
    1.70 +}
    1.71 +
    1.72 +function workerMessage(evt) {
    1.73 +  // Relay the results of the worker-side tests.
    1.74 +  is(evt.data.statusMessage, 'PASS', evt.data.statusMessage);
    1.75 +
    1.76 +  // Test what the worker sent us.
    1.77 +  ok(checkPattern(evt.data.imageData, evt.data.pattern),
    1.78 +     'postMessage from worker worked correctly');
    1.79 +
    1.80 +  // All done.
    1.81 +  SimpleTest.finish();
    1.82 +}
    1.83 +
    1.84 +</script>
    1.85 +</pre>
    1.86 +</body>
    1.87 +</html>

mercurial