gecko-dev/dom/workers/test/test_bug1241485.html
Olli Pettay d6444f776f Bug 1241485 - Increase the limit for workers per-origin, r=khuey
--HG--
extra : rebase_source : cff8b7973ceffe97e56d49adeeac13b040279a50
2016-01-27 02:45:22 +02:00

83 lines
2.2 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1241485
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1241485</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 1241485 **/
SimpleTest.waitForExplicitFinish();
SimpleTest.requestCompleteLog();
SimpleTest.requestFlakyTimeout("requestFlakyTimeout is silly.");
var limit = SpecialPowers.Services.prefs.getIntPref("dom.workers.maxPerDomain");
var workers = new Array();
var workerToWait = null;
var url = URL.createObjectURL(new Blob(["postMessage('loaded');"]));
var timeouts = new Array();
function addTimeout(fn, time) {
timeouts.push(setTimeout(fn, time));
}
function createWorker() {
workerToWait = new Worker(url);
workerToWait.onmessage = function(e) {
if (!workers) {
// finish() has been called already.
return;
}
workers.push(workerToWait);
info(workers.length + " workers");
addTimeout(createWorker, 0);
if (workers.length == limit) {
// Just give the worker creation loop some more time to try to
// create more workers to check that we don't go over the limit.
addTimeout(finish, 250);
}
};
}
function test() {
info("Expecting no more than " + limit + " workers.");
// Make sure we finish at some point, even if creating workers takes
// lots of time.
addTimeout(finish, 10000);
addTimeout(createWorker, 0);
}
function finish() {
for (var i = 0; i < timeouts.length; ++i) {
clearTimeout(timeouts[i]);
}
if (workerToWait) {
workerToWait.onmessage = null;
}
ok(workers.length <= limit, "Too many workers created!");
workers = null;
SpecialPowers.gc();
SimpleTest.finish();
}
</script>
</head>
<body onload="test();">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1241485">Mozilla Bug 1241485</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>