| Index: third_party/WebKit/LayoutTests/fast/workers/worker-sharedarraybuffer-transfer.html
|
| diff --git a/third_party/WebKit/LayoutTests/fast/workers/worker-sharedarraybuffer-transfer.html b/third_party/WebKit/LayoutTests/fast/workers/worker-sharedarraybuffer-transfer.html
|
| index 686b826cf8128031634dba0e3fa0cae8745ac869..63a9815aad247e820823b7d64ee9a3fa086275d8 100644
|
| --- a/third_party/WebKit/LayoutTests/fast/workers/worker-sharedarraybuffer-transfer.html
|
| +++ b/third_party/WebKit/LayoutTests/fast/workers/worker-sharedarraybuffer-transfer.html
|
| @@ -9,53 +9,129 @@ function log(message)
|
| document.getElementById("result").innerHTML += message + "</br>";
|
| }
|
|
|
| -if (window.testRunner) {
|
| - testRunner.dumpAsText();
|
| - testRunner.waitUntilDone();
|
| -}
|
| -
|
| var testCases = [
|
| - {name: "SharedArrayBuffer"},
|
| - {name: "Int8Array"},
|
| - {name: "Uint8Array"},
|
| - {name: "Uint8ClampedArray"},
|
| - {name: "Int16Array"},
|
| - {name: "Uint16Array"},
|
| - {name: "Int32Array"},
|
| - {name: "Uint32Array"},
|
| - {name: "Float32Array"},
|
| - {name: "Float64Array"}
|
| + "testSendSharedArrayBuffer",
|
| + "testSendInt8Array",
|
| + "testSendUint8Array",
|
| + "testSendUint8ClampedArray",
|
| + "testSendInt16Array",
|
| + "testSendUint16Array",
|
| + "testSendInt32Array",
|
| + "testSendUint32Array",
|
| + "testSendFloat32Array",
|
| + "testSendFloat64Array",
|
| + "testSendSharedArrayBufferTwice",
|
| + "testTransferArrayBufferAndSharedArrayBuffer"
|
| ];
|
| -var currentTestCase = 0;
|
| +var testIndex = 0;
|
| +
|
| +function runNextTest()
|
| +{
|
| + if (testIndex < testCases.length) {
|
| + testIndex++;
|
| + try {
|
| + window[testCases[testIndex - 1]]();
|
| + } catch (ex) {
|
| + log("FAIL: unexpected exception " + ex);
|
| + runNextTest();
|
| + }
|
| + } else {
|
| + log("DONE");
|
| + if (window.testRunner)
|
| + testRunner.notifyDone();
|
| + }
|
| +}
|
| +
|
| +function testSendSharedArrayBuffer()
|
| +{
|
| + runSendTest("SharedArrayBuffer");
|
| +}
|
| +
|
| +function testSendInt8Array()
|
| +{
|
| + runSendTest("Int8Array");
|
| +}
|
| +
|
| +function testSendUint8Array()
|
| +{
|
| + runSendTest("Uint8Array");
|
| +}
|
| +
|
| +function testSendUint8ClampedArray()
|
| +{
|
| + runSendTest("Uint8ClampedArray");
|
| +}
|
| +
|
| +function testSendInt16Array()
|
| +{
|
| + runSendTest("Int16Array");
|
| +}
|
| +
|
| +function testSendUint16Array()
|
| +{
|
| + runSendTest("Uint16Array");
|
| +}
|
| +
|
| +function testSendInt32Array()
|
| +{
|
| + runSendTest("Int32Array");
|
| +}
|
| +
|
| +function testSendUint32Array()
|
| +{
|
| + runSendTest("Uint32Array");
|
| +}
|
| +
|
| +function testSendFloat32Array()
|
| +{
|
| + runSendTest("Float32Array");
|
| +}
|
|
|
| -function runTestCase(testCase) {
|
| +function testSendFloat64Array()
|
| +{
|
| + runSendTest("Float64Array");
|
| +}
|
| +
|
| +function initializeTypedArray(ta, length) {
|
| + var i;
|
| + for (i = 0; i < length; ++i)
|
| + ta[i] = i;
|
| +}
|
| +
|
| +function runSendTest(name)
|
| +{
|
| var length = 8;
|
| - var name = testCase.name;
|
| var type = window[name];
|
| var sab;
|
| var ta;
|
| + var msg;
|
|
|
| log("Running " + name + " test case");
|
|
|
| - if (testCase.name == 'SharedArrayBuffer') {
|
| + if (name == 'SharedArrayBuffer') {
|
| sab = new SharedArrayBuffer(length);
|
| ta = new Uint8Array(sab);
|
| + msg = {name: name, data: sab, length: length};
|
| } else {
|
| sab = new SharedArrayBuffer(length * type.BYTES_PER_ELEMENT);
|
| ta = new type(sab);
|
| + msg = {name: name, data: ta, length: length};
|
| }
|
|
|
| - var i;
|
| - for (i = 0; i < length; ++i)
|
| - ta[i] = i;
|
| + initializeTypedArray(ta, length);
|
| +
|
| + // Don't allow passing a SharedArrayBuffer in the transfer list.
|
| + try {
|
| + worker.postMessage(msg, [sab]);
|
| + log("FAIL: Passing SharedArrayBuffer in the transfer list did not throw.");
|
| + } catch (e) {
|
| + log("PASS: Passing SharedArrayBuffer in the transfer list threw.");
|
| + }
|
|
|
| // Without Atomics, we can't safely test modifying the contents of the
|
| // SharedArrayBuffer. All we can test for now is that the SharedArrayBuffer
|
| // is not neutered when transferred to a Worker.
|
| - if (testCase.name == 'SharedArrayBuffer')
|
| - worker.postMessage({name: name, data: sab, length: length}, [sab]);
|
| - else
|
| - worker.postMessage({name: name, data: ta, length: length}, [sab]);
|
| + worker.postMessage(msg);
|
|
|
| if (sab.length === 0)
|
| log("FAIL: SharedArrayBuffer was neutered during transfer.");
|
| @@ -74,25 +150,64 @@ function runTestCase(testCase) {
|
| log("PASS: Original data not changed during transfer.");
|
| }
|
|
|
| +function testTransferArrayBufferAndSharedArrayBuffer() {
|
| + var ab = new ArrayBuffer(4);
|
| + var sab = new SharedArrayBuffer(16);
|
| + var msg = {
|
| + name : 'ArrayBufferAndSharedArrayBuffer',
|
| + ab: ab,
|
| + abLength: ab.byteLength,
|
| + sab: sab,
|
| + sabLength: sab.byteLength,
|
| + };
|
| +
|
| + log("Running TransferArrayBufferAndSharedArrayBuffer test case");
|
| +
|
| + initializeTypedArray(new Uint8Array(ab), ab.byteLength);
|
| + initializeTypedArray(new Uint8Array(sab), sab.byteLength);
|
| +
|
| + worker.postMessage(msg, [ab]);
|
| +
|
| + if (ab.byteLength === 0)
|
| + log("PASS: ArrayBuffer was neutered during transfer.");
|
| + else
|
| + log("FAIL: ArrayBuffer was not neutered during transfer.");
|
| +}
|
| +
|
| +function testSendSharedArrayBufferTwice() {
|
| + var sab = new SharedArrayBuffer(16);
|
| + var msg = {
|
| + name : 'SharedArrayBufferTwice',
|
| + sab: sab,
|
| + sabLength: sab.byteLength,
|
| + sab2: sab,
|
| + sab2Length: sab.byteLength,
|
| + };
|
| +
|
| + log("Running SendSharedArrayBufferTwice test case");
|
| +
|
| + initializeTypedArray(new Uint8Array(sab), sab.byteLength);
|
| +
|
| + worker.postMessage(msg);
|
| +}
|
| +
|
| +if (window.testRunner) {
|
| + testRunner.dumpAsText();
|
| + testRunner.waitUntilDone();
|
| +}
|
| +
|
| if (window.internals && internals.runtimeFlags.sharedArrayBufferEnabled && window.SharedArrayBuffer) {
|
| var worker = new Worker('resources/worker-sharedarraybuffer-transfer.js');
|
|
|
| - runTestCase(testCases[currentTestCase]);
|
| + runNextTest();
|
|
|
| worker.onmessage = function(e) {
|
| - if (e.data == 'DONE') {
|
| - // The current test case is finished.
|
| - if (++currentTestCase == testCases.length) {
|
| - log("DONE");
|
| - testRunner.notifyDone();
|
| - } else {
|
| - runTestCase(testCases[currentTestCase]);
|
| - }
|
| - } else {
|
| + if (e.data != 'DONE') {
|
| // The worker sent a pass/fail message.
|
| log(e.data);
|
| + } else {
|
| + runNextTest();
|
| }
|
| -
|
| };
|
| } else {
|
| log("SharedArrayBuffers are not enabled -- skipping test.");
|
|
|