Bug 1611855 - Worklet must be part of the same parent's agentCluster - part 10 - split test_postMessages.html, r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D61503

--HG--
rename : dom/base/test/test_postMessages.html => dom/base/test/common_postMessages.js
rename : dom/base/test/test_postMessages.html => dom/base/test/test_postMessages_broadcastChannel.html
rename : dom/base/test/test_postMessages.html => dom/base/test/test_postMessages_messagePort.html
rename : dom/base/test/test_postMessages.html => dom/base/test/test_postMessages_window.html
rename : dom/base/test/test_postMessages.html => dom/base/test/test_postMessages_workers.html
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2020-02-05 22:10:52 +00:00
Родитель 328568c1cf
Коммит d6faf548b2
7 изменённых файлов: 862 добавлений и 777 удалений

Просмотреть файл

@ -0,0 +1,340 @@
function setup_tests() {
SpecialPowers.pushPrefEnv({ set: [["dom.input.dirpicker", true]] }, next);
}
function getType(a) {
if (a === null || a === undefined) {
return "null";
}
if (Array.isArray(a)) {
return "array";
}
if (typeof a == "object") {
return "object";
}
if (
SpecialPowers.Cu.getJSTestingFunctions().wasmIsSupported() &&
a instanceof WebAssembly.Module
) {
return "wasm";
}
return "primitive";
}
function compare(a, b) {
is(getType(a), getType(b), "Type matches");
var type = getType(a);
if (type == "array") {
is(a.length, b.length, "Array.length matches");
for (var i = 0; i < a.length; ++i) {
compare(a[i], b[i]);
}
return;
}
if (type == "object") {
ok(a !== b, "They should not match");
var aProps = [];
for (var p in a) {
aProps.push(p);
}
var bProps = [];
for (var p in b) {
bProps.push(p);
}
is(aProps.length, bProps.length, "Props match");
is(aProps.sort().toString(), bProps.sort().toString(), "Props names match");
for (var p in a) {
compare(a[p], b[p]);
}
return;
}
if (type == "wasm") {
var wasmA = new WebAssembly.Instance(a);
ok(wasmA instanceof WebAssembly.Instance, "got an instance");
var wasmB = new WebAssembly.Instance(b);
ok(wasmB instanceof WebAssembly.Instance, "got an instance");
ok(wasmA.exports.foo() === wasmB.exports.foo(), "Same result!");
ok(wasmB.exports.foo() === 42, "We want 42");
}
if (type != "null") {
is(a, b, "Same value");
}
}
var clonableObjects = [
{ target: "all", data: "hello world" },
{ target: "all", data: 123 },
{ target: "all", data: null },
{ target: "all", data: true },
{ target: "all", data: new Date() },
{ target: "all", data: [1, "test", true, new Date()] },
{
target: "all",
data: { a: true, b: null, c: new Date(), d: [true, false, {}] },
},
{ target: "all", data: new Blob([123], { type: "plain/text" }) },
{ target: "all", data: new ImageData(2, 2) },
];
function create_fileList() {
var url = SimpleTest.getTestFileURL("script_postmessages_fileList.js");
var script = SpecialPowers.loadChromeScript(url);
function onOpened(message) {
var fileList = document.getElementById("fileList");
SpecialPowers.wrap(fileList).mozSetFileArray([message.file]);
// Just a simple test
var domFile = fileList.files[0];
is(domFile.name, "prefs.js", "fileName should be prefs.js");
clonableObjects.push({ target: "all", data: fileList.files });
script.destroy();
next();
}
script.addMessageListener("file.opened", onOpened);
script.sendAsyncMessage("file.open");
}
function create_directory() {
if (navigator.userAgent.toLowerCase().includes("Android")) {
next();
return;
}
var url = SimpleTest.getTestFileURL("script_postmessages_fileList.js");
var script = SpecialPowers.loadChromeScript(url);
function onOpened(message) {
var fileList = document.getElementById("fileList");
SpecialPowers.wrap(fileList).mozSetDirectory(message.dir);
fileList.getFilesAndDirectories().then(function(list) {
// Just a simple test
is(list.length, 1, "This list has 1 element");
ok(list[0] instanceof Directory, "We have a directory.");
clonableObjects.push({ target: "all", data: list[0] });
script.destroy();
next();
});
}
script.addMessageListener("dir.opened", onOpened);
script.sendAsyncMessage("dir.open");
}
function create_wasmModule() {
info("Checking if we can play with WebAssembly...");
if (!SpecialPowers.Cu.getJSTestingFunctions().wasmIsSupported()) {
next();
return;
}
ok(WebAssembly, "WebAssembly object should exist");
ok(WebAssembly.compile, "WebAssembly.compile function should exist");
const wasmTextToBinary = SpecialPowers.unwrap(
SpecialPowers.Cu.getJSTestingFunctions().wasmTextToBinary
);
const fooModuleCode = wasmTextToBinary(`(module
(func $foo (result i32) (i32.const 42))
(export "foo" $foo)
)`);
WebAssembly.compile(fooModuleCode).then(
m => {
ok(m instanceof WebAssembly.Module, "The WasmModule has been compiled.");
clonableObjects.push({ target: "sameProcess", data: m });
next();
},
() => {
ok(false, "The compilation of the wasmModule failed.");
}
);
}
function runTests(obj) {
ok(
"clonableObjectsEveryWhere" in obj &&
"clonableObjectsSameProcess" in obj &&
"transferableObjects" in obj &&
(obj.clonableObjectsEveryWhere ||
obj.clonableObjectsSameProcess ||
obj.transferableObjects),
"We must run some test!"
);
// cloning tests - everyWhere
new Promise(function(resolve, reject) {
var clonableObjectsId = 0;
function runClonableTest() {
if (clonableObjectsId >= clonableObjects.length) {
resolve();
return;
}
var object = clonableObjects[clonableObjectsId++];
if (object.target != "all") {
runClonableTest();
return;
}
obj
.send(object.data, [])
.catch(() => {
return { error: true };
})
.then(received => {
if (!obj.clonableObjectsEveryWhere) {
ok(received.error, "Error expected");
} else {
ok(!received.error, "Error not expected");
compare(received.data, object.data);
}
runClonableTest();
});
}
runClonableTest();
})
// clonable same process
.then(function() {
return new Promise(function(resolve, reject) {
var clonableObjectsId = 0;
function runClonableTest() {
if (clonableObjectsId >= clonableObjects.length) {
resolve();
return;
}
var object = clonableObjects[clonableObjectsId++];
if (object.target != "sameProcess") {
runClonableTest();
return;
}
obj
.send(object.data, [])
.catch(() => {
return { error: true };
})
.then(received => {
if (!obj.clonableObjectsSameProcess) {
ok(received.error, "Error expected");
} else {
ok(!received.error, "Error not expected");
compare(received.data, object.data);
}
runClonableTest();
});
}
runClonableTest();
});
})
// transfering tests
.then(function() {
if (!obj.transferableObjects) {
return;
}
// MessagePort
return new Promise(function(r, rr) {
var mc = new MessageChannel();
obj.send(42, [mc.port1]).then(function(received) {
is(received.ports.length, 1, "MessagePort has been transferred");
mc.port2.postMessage("hello world");
received.ports[0].onmessage = function(e) {
is(e.data, "hello world", "Ports are connected!");
r();
};
});
});
})
// no dup transfering
.then(function() {
if (!obj.transferableObjects) {
return;
}
// MessagePort
return new Promise(function(r, rr) {
var mc = new MessageChannel();
obj
.send(42, [mc.port1, mc.port1])
.then(
function(received) {
ok(false, "Duplicate ports should throw!");
},
function() {
ok(true, "Duplicate ports should throw!");
}
)
.then(r);
});
})
// non transfering tests
.then(function() {
if (obj.transferableObjects) {
return;
}
// MessagePort
return new Promise(function(r, rr) {
var mc = new MessageChannel();
obj
.send(42, [mc.port1])
.then(
function(received) {
ok(false, "This object should not support port transferring");
},
function() {
ok(true, "This object should not support port transferring");
}
)
.then(r);
});
})
// done.
.then(function() {
obj.finished();
});
}
function next() {
if (!tests.length) {
SimpleTest.finish();
return;
}
var test = tests.shift();
test();
}
var tests = [setup_tests, create_fileList, create_directory, create_wasmModule];

Просмотреть файл

@ -210,7 +210,9 @@ support-files =
referrer_header.sjs
referrer_header_current_document_iframe.html
script_postmessages_fileList.js
common_postMessages.js
iframe_postMessages.html
worker_postMessages.js
test_anonymousContent_style_csp.html^headers^
file_explicit_user_agent.sjs
referrer_change_server.sjs
@ -779,8 +781,10 @@ skip-if = toolkit == 'android' # Plugins don't work on Android
tags = audiochannel
skip-if = toolkit == 'android' # Plugins don't work on Android
[test_postMessage_solidus.html]
[test_postMessages.html]
support-files = worker_postMessages.js
[test_postMessages_window.html]
[test_postMessages_workers.html]
[test_postMessages_broadcastChannel.html]
[test_postMessages_messagePort.html]
[test_postMessage_originAttributes.html]
support-files = file_receiveMessage.html
[test_processing_instruction_update_stylesheet.xhtml]

Просмотреть файл

@ -1,775 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for postMessages cloning/transferring objects</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<input id="fileList" type="file"></input>
<script type="application/javascript">
function setup_tests() {
SpecialPowers.pushPrefEnv({"set": [["dom.input.dirpicker", true]]}, next);
}
function getType(a) {
if (a === null || a === undefined)
return 'null';
if (Array.isArray(a))
return 'array';
if (typeof a == 'object')
return 'object';
if (SpecialPowers.Cu.getJSTestingFunctions().wasmIsSupported() &&
a instanceof WebAssembly.Module)
return "wasm";
return 'primitive';
}
function compare(a, b) {
is (getType(a), getType(b), 'Type matches');
var type = getType(a);
if (type == 'array') {
is (a.length, b.length, 'Array.length matches');
for (var i = 0; i < a.length; ++i) {
compare(a[i], b[i]);
}
return;
}
if (type == 'object') {
ok (a !== b, 'They should not match');
var aProps = [];
for (var p in a) aProps.push(p);
var bProps = [];
for (var p in b) bProps.push(p);
is (aProps.length, bProps.length, 'Props match');
is (aProps.sort().toString(), bProps.sort().toString(), 'Props names match');
for (var p in a) {
compare(a[p], b[p]);
}
return;
}
if (type == 'wasm') {
var wasmA = new WebAssembly.Instance(a);
ok(wasmA instanceof WebAssembly.Instance, "got an instance");
var wasmB = new WebAssembly.Instance(b);
ok(wasmB instanceof WebAssembly.Instance, "got an instance");
ok(wasmA.exports.foo() === wasmB.exports.foo(), "Same result!");
ok(wasmB.exports.foo() === 42, "We want 42");
}
if (type != 'null') {
is (a, b, 'Same value');
}
}
var clonableObjects = [
{ target: 'all', data: 'hello world' },
{ target: 'all', data: 123 },
{ target: 'all', data: null },
{ target: 'all', data: true },
{ target: 'all', data: new Date() },
{ target: 'all', data: [ 1, 'test', true, new Date() ] },
{ target: 'all', data: { a: true, b: null, c: new Date(), d: [ true, false, {} ] } },
{ target: 'all', data: new Blob([123], { type: 'plain/text' }) },
{ target: 'all', data: new ImageData(2, 2) },
];
function create_fileList() {
var url = SimpleTest.getTestFileURL("script_postmessages_fileList.js");
var script = SpecialPowers.loadChromeScript(url);
function onOpened(message) {
var fileList = document.getElementById('fileList');
SpecialPowers.wrap(fileList).mozSetFileArray([message.file]);
// Just a simple test
var domFile = fileList.files[0];
is(domFile.name, "prefs.js", "fileName should be prefs.js");
clonableObjects.push({ target: 'all', data: fileList.files });
script.destroy();
next();
}
script.addMessageListener("file.opened", onOpened);
script.sendAsyncMessage("file.open");
}
function create_directory() {
if (navigator.userAgent.toLowerCase().includes('Android')) {
next();
return;
}
var url = SimpleTest.getTestFileURL("script_postmessages_fileList.js");
var script = SpecialPowers.loadChromeScript(url);
function onOpened(message) {
var fileList = document.getElementById('fileList');
SpecialPowers.wrap(fileList).mozSetDirectory(message.dir);
fileList.getFilesAndDirectories().then(function(list) {
// Just a simple test
is(list.length, 1, "This list has 1 element");
ok(list[0] instanceof Directory, "We have a directory.");
clonableObjects.push({ target: 'all', data: list[0] });
script.destroy();
next();
});
}
script.addMessageListener("dir.opened", onOpened);
script.sendAsyncMessage("dir.open");
}
function create_wasmModule() {
info("Checking if we can play with WebAssembly...");
if (!SpecialPowers.Cu.getJSTestingFunctions().wasmIsSupported()) {
next();
return;
}
ok(WebAssembly, "WebAssembly object should exist");
ok(WebAssembly.compile, "WebAssembly.compile function should exist");
const wasmTextToBinary = SpecialPowers.unwrap(SpecialPowers.Cu.getJSTestingFunctions().wasmTextToBinary);
const fooModuleCode = wasmTextToBinary(`(module
(func $foo (result i32) (i32.const 42))
(export "foo" $foo)
)`);
WebAssembly.compile(fooModuleCode).then((m) => {
ok(m instanceof WebAssembly.Module, "The WasmModule has been compiled.");
clonableObjects.push({ target: 'sameProcess', data: m });
next();
}, () => {
ok(false, "The compilation of the wasmModule failed.");
});
}
function runTests(obj) {
ok(('clonableObjectsEveryWhere' in obj) &&
('clonableObjectsSameProcess' in obj) &&
('transferableObjects' in obj) &&
(obj.clonableObjectsEveryWhere || obj.clonableObjectsSameProcess || obj.transferableObjects), "We must run some test!");
// cloning tests - everyWhere
new Promise(function(resolve, reject) {
var clonableObjectsId = 0;
function runClonableTest() {
if (clonableObjectsId >= clonableObjects.length) {
resolve();
return;
}
var object = clonableObjects[clonableObjectsId++];
if (object.target != 'all') {
runClonableTest();
return;
}
obj.send(object.data, []).then(function(received) {
if (!obj.clonableObjectsEveryWhere) {
ok(received.error, "Error expected");
} else {
ok(!received.error, "Error not expected");
compare(received.data, object.data);
}
runClonableTest();
});
}
runClonableTest();
})
// clonable same process
.then(function() {
return new Promise(function(resolve, reject) {
var clonableObjectsId = 0;
function runClonableTest() {
if (clonableObjectsId >= clonableObjects.length) {
resolve();
return;
}
var object = clonableObjects[clonableObjectsId++];
if (object.target != 'sameProcess') {
runClonableTest();
return;
}
obj.send(object.data, []).then(function(received) {
if (!obj.clonableObjectsSameProcess) {
ok(received.error, "Error expected");
} else {
ok(!received.error, "Error not expected");
compare(received.data, object.data);
}
runClonableTest();
});
}
runClonableTest();
});
})
// transfering tests
.then(function() {
if (!obj.transferableObjects) {
return;
}
// MessagePort
return new Promise(function(r, rr) {
var mc = new MessageChannel();
obj.send(42, [mc.port1]).then(function(received) {
is(received.ports.length, 1, "MessagePort has been transferred");
mc.port2.postMessage("hello world");
received.ports[0].onmessage = function(e) {
is(e.data, "hello world", "Ports are connected!");
r();
}
});
});
})
// no dup transfering
.then(function() {
if (!obj.transferableObjects) {
return;
}
// MessagePort
return new Promise(function(r, rr) {
var mc = new MessageChannel();
obj.send(42, [mc.port1, mc.port1]).then(function(received) {
ok(false, "Duplicate ports should throw!");
}, function() {
ok(true, "Duplicate ports should throw!");
})
.then(r);
});
})
// non transfering tests
.then(function() {
if (obj.transferableObjects) {
return;
}
// MessagePort
return new Promise(function(r, rr) {
var mc = new MessageChannel();
obj.send(42, [mc.port1]).then(function(received) {
ok(false, "This object should not support port transferring");
}, function() {
ok(true, "This object should not support port transferring");
})
.then(r);
});
})
// done.
.then(function() {
obj.finished();
});
}
// PostMessage to the same window.
function test_windowToWindow() {
info("Testing window to window");
var resolve;
function resolvePromise(data) {
if (!resolve) {
ok(false, "Unexpected message!");
return;
}
let tmp = resolve;
resolve = null;
tmp(data);
}
onmessage = function(e) {
resolvePromise({ data: e.data, ports: e.ports, error: false });
}
onmessageerror = function(e) {
resolvePromise({ error: true });
}
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess: true,
transferableObjects: true,
send(what, ports) {
return new Promise(function(r, rr) {
resolve = r;
try {
postMessage(what, '*', ports);
} catch(e) {
resolve = null;
rr();
}
});
},
finished() {
onmessage = null;
onmessageerror = null;
next();
}
});
}
// PostMessage to iframe
function test_windowToIframe() {
info("Testing window to iframe");
test_windowToIframeURL('iframe_postMessages.html', true);
}
// PostMessage to cross-origin iframe
function test_windowToCrossOriginIframe() {
info("Testing window to cross-origin iframe");
test_windowToIframeURL('http://example.com/tests/dom/base/test/iframe_postMessages.html', false);
}
// iframe helper class
function test_windowToIframeURL(url, clonableObjectsSameProcess) {
var resolve;
onmessage = function(e) {
if (!resolve) {
ok(false, "Unexpected message!");
return;
}
let tmp = resolve;
resolve = null;
tmp({ data: e.data, ports: e.ports, error: e.data === "error" });
}
var ifr = document.createElement('iframe');
ifr.src = url;
ifr.onload = function() {
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess,
transferableObjects: true,
send(what, ports) {
return new Promise(function(r, rr) {
resolve = r;
try {
ifr.contentWindow.postMessage(what, '*', ports);
} catch(e) {
resolve = null;
rr();
}
});
},
finished() {
document.body.removeChild(ifr);
onmessage = null;
next();
}
});
}
document.body.appendChild(ifr);
}
// PostMessage for Workers
function test_workers() {
info("Testing Workers");
var resolve;
var w = new Worker('worker_postMessages.js');
w.postMessage('workers');
w.onmessage = function(e) {
is(e.data, 'ok', "Worker ready!");
w.onmessage = function(e1) {
if (!resolve) {
ok(false, "Unexpected message!");
return;
}
let tmp = resolve;
resolve = null;
tmp({ data: e1.data, ports: e1.ports, error: e1.data === "error" });
}
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess: true,
transferableObjects: true,
send(what, ports) {
return new Promise(function(r, rr) {
resolve = r;
try {
w.postMessage(what, ports);
} catch(ex) {
resolve = null;
rr();
}
});
},
finished() {
w.terminate();
next();
}
});
}
}
// PostMessage for SharedWorkers
function test_sharedWorkers() {
info("Testing SharedWorkers");
var resolve;
var w = new SharedWorker('worker_postMessages.js');
w.port.postMessage('sharedworkers');
w.port.onmessage = function(e) {
is(e.data, 'ok', "Worker ready!");
w.port.onmessage = function(e1) {
if (!resolve) {
ok(false, "Unexpected message!");
return;
}
let tmp = resolve;
resolve = null;
tmp({ data: e1.data, ports: e1.ports, error: e1.data === "error" });
}
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess: false,
transferableObjects: true,
send(what, ports) {
return new Promise(function(r, rr) {
resolve = r;
try {
w.port.postMessage(what, ports);
} catch(ex) {
resolve = null;
rr();
}
});
},
finished() {
w.port.postMessage("terminate");
next();
}
});
}
}
// PostMessage for BroadcastChannel
function test_broadcastChannel() {
info("Testing broadcastChannel");
var bc1 = new BroadcastChannel('postMessagesTest');
var bc2 = new BroadcastChannel('postMessagesTest');
var resolve;
function resolvePromise(data) {
if (!resolve) {
ok(false, "Unexpected message!");
return;
}
let tmp = resolve;
resolve = null;
tmp(data);
}
bc2.onmessage = function(e) {
resolvePromise({ data: e.data, ports: [], error: false });
}
bc2.onmessageerror = function(e) {
resolvePromise({ error: true });
}
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess: true,
transferableObjects: false,
send(what, ports) {
return new Promise(function(r, rr) {
if (ports.length) {
rr();
return;
}
resolve = r;
bc1.postMessage(what);
});
},
finished() {
bc1.close();
bc2.close();
next();
}
});
}
// PostMessage for BroadcastChannel in workers
function test_broadcastChannel_inWorkers() {
info("Testing broadcastChannel in Workers");
var bc = new BroadcastChannel('postMessagesTest_inWorkers');
var resolve;
var w = new Worker('worker_postMessages.js');
w.postMessage('broadcastChannel');
w.onmessage = function(e) {
is(e.data, 'ok', "Worker ready!");
w.onmessage = function(e1) {
if (!resolve) {
ok(false, "Unexpected message!");
return;
}
let tmp = resolve;
resolve = null;
tmp({ data: e1.data, ports: e1.ports, error: e1.data === "error" });
}
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess: true,
transferableObjects: false,
send(what, ports) {
return new Promise(function(r, rr) {
if (ports.length) {
rr();
return;
}
resolve = r;
bc.postMessage(what);
});
},
finished() {
bc.close();
w.terminate();
next();
}
});
}
}
// PostMessage for BroadcastChannel in SharedWorkers
function test_broadcastChannel_inSharedWorkers() {
info("Testing broadcastChannel in SharedWorkers");
var bc = new BroadcastChannel('postMessagesTest_inWorkers');
var resolve;
var w = new SharedWorker('worker_postMessages.js');
w.port.postMessage('broadcastChannel');
w.port.onmessage = function(e) {
is(e.data, 'ok', "Worker ready!");
w.port.onmessage = function(e1) {
if (!resolve) {
ok(false, "Unexpected message!");
return;
}
let tmp = resolve;
resolve = null;
tmp({ data: e1.data, ports: e1.ports, error: e1.data === "error" });
}
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess: false,
transferableObjects: false,
send(what, ports) {
return new Promise(function(r, rr) {
if (ports.length) {
rr();
return;
}
resolve = r;
bc.postMessage(what);
});
},
finished() {
bc.close();
w.port.postMessage("terminate");
next();
}
});
}
}
// PostMessage for MessagePort
function test_messagePort() {
info("Testing messagePort");
var mc = new MessageChannel();
var resolve;
function resolvePromise(data) {
if (!resolve) {
ok(false, "Unexpected message!");
return;
}
let tmp = resolve;
resolve = null;
tmp(data);
}
mc.port2.onmessage = function(e) {
resolvePromise({ data: e.data, ports: e.ports, error: false });
}
mc.port2.onmessageerror = function(e) {
resolvePromise({ error: true });
}
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess: true,
transferableObjects: true,
send(what, ports) {
return new Promise(function(r, rr) {
resolve = r;
try {
mc.port1.postMessage(what, ports);
} catch(e) {
resolve = null;
rr();
}
});
},
finished() {
next();
}
});
}
// PostMessage for MessagePort in Workers
function test_messagePort_inWorkers() {
info("Testing messagePort in workers");
var mc = new MessageChannel();
var resolve;
var w = new Worker('worker_postMessages.js');
w.postMessage('messagePort', [ mc.port2 ]);
w.onmessage = function(e) {
is(e.data, 'ok', "Worker ready!");
w.onmessage = function(e1) {
if (!resolve) {
ok(false, "Unexpected message!");
return;
}
let tmp = resolve;
resolve = null;
tmp({ data: e1.data, ports: e1.ports, error: e1.data === "error" });
}
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess: true,
transferableObjects: true,
send(what, ports) {
return new Promise(function(r, rr) {
resolve = r;
try {
mc.port1.postMessage(what, ports);
} catch(ex) {
resolve = null;
rr();
}
});
},
finished() {
w.terminate();
next();
}
});
}
}
var tests = [
setup_tests,
create_fileList,
create_directory,
create_wasmModule,
test_windowToWindow,
test_windowToIframe,
test_windowToCrossOriginIframe,
test_workers,
test_sharedWorkers,
test_broadcastChannel,
test_broadcastChannel_inWorkers,
test_broadcastChannel_inSharedWorkers,
test_messagePort,
test_messagePort_inWorkers,
];
function next() {
if (!tests.length) {
SimpleTest.finish();
return;
}
var test = tests.shift();
test();
}
SimpleTest.waitForExplicitFinish();
next();
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,167 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for postMessages cloning/transferring objects</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script src="common_postMessages.js"></script>
</head>
<body>
<input id="fileList" type="file"></input>
<script type="application/javascript">
// PostMessage for BroadcastChannel
tests.push(function test_broadcastChannel() {
info("Testing broadcastChannel");
var bc1 = new BroadcastChannel('postMessagesTest');
var bc2 = new BroadcastChannel('postMessagesTest');
var resolve;
function resolvePromise(data) {
if (!resolve) {
ok(false, "Unexpected message!");
return;
}
let tmp = resolve;
resolve = null;
tmp(data);
}
bc2.onmessage = function(e) {
resolvePromise({ data: e.data, ports: [], error: false });
}
bc2.onmessageerror = function(e) {
resolvePromise({ error: true });
}
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess: true,
transferableObjects: false,
send(what, ports) {
return new Promise(function(r, rr) {
if (ports.length) {
rr();
return;
}
resolve = r;
bc1.postMessage(what);
});
},
finished() {
bc1.close();
bc2.close();
next();
}
});
});
// PostMessage for BroadcastChannel in workers
tests.push(function test_broadcastChannel_inWorkers() {
info("Testing broadcastChannel in Workers");
var bc = new BroadcastChannel('postMessagesTest_inWorkers');
var resolve;
var w = new Worker('worker_postMessages.js');
w.postMessage('broadcastChannel');
w.onmessage = function(e) {
is(e.data, 'ok', "Worker ready!");
w.onmessage = function(e1) {
if (!resolve) {
ok(false, "Unexpected message!");
return;
}
let tmp = resolve;
resolve = null;
tmp({ data: e1.data, ports: e1.ports, error: e1.data === "error" });
}
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess: true,
transferableObjects: false,
send(what, ports) {
return new Promise(function(r, rr) {
if (ports.length) {
rr();
return;
}
resolve = r;
bc.postMessage(what);
});
},
finished() {
bc.close();
w.terminate();
next();
}
});
}
});
// PostMessage for BroadcastChannel in SharedWorkers
tests.push(function test_broadcastChannel_inSharedWorkers() {
info("Testing broadcastChannel in SharedWorkers");
var bc = new BroadcastChannel('postMessagesTest_inWorkers');
var resolve;
var w = new SharedWorker('worker_postMessages.js');
w.port.postMessage('broadcastChannel');
w.port.onmessage = function(e) {
is(e.data, 'ok', "Worker ready!");
w.port.onmessage = function(e1) {
if (!resolve) {
ok(false, "Unexpected message!");
return;
}
let tmp = resolve;
resolve = null;
tmp({ data: e1.data, ports: e1.ports, error: e1.data === "error" });
}
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess: false,
transferableObjects: false,
send(what, ports) {
return new Promise(function(r, rr) {
if (ports.length) {
rr();
return;
}
resolve = r;
bc.postMessage(what);
});
},
finished() {
bc.close();
w.port.postMessage("terminate");
next();
}
});
}
});
SimpleTest.waitForExplicitFinish();
next();
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,114 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for postMessages cloning/transferring objects</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script src="common_postMessages.js"></script>
</head>
<body>
<input id="fileList" type="file"></input>
<script type="application/javascript">
// PostMessage for MessagePort
tests.push(function test_messagePort() {
info("Testing messagePort");
var mc = new MessageChannel();
var resolve;
function resolvePromise(data) {
if (!resolve) {
ok(false, "Unexpected message!");
return;
}
let tmp = resolve;
resolve = null;
tmp(data);
}
mc.port2.onmessage = function(e) {
resolvePromise({ data: e.data, ports: e.ports, error: false });
}
mc.port2.onmessageerror = function(e) {
resolvePromise({ error: true });
}
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess: true,
transferableObjects: true,
send(what, ports) {
return new Promise(function(r, rr) {
resolve = r;
try {
mc.port1.postMessage(what, ports);
} catch(e) {
resolve = null;
rr();
}
});
},
finished() {
next();
}
});
});
// PostMessage for MessagePort in Workers
tests.push(function test_messagePort_inWorkers() {
info("Testing messagePort in workers");
var mc = new MessageChannel();
var resolve;
var w = new Worker('worker_postMessages.js');
w.postMessage('messagePort', [ mc.port2 ]);
w.onmessage = function(e) {
is(e.data, 'ok', "Worker ready!");
w.onmessage = function(e1) {
if (!resolve) {
ok(false, "Unexpected message!");
return;
}
let tmp = resolve;
resolve = null;
tmp({ data: e1.data, ports: e1.ports, error: e1.data === "error" });
}
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess: true,
transferableObjects: true,
send(what, ports) {
return new Promise(function(r, rr) {
resolve = r;
try {
mc.port1.postMessage(what, ports);
} catch(ex) {
resolve = null;
rr();
}
});
},
finished() {
w.terminate();
next();
}
});
}
});
SimpleTest.waitForExplicitFinish();
next();
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,124 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for postMessages cloning/transferring objects</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script src="common_postMessages.js"></script>
</head>
<body>
<input id="fileList" type="file"></input>
<script type="application/javascript">
// PostMessage to the same window.
tests.push(function test_windowToWindow() {
info("Testing window to window");
var resolve;
function resolvePromise(data) {
if (!resolve) {
ok(false, "Unexpected message!");
return;
}
let tmp = resolve;
resolve = null;
tmp(data);
}
onmessage = function(e) {
resolvePromise({ data: e.data, ports: e.ports, error: false });
}
onmessageerror = function(e) {
resolvePromise({ error: true });
}
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess: true,
transferableObjects: true,
send(what, ports) {
return new Promise(function(r, rr) {
resolve = r;
try {
postMessage(what, '*', ports);
} catch(e) {
resolve = null;
rr();
}
});
},
finished() {
onmessage = null;
onmessageerror = null;
next();
}
});
});
// iframe helper class
function test_windowToIframeURL(url, clonableObjectsSameProcess) {
var resolve;
onmessage = function(e) {
if (!resolve) {
ok(false, "Unexpected message!");
return;
}
let tmp = resolve;
resolve = null;
tmp({ data: e.data, ports: e.ports, error: e.data === "error" });
}
var ifr = document.createElement('iframe');
ifr.src = url;
ifr.onload = function() {
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess,
transferableObjects: true,
send(what, ports) {
return new Promise(function(r, rr) {
resolve = r;
try {
ifr.contentWindow.postMessage(what, '*', ports);
} catch(e) {
resolve = null;
rr();
}
});
},
finished() {
document.body.removeChild(ifr);
onmessage = null;
next();
}
});
}
document.body.appendChild(ifr);
}
// PostMessage to iframe
tests.push(function test_windowToIframe() {
info("Testing window to iframe");
test_windowToIframeURL('iframe_postMessages.html', true);
});
// PostMessage to cross-origin iframe
tests.push(function test_windowToCrossOriginIframe() {
info("Testing window to cross-origin iframe");
test_windowToIframeURL('http://example.com/tests/dom/base/test/iframe_postMessages.html', false);
});
SimpleTest.waitForExplicitFinish();
next();
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,111 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for postMessages cloning/transferring objects</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script src="common_postMessages.js"></script>
</head>
<body>
<input id="fileList" type="file"></input>
<script type="application/javascript">
// PostMessage for Workers
tests.push(function test_workers() {
info("Testing Workers");
var resolve;
var w = new Worker('worker_postMessages.js');
w.postMessage('workers');
w.onmessage = function(e) {
is(e.data, 'ok', "Worker ready!");
w.onmessage = function(e1) {
if (!resolve) {
ok(false, "Unexpected message!");
return;
}
let tmp = resolve;
resolve = null;
tmp({ data: e1.data, ports: e1.ports, error: e1.data === "error" });
}
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess: true,
transferableObjects: true,
send(what, ports) {
return new Promise(function(r, rr) {
resolve = r;
try {
w.postMessage(what, ports);
} catch(ex) {
resolve = null;
rr();
}
});
},
finished() {
w.terminate();
next();
}
});
}
});
// PostMessage for SharedWorkers
tests.push(function test_sharedWorkers() {
info("Testing SharedWorkers");
var resolve;
var w = new SharedWorker('worker_postMessages.js');
w.port.postMessage('sharedworkers');
w.port.onmessage = function(e) {
is(e.data, 'ok', "Worker ready!");
w.port.onmessage = function(e1) {
if (!resolve) {
ok(false, "Unexpected message!");
return;
}
let tmp = resolve;
resolve = null;
tmp({ data: e1.data, ports: e1.ports, error: e1.data === "error" });
}
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess: false,
transferableObjects: true,
send(what, ports) {
return new Promise(function(r, rr) {
resolve = r;
try {
w.port.postMessage(what, ports);
} catch(ex) {
resolve = null;
rr();
}
});
},
finished() {
w.port.postMessage("terminate");
next();
}
});
}
});
SimpleTest.waitForExplicitFinish();
next();
</script>
</body>
</html>