Bug 1245768 - Implement a test for the correct error management when worker imports 3rd party scripts, r=bz

This commit is contained in:
Andrea Marchesini 2016-02-04 15:35:16 +00:00
Родитель 5b55c70961
Коммит 21900562cd
3 изменённых файлов: 214 добавлений и 0 удалений

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

@ -0,0 +1,78 @@
const workerURL = 'http://mochi.test:8888/tests/dom/workers/test/importScripts_3rdParty_worker.js';
onmessage = function(a) {
if (a.data.nested) {
var worker = new Worker(workerURL);
worker.onmessage = function(event) {
postMessage(event.data);
}
worker.onerror = function(event) {
event.preventDefault();
postMessage({ error: event instanceof ErrorEvent &&
event.filename == workerURL });
}
a.data.nested = false;
worker.postMessage(a.data);
return;
}
// This first URL will use the same origin of this script.
var sameOriginURL = new URL(a.data.url);
var fileName1 = 42;
// This is cross-origin URL.
var crossOriginURL = new URL(a.data.url);
crossOriginURL.host = 'example.com';
crossOriginURL.port = 80;
var fileName2 = 42;
if (a.data.test == 'none') {
importScripts([crossOriginURL.href]);
return;
}
try {
importScripts([sameOriginURL.href]);
} catch(e) {
if (!(e instanceof SyntaxError)) {
postMessage({ result: false });
return;
}
fileName1 = e.fileName;
}
if (fileName1 != sameOriginURL.href || !fileName1) {
postMessage({ result: false });
return;
}
if (a.data.test == 'try') {
try {
importScripts([crossOriginURL.href]);
} catch(e) {
fileName2 = e.filename;
}
postMessage({ result: fileName2 == workerURL });
return;
}
if (a.data.test == 'eventListener') {
addEventListener("error", function(event) {
event.preventDefault();
postMessage({result: event instanceof ErrorEvent &&
event.filename == workerURL });
});
}
if (a.data.test == 'onerror') {
onerror = function(...args) {
postMessage({result: args[1] == workerURL });
}
}
importScripts([crossOriginURL.href]);
}

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

@ -121,6 +121,7 @@ support-files =
websocket_https_worker.js
worker_fileReader.js
fileapi_chromeScript.js
importScripts_3rdParty_worker.js
[test_404.html]
[test_atob.html]
@ -237,6 +238,7 @@ skip-if = buildapp == 'b2g'
skip-if = (os == "win") || (os == "mac") || toolkit == 'android' #bug 798220
[test_xhrAbort.html]
[test_referrer.html]
[test_importScripts_3rdparty.html]
[test_sharedWorker_ports.html]
[test_sharedWorker_lifetime.html]
[test_fileReader.html]

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

@ -0,0 +1,134 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Test for 3rd party imported script and muted errors</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script type="text/javascript">
const workerURL = 'http://mochi.test:8888/tests/dom/workers/test/importScripts_3rdParty_worker.js';
var tests = [
function() {
var worker = new Worker("importScripts_3rdParty_worker.js");
worker.onmessage = function(event) {
ok("result" in event.data && event.data.result, "It seems we don't share data!");
next();
};
worker.postMessage({ url: location.href, test: 'try', nested: false });
},
function() {
var worker = new Worker("importScripts_3rdParty_worker.js");
worker.onmessage = function(event) {
ok("result" in event.data && event.data.result, "It seems we don't share data in nested workers!");
next();
};
worker.postMessage({ url: location.href, test: 'try', nested: true });
},
function() {
var worker = new Worker("importScripts_3rdParty_worker.js");
worker.onmessage = function(event) {
ok("result" in event.data && event.data.result, "It seems we don't share data via eventListener!");
next();
};
worker.postMessage({ url: location.href, test: 'eventListener', nested: false });
},
function() {
var worker = new Worker("importScripts_3rdParty_worker.js");
worker.onmessage = function(event) {
ok("result" in event.data && event.data.result, "It seems we don't share data in nested workers via eventListener!");
next();
};
worker.postMessage({ url: location.href, test: 'eventListener', nested: true });
},
function() {
var worker = new Worker("importScripts_3rdParty_worker.js");
worker.onmessage = function(event) {
ok("result" in event.data && event.data.result, "It seems we don't share data via onerror!");
next();
};
worker.onerror = function(event) {
event.preventDefault();
}
worker.postMessage({ url: location.href, test: 'onerror', nested: false });
},
function() {
var worker = new Worker("importScripts_3rdParty_worker.js");
worker.onerror = function(event) {
event.preventDefault();
ok(event instanceof ErrorEvent, "ErrorEvent received.");
is(event.filename, workerURL, "ErrorEvent.filename is correct");
next();
};
worker.postMessage({ url: location.href, test: 'none', nested: false });
},
function() {
var worker = new Worker("importScripts_3rdParty_worker.js");
worker.addEventListener("error", function(event) {
event.preventDefault();
ok(event instanceof ErrorEvent, "ErrorEvent received.");
is(event.filename, workerURL, "ErrorEvent.filename is correct");
next();
});
worker.postMessage({ url: location.href, test: 'none', nested: false });
},
function() {
var worker = new Worker("importScripts_3rdParty_worker.js");
worker.onerror = function(event) {
ok(false, "No error should be received!");
};
worker.onmessage = function(event) {
ok("error" in event.data && event.data.error, "The error has been fully received from a nested worker");
next();
};
worker.postMessage({ url: location.href, test: 'none', nested: true });
},
function() {
var url = URL.createObjectURL(new Blob(["%&%^&%^"]));
var worker = new Worker(url);
worker.onerror = function(event) {
event.preventDefault();
ok(event instanceof ErrorEvent, "ErrorEvent received.");
next();
};
}
];
function next() {
if (!tests.length) {
SimpleTest.finish();
return;
}
var test = tests.shift();
test();
}
SimpleTest.waitForExplicitFinish();
next();
</script>
</body>
</html>