diff --git a/dom/workers/test/test_transferable.html b/dom/workers/test/test_transferable.html index 3490c910f8cc..a3deec12a228 100644 --- a/dom/workers/test/test_transferable.html +++ b/dom/workers/test/test_transferable.html @@ -22,7 +22,7 @@ Tests of DOM Worker transferable objects function test1(sizes) { if (!sizes.length) { - SimpleTest.finish(); + runTests(); return; } @@ -32,10 +32,15 @@ Tests of DOM Worker transferable objects worker.onmessage = function(event) { ok(event.data.status, event.data.event); if (!event.data.status) { - SimpleTest.finish(); + runTests(); return; } + if ("notEmpty" in event.data && "byteLength" in event.data.notEmpty) { + ok(event.data.notEmpty.byteLength != 0, + "P: NotEmpty object received: " + event.data.notEmpty.byteLength); + } + if (!event.data.last) return; @@ -60,14 +65,57 @@ Tests of DOM Worker transferable objects ok(true, "P: PostMessage - Exception for duplicate"); } - ab = new ArrayBuffer(size); + var ab = new ArrayBuffer(size); ok(ab.byteLength == size, "P: The size is: " + size + " == " + ab.byteLength); worker.postMessage({ data: 0, timeout: 0, ab: ab, cb: ab, size: size }, [ab]); ok(ab.byteLength == 0, "P: PostMessage - The size is: 0 == " + ab.byteLength) } - test1([1024 * 1024 * 32, 128, 4]); + function test2() { + var worker = new Worker("transferable_worker.js"); + worker.onmessage = function(event) { + ok(event.data.status, event.data.event); + if (!event.data.status) { + runTests(); + return; + } + + if ("notEmpty" in event.data && "byteLength" in event.data.notEmpty) { + ok(event.data.notEmpty.byteLength != 0, + "P: NotEmpty object received: " + event.data.notEmpty.byteLength); + } + + if (event.data.last) { + runTests(); + } + } + worker.onerror = function(event) { + ok(false, "No errors!"); + } + + var f = new Float32Array([0,1,2,3]); + ok(f.byteLength != 0, "P: The size is: " + f.byteLength + " is not 0"); + worker.postMessage({ event: "P: postMessage with Float32Array", status: true, + size: 4, notEmpty: f, bc: [ f, f, { dd: f } ] }, [f.buffer]); + ok(f.byteLength == 0, "P: The size is: " + f.byteLength + " is 0"); + } + + var tests = [ + function() { test1([1024 * 1024 * 32, 128, 4]); }, + test2 + ]; + function runTests() { + if (!tests.length) { + SimpleTest.finish(); + return; + } + + var test = tests.shift(); + test(); + } + SimpleTest.waitForExplicitFinish(); + runTests(); diff --git a/dom/workers/test/transferable_worker.js b/dom/workers/test/transferable_worker.js index a8026830742a..3caf6121b540 100644 --- a/dom/workers/test/transferable_worker.js +++ b/dom/workers/test/transferable_worker.js @@ -4,30 +4,20 @@ */ onmessage = function(event) { - if (event.data.data == 0) { - ab = new ArrayBuffer(event.data.size); - postMessage({ event: "W: The size is: " + event.data.size + " == " + ab.byteLength, - status: ab.byteLength == event.data.size, last: false }); - - postMessage({ event: "W: postMessage with arrayBuffer", status: true, - ab: ab, bc: [ ab, ab, { dd: ab } ] }, [ab]); - - postMessage({ event: "W: The size is: 0 == " + ab.byteLength, - status: ab.byteLength == 0, last: false }); - - postMessage({ event: "last one!", status: true, last: true }); - - } else { - var worker = new Worker('sync_worker.js'); - worker.onmessage = function(event) { - postMessage(event.data); - } - worker.onsyncmessage = function(event) { - var v = postSyncMessage(event.data, null, 500); - event.reply(v); - } - - --event.data.data; - worker.postMessage(event.data); + if ("notEmpty" in event.data && "byteLength" in event.data.notEmpty) { + postMessage({ event: "W: NotEmpty object received: " + event.data.notEmpty.byteLength, + status: event.data.notEmpty.byteLength != 0, last: false }); } + + var ab = new ArrayBuffer(event.data.size); + postMessage({ event: "W: The size is: " + event.data.size + " == " + ab.byteLength, + status: ab.byteLength == event.data.size, last: false }); + + postMessage({ event: "W: postMessage with arrayBuffer", status: true, + notEmpty: ab, ab: ab, bc: [ ab, ab, { dd: ab } ] }, [ab]); + + postMessage({ event: "W: The size is: 0 == " + ab.byteLength, + status: ab.byteLength == 0, last: false }); + + postMessage({ event: "W: last one!", status: true, last: true }); }