Permalink
Browse files

Add optimpl tests

  • Loading branch information...
nmaier committed May 20, 2012
1 parent 407884e commit 41d289cb919fdd020e75ca08ca94d0d60f651673
@@ -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);
@@ -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);
@@ -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");
View
@@ -16,8 +16,9 @@
<script src="support/testAlertservice.js"></script>
<script src="support/testAtoms.js"></script>
<script src="support/testBatchgen.js"></script>
- <script src="support/testFileextsheet.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/testPBM.js"></script>
<script src="support/testTextLinks.js"></script>
@@ -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.