summaryrefslogtreecommitdiffstats
path: root/dom/worklet/tests
diff options
context:
space:
mode:
Diffstat (limited to 'dom/worklet/tests')
-rw-r--r--dom/worklet/tests/common.js14
-rw-r--r--dom/worklet/tests/file_basic.html57
-rw-r--r--dom/worklet/tests/file_console.html19
-rw-r--r--dom/worklet/tests/file_dump.html22
-rw-r--r--dom/worklet/tests/file_import_with_cache.html43
-rw-r--r--dom/worklet/tests/mochitest.ini13
-rw-r--r--dom/worklet/tests/server_import_with_cache.sjs13
-rw-r--r--dom/worklet/tests/test_basic.html21
-rw-r--r--dom/worklet/tests/test_console.html42
-rw-r--r--dom/worklet/tests/test_dump.html21
-rw-r--r--dom/worklet/tests/test_import_with_cache.html21
-rw-r--r--dom/worklet/tests/worklet_console.js1
-rw-r--r--dom/worklet/tests/worklet_dump.js1
13 files changed, 288 insertions, 0 deletions
diff --git a/dom/worklet/tests/common.js b/dom/worklet/tests/common.js
new file mode 100644
index 000000000..9d70f6aa7
--- /dev/null
+++ b/dom/worklet/tests/common.js
@@ -0,0 +1,14 @@
+function loadTest(file) {
+ var iframe = document.createElement('iframe');
+ iframe.src = file;
+
+ document.body.appendChild(iframe);
+}
+
+function setupTest() {
+ window.SimpleTest = parent.SimpleTest;
+ window.is = parent.is;
+ window.isnot = parent.isnot;
+ window.ok = parent.ok;
+ window.info = parent.info;
+}
diff --git a/dom/worklet/tests/file_basic.html b/dom/worklet/tests/file_basic.html
new file mode 100644
index 000000000..ef60ee27f
--- /dev/null
+++ b/dom/worklet/tests/file_basic.html
@@ -0,0 +1,57 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for Worklet</title>
+ <script type="application/javascript" src="common.js"></script>
+</head>
+<body>
+
+<script type="application/javascript">
+
+setupTest();
+
+var worklet = window.createWorklet();
+ok(!!worklet, "We have a Worklet");
+
+// First loading
+worklet.import("common.js")
+.then(() => {
+ ok(true, "Import should load a resource.");
+})
+
+// Second loading - same file
+.then(() => {
+ return worklet.import("common.js")
+})
+.then(() => {
+ ok(true, "Import should load a resource.");
+})
+
+// 3rd loading - a network error
+.then(() => {
+ return worklet.import("404.js");
+})
+.then(() => {
+ ok(false, "The loading should fail.");
+}, () => {
+ ok(true, "The loading should fail.");
+})
+
+// 4th loading - a network error
+.then(() => {
+ return worklet.import("404.js");
+})
+.then(() => {
+ ok(false, "The loading should fail.");
+}, () => {
+ ok(true, "The loading should fail.");
+})
+
+// done
+.then(() => {
+ SimpleTest.finish();
+});
+
+</script>
+</body>
+</html>
diff --git a/dom/worklet/tests/file_console.html b/dom/worklet/tests/file_console.html
new file mode 100644
index 000000000..c4a71e172
--- /dev/null
+++ b/dom/worklet/tests/file_console.html
@@ -0,0 +1,19 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for Worklet</title>
+ <script type="application/javascript" src="common.js"></script>
+</head>
+<body>
+
+<script type="application/javascript">
+
+setupTest();
+
+var worklet = window.createWorklet();
+ok(!!worklet, "We have a Worklet");
+worklet.import("worklet_console.js");
+
+</script>
+</body>
+</html>
diff --git a/dom/worklet/tests/file_dump.html b/dom/worklet/tests/file_dump.html
new file mode 100644
index 000000000..123a625a9
--- /dev/null
+++ b/dom/worklet/tests/file_dump.html
@@ -0,0 +1,22 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for Worklet</title>
+ <script type="application/javascript" src="common.js"></script>
+</head>
+<body>
+
+<script type="application/javascript">
+
+setupTest();
+
+var worklet = window.createWorklet();
+ok(!!worklet, "We have a Worklet");
+worklet.import("worklet_dump.js")
+.then(() => {
+ SimpleTest.finish();
+});
+
+</script>
+</body>
+</html>
diff --git a/dom/worklet/tests/file_import_with_cache.html b/dom/worklet/tests/file_import_with_cache.html
new file mode 100644
index 000000000..e98818d6f
--- /dev/null
+++ b/dom/worklet/tests/file_import_with_cache.html
@@ -0,0 +1,43 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for Worklet</title>
+ <script type="application/javascript" src="common.js"></script>
+</head>
+<body>
+
+<script type="application/javascript">
+
+setupTest();
+
+var worklet = window.createWorklet();
+ok(!!worklet, "We have a Worklet");
+
+function loading() {
+ worklet.import("server_import_with_cache.sjs")
+ .then(() => {
+ ok(true, "Import should load a resource.");
+ }, () => {
+ ok(false, "Import should load a resource.");
+ })
+ .then(() => {
+ done();
+ });
+}
+
+var count = 0;
+const MAX = 10;
+
+function done() {
+ if (++count == MAX) {
+ SimpleTest.finish();
+ }
+}
+
+for (var i = 0; i < MAX; ++i) {
+ loading();
+}
+
+</script>
+</body>
+</html>
diff --git a/dom/worklet/tests/mochitest.ini b/dom/worklet/tests/mochitest.ini
new file mode 100644
index 000000000..2194361cc
--- /dev/null
+++ b/dom/worklet/tests/mochitest.ini
@@ -0,0 +1,13 @@
+[DEFAULT]
+skip-if = release_or_beta
+support-files =
+ common.js
+
+[test_basic.html]
+support-files=file_basic.html
+[test_console.html]
+support-files=file_console.html worklet_console.js
+[test_import_with_cache.html]
+support-files=file_import_with_cache.html server_import_with_cache.sjs
+[test_dump.html]
+support-files=file_dump.html worklet_dump.js
diff --git a/dom/worklet/tests/server_import_with_cache.sjs b/dom/worklet/tests/server_import_with_cache.sjs
new file mode 100644
index 000000000..79a934dd3
--- /dev/null
+++ b/dom/worklet/tests/server_import_with_cache.sjs
@@ -0,0 +1,13 @@
+function handleRequest(request, response)
+{
+ response.setHeader("Content-Type", "text/javascript", false);
+
+ var state = getState("alreadySent");
+ if (!state) {
+ setState("alreadySent", "1");
+ } else {
+ response.setStatusLine('1.1', 404, "Not Found");
+ }
+
+ response.write("42");
+}
diff --git a/dom/worklet/tests/test_basic.html b/dom/worklet/tests/test_basic.html
new file mode 100644
index 000000000..b3010d1a5
--- /dev/null
+++ b/dom/worklet/tests/test_basic.html
@@ -0,0 +1,21 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for Worklet</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" src="common.js"></script>
+</head>
+<body>
+
+<script type="application/javascript">
+
+SimpleTest.waitForExplicitFinish();
+SpecialPowers.pushPrefEnv(
+ {"set": [["dom.worklet.testing.enabled", true],
+ ["dom.worklet.enabled", true]]},
+ function() { loadTest("file_basic.html"); });
+
+</script>
+</body>
+</html>
diff --git a/dom/worklet/tests/test_console.html b/dom/worklet/tests/test_console.html
new file mode 100644
index 000000000..72a667389
--- /dev/null
+++ b/dom/worklet/tests/test_console.html
@@ -0,0 +1,42 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for Worklet - Console</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" src="common.js"></script>
+</head>
+<body>
+
+<script type="application/javascript">
+
+function consoleListener() {
+ SpecialPowers.addObserver(this, "console-api-log-event", false);
+}
+
+consoleListener.prototype = {
+ observe: function(aSubject, aTopic, aData) {
+ if (aTopic == "console-api-log-event") {
+ var obj = aSubject.wrappedJSObject;
+ if (obj.arguments[0] == "Hello world from a worklet") {
+ ok(true, "Message received \\o/");
+
+ SpecialPowers.removeObserver(this, "console-api-log-event");
+ SimpleTest.finish();
+ return;
+ }
+ }
+ }
+}
+
+var cl = new consoleListener();
+
+SimpleTest.waitForExplicitFinish();
+SpecialPowers.pushPrefEnv(
+ {"set": [["dom.worklet.testing.enabled", true],
+ ["dom.worklet.enabled", true]]},
+ function() { loadTest("file_console.html"); });
+
+</script>
+</body>
+</html>
diff --git a/dom/worklet/tests/test_dump.html b/dom/worklet/tests/test_dump.html
new file mode 100644
index 000000000..011e6d498
--- /dev/null
+++ b/dom/worklet/tests/test_dump.html
@@ -0,0 +1,21 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for Worklet - Console</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" src="common.js"></script>
+</head>
+<body>
+
+<script type="application/javascript">
+
+SimpleTest.waitForExplicitFinish();
+SpecialPowers.pushPrefEnv(
+ {"set": [["dom.worklet.testing.enabled", true],
+ ["dom.worklet.enabled", true]]},
+ function() { loadTest("file_dump.html"); });
+
+</script>
+</body>
+</html>
diff --git a/dom/worklet/tests/test_import_with_cache.html b/dom/worklet/tests/test_import_with_cache.html
new file mode 100644
index 000000000..316f914eb
--- /dev/null
+++ b/dom/worklet/tests/test_import_with_cache.html
@@ -0,0 +1,21 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for Worklet</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" src="common.js"></script>
+</head>
+<body>
+
+<script type="application/javascript">
+
+SimpleTest.waitForExplicitFinish();
+SpecialPowers.pushPrefEnv(
+ {"set": [["dom.worklet.testing.enabled", true],
+ ["dom.worklet.enabled", true]]},
+ function() { loadTest("file_import_with_cache.html"); });
+
+</script>
+</body>
+</html>
diff --git a/dom/worklet/tests/worklet_console.js b/dom/worklet/tests/worklet_console.js
new file mode 100644
index 000000000..557beb1af
--- /dev/null
+++ b/dom/worklet/tests/worklet_console.js
@@ -0,0 +1 @@
+console.log("Hello world from a worklet");
diff --git a/dom/worklet/tests/worklet_dump.js b/dom/worklet/tests/worklet_dump.js
new file mode 100644
index 000000000..439d13f70
--- /dev/null
+++ b/dom/worklet/tests/worklet_dump.js
@@ -0,0 +1 @@
+dump("Hello world from a worklet");