Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!-- |
michael@0 | 2 | Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 4 | --> |
michael@0 | 5 | <!DOCTYPE HTML> |
michael@0 | 6 | <html> |
michael@0 | 7 | <!-- |
michael@0 | 8 | Tests of DOM Worker transferable objects |
michael@0 | 9 | --> |
michael@0 | 10 | <head> |
michael@0 | 11 | <title>Test for DOM Worker transferable objects</title> |
michael@0 | 12 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 13 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 14 | </head> |
michael@0 | 15 | <body> |
michael@0 | 16 | <p id="display"></p> |
michael@0 | 17 | <div id="content" style="display: none"> |
michael@0 | 18 | |
michael@0 | 19 | </div> |
michael@0 | 20 | <pre id="test"> |
michael@0 | 21 | <script class="testbody" language="javascript"> |
michael@0 | 22 | |
michael@0 | 23 | function test1(sizes) { |
michael@0 | 24 | if (!sizes.length) { |
michael@0 | 25 | runTests(); |
michael@0 | 26 | return; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | var size = sizes.pop(); |
michael@0 | 30 | |
michael@0 | 31 | var worker = new Worker("transferable_worker.js"); |
michael@0 | 32 | worker.onmessage = function(event) { |
michael@0 | 33 | ok(event.data.status, event.data.event); |
michael@0 | 34 | if (!event.data.status) { |
michael@0 | 35 | runTests(); |
michael@0 | 36 | return; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | if ("notEmpty" in event.data && "byteLength" in event.data.notEmpty) { |
michael@0 | 40 | ok(event.data.notEmpty.byteLength != 0, |
michael@0 | 41 | "P: NotEmpty object received: " + event.data.notEmpty.byteLength); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | if (!event.data.last) |
michael@0 | 45 | return; |
michael@0 | 46 | |
michael@0 | 47 | test1(sizes); |
michael@0 | 48 | } |
michael@0 | 49 | worker.onerror = function(event) { |
michael@0 | 50 | ok(false, "No errors!"); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | try { |
michael@0 | 54 | worker.postMessage(42, true); |
michael@0 | 55 | ok(false, "P: PostMessage - Exception for wrong type"); |
michael@0 | 56 | } catch(e) { |
michael@0 | 57 | ok(true, "P: PostMessage - Exception for wrong type"); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | try { |
michael@0 | 61 | ab = new ArrayBuffer(size); |
michael@0 | 62 | worker.postMessage(42,[ab, ab]); |
michael@0 | 63 | ok(false, "P: PostMessage - Exception for duplicate"); |
michael@0 | 64 | } catch(e) { |
michael@0 | 65 | ok(true, "P: PostMessage - Exception for duplicate"); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | var ab = new ArrayBuffer(size); |
michael@0 | 69 | ok(ab.byteLength == size, "P: The size is: " + size + " == " + ab.byteLength); |
michael@0 | 70 | worker.postMessage({ data: 0, timeout: 0, ab: ab, cb: ab, size: size }, [ab]); |
michael@0 | 71 | ok(ab.byteLength == 0, "P: PostMessage - The size is: 0 == " + ab.byteLength) |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | function test2() { |
michael@0 | 75 | var worker = new Worker("transferable_worker.js"); |
michael@0 | 76 | worker.onmessage = function(event) { |
michael@0 | 77 | ok(event.data.status, event.data.event); |
michael@0 | 78 | if (!event.data.status) { |
michael@0 | 79 | runTests(); |
michael@0 | 80 | return; |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | if ("notEmpty" in event.data && "byteLength" in event.data.notEmpty) { |
michael@0 | 84 | ok(event.data.notEmpty.byteLength != 0, |
michael@0 | 85 | "P: NotEmpty object received: " + event.data.notEmpty.byteLength); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | if (event.data.last) { |
michael@0 | 89 | runTests(); |
michael@0 | 90 | } |
michael@0 | 91 | } |
michael@0 | 92 | worker.onerror = function(event) { |
michael@0 | 93 | ok(false, "No errors!"); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | var f = new Float32Array([0,1,2,3]); |
michael@0 | 97 | ok(f.byteLength != 0, "P: The size is: " + f.byteLength + " is not 0"); |
michael@0 | 98 | worker.postMessage({ event: "P: postMessage with Float32Array", status: true, |
michael@0 | 99 | size: 4, notEmpty: f, bc: [ f, f, { dd: f } ] }, [f.buffer]); |
michael@0 | 100 | ok(f.byteLength == 0, "P: The size is: " + f.byteLength + " is 0"); |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | var tests = [ |
michael@0 | 104 | function() { test1([1024 * 1024 * 32, 128, 4]); }, |
michael@0 | 105 | test2 |
michael@0 | 106 | ]; |
michael@0 | 107 | function runTests() { |
michael@0 | 108 | if (!tests.length) { |
michael@0 | 109 | SimpleTest.finish(); |
michael@0 | 110 | return; |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | var test = tests.shift(); |
michael@0 | 114 | test(); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 118 | runTests(); |
michael@0 | 119 | |
michael@0 | 120 | </script> |
michael@0 | 121 | </pre> |
michael@0 | 122 | </body> |
michael@0 | 123 | </html> |