dom/tests/mochitest/bugs/test_bug743615.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial