Skip to content

Commit

Permalink
Add optimpl tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nmaier committed May 20, 2012
1 parent 407884e commit 41d289c
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 1 deletion.
16 changes: 16 additions & 0 deletions modules/testsupport/worker.js
@@ -0,0 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/ */

"use strict";
onmessage = function(event) {
let data = event.data;
if (data == "close") {
close();
return;
}
data.result = "worker";
postMessage(data);
}

postMessage(false);
16 changes: 16 additions & 0 deletions modules/testsupport/workerFail.js
@@ -0,0 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/ */

"use strict";
onmessage = function(event) {
let data = event.data;
if (data == "close") {
close();
return;
}
data.result = "worker";
postMessage(data);
}

postMessage(true);
7 changes: 7 additions & 0 deletions modules/testsupport/workerThrow.js
@@ -0,0 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/ */

"use strict";

throw new Error("throws");
3 changes: 2 additions & 1 deletion tests/index.html
Expand Up @@ -16,8 +16,9 @@
<script src="support/testAlertservice.js"></script> <script src="support/testAlertservice.js"></script>
<script src="support/testAtoms.js"></script> <script src="support/testAtoms.js"></script>
<script src="support/testBatchgen.js"></script> <script src="support/testBatchgen.js"></script>
<script src="support/testFileextsheet.js"></script>
<script src="support/testDefer.js"></script> <script src="support/testDefer.js"></script>
<script src="support/testFileextsheet.js"></script>
<script src="support/testOptimpl.js"></script>
<script src="support/testHistoryManager.js"></script> <script src="support/testHistoryManager.js"></script>
<script src="support/testPBM.js"></script> <script src="support/testPBM.js"></script>
<script src="support/testTextLinks.js"></script> <script src="support/testTextLinks.js"></script>
Expand Down
61 changes: 61 additions & 0 deletions tests/support/testOptimpl.js
@@ -0,0 +1,61 @@
module("support/optimpl.js");

test("exports", function() {
checkExports("support/optimpl", ["NullCancel", "createOptimizedImplementation"]);
});

asyncTest("non-existant", function() {
function cb(result) {
QUnit.start();
strictEqual(result, "non-worker");
};
const {createOptimizedImplementation} = require("support/optimpl");
var impl = createOptimizedImplementation(
"non-existant",
function(impl) function(cb) impl(null, cb),
function() cb("non-worker")
);
setTimeout(function() impl.callImpl(cb), 50);
});

asyncTest("worker", function() {
function cb(result) {
QUnit.start();
strictEqual(result, "worker");
};
const {createOptimizedImplementation} = require("support/optimpl");
var impl = createOptimizedImplementation(
"testsupport/worker",
function(impl) function(cb) impl({}, cb),
function() cb("non-worker")
);
setTimeout(function() impl.callImpl(cb), 50);
});

asyncTest("workerThrow", function() {
function cb(result) {
QUnit.start();
strictEqual(result, "non-worker");
};
const {createOptimizedImplementation} = require("support/optimpl");
var impl = createOptimizedImplementation(
"testsupport/workerThrow",
function(impl) function(cb) impl({}, cb),
function() cb("non-worker")
);
setTimeout(function() impl.callImpl(cb), 50);
});

asyncTest("workerFail", function() {
function cb(result) {
QUnit.start();
strictEqual(result, "non-worker");
};
const {createOptimizedImplementation} = require("support/optimpl");
var impl = createOptimizedImplementation(
"testsupport/workerFail",
function(impl) function(cb) impl({}, cb),
function() cb("non-worker")
);
setTimeout(function() impl.callImpl(cb), 50);
});

0 comments on commit 41d289c

Please sign in to comment.