summaryrefslogtreecommitdiffstats
path: root/testing/mochitest/tests/Harness_sanity
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/mochitest/tests/Harness_sanity
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/mochitest/tests/Harness_sanity')
-rw-r--r--testing/mochitest/tests/Harness_sanity/ImportTesting.jsm5
-rw-r--r--testing/mochitest/tests/Harness_sanity/SpecialPowersLoadChromeScript.js15
-rw-r--r--testing/mochitest/tests/Harness_sanity/empty.js0
-rw-r--r--testing/mochitest/tests/Harness_sanity/file_SpecialPowersFrame1.html14
-rw-r--r--testing/mochitest/tests/Harness_sanity/importtesting_chromescript.js3
-rw-r--r--testing/mochitest/tests/Harness_sanity/mochitest.ini44
-rw-r--r--testing/mochitest/tests/Harness_sanity/specialPowers_framescript.js13
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_SimpletestGetTestFileURL.html20
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_SpecialPowersExtension.html192
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_SpecialPowersExtension2.html21
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadChromeScript.html49
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadChromeScript_function.html67
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadPrivilegedScript.html37
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_SpecialPowersPushPermissions.html237
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_SpecialPowersPushPrefEnv.html211
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_TestsRunningAfterSimpleTestFinish.html23
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_add_task.html38
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_bug649012.html38
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_createFiles.html91
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_importInMainProcess.html54
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_sanity.html63
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_sanityEventUtils.html188
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_sanityException.html15
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_sanityException2.html21
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_sanityParams.html13
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_sanityRegisteredServiceWorker.html24
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_sanityRegisteredServiceWorker2.html25
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_sanitySimpletest.html95
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_sanityWindowSnapshot.html35
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_sanity_cleanup.html30
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_sanity_cleanup2.html24
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_sanity_manifest.html16
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_sanity_manifest_pf.html17
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_sanity_waitForCondition.html53
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_spawn_task.html73
35 files changed, 1864 insertions, 0 deletions
diff --git a/testing/mochitest/tests/Harness_sanity/ImportTesting.jsm b/testing/mochitest/tests/Harness_sanity/ImportTesting.jsm
new file mode 100644
index 000000000..b4d5089ff
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/ImportTesting.jsm
@@ -0,0 +1,5 @@
+this.EXPORTED_SYMBOLS = ["ImportTesting"];
+
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+// Empty module for testing via SpecialPowers.importInMainProcess.
diff --git a/testing/mochitest/tests/Harness_sanity/SpecialPowersLoadChromeScript.js b/testing/mochitest/tests/Harness_sanity/SpecialPowersLoadChromeScript.js
new file mode 100644
index 000000000..731081832
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/SpecialPowersLoadChromeScript.js
@@ -0,0 +1,15 @@
+// Just receive 'foo' message and forward it back
+// as 'bar' message
+addMessageListener("foo", function (message) {
+ sendAsyncMessage("bar", message);
+});
+
+addMessageListener("valid-assert", function (message) {
+ assert.ok(true, "valid assertion");
+ assert.equal(1, 1, "another valid assertion");
+ sendAsyncMessage("valid-assert-done");
+});
+
+addMessageListener("sync-message", () => {
+ return "Received a synchronous message.";
+});
diff --git a/testing/mochitest/tests/Harness_sanity/empty.js b/testing/mochitest/tests/Harness_sanity/empty.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/empty.js
diff --git a/testing/mochitest/tests/Harness_sanity/file_SpecialPowersFrame1.html b/testing/mochitest/tests/Harness_sanity/file_SpecialPowersFrame1.html
new file mode 100644
index 000000000..623460c52
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/file_SpecialPowersFrame1.html
@@ -0,0 +1,14 @@
+<html>
+ <head>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+ </head>
+ <body>
+ <div id="content" style="display: none">
+ <script type="text/javascript">
+ is(SpecialPowers.sanityCheck(), "foo", "Check Special Powers in iframe");
+ </script>
+ </div>
+ </body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/importtesting_chromescript.js b/testing/mochitest/tests/Harness_sanity/importtesting_chromescript.js
new file mode 100644
index 000000000..2c2f9bd55
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/importtesting_chromescript.js
@@ -0,0 +1,3 @@
+addMessageListener("ImportTesting:IsModuleLoaded", function (msg) {
+ sendAsyncMessage("ImportTesting:IsModuleLoadedReply", Components.utils.isModuleLoaded(msg));
+});
diff --git a/testing/mochitest/tests/Harness_sanity/mochitest.ini b/testing/mochitest/tests/Harness_sanity/mochitest.ini
new file mode 100644
index 000000000..e9f744102
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/mochitest.ini
@@ -0,0 +1,44 @@
+[DEFAULT]
+[test_TestsRunningAfterSimpleTestFinish.html]
+skip-if = true #depends on fix for bug 1048446
+[test_add_task.html]
+[test_createFiles.html]
+[test_importInMainProcess.html]
+support-files = importtesting_chromescript.js
+[test_sanity.html]
+[test_sanityException.html]
+[test_sanityException2.html]
+[test_sanityParams.html]
+[test_sanityRegisteredServiceWorker.html]
+support-files = empty.js
+[test_sanityRegisteredServiceWorker2.html]
+support-files = empty.js
+[test_sanityWindowSnapshot.html]
+[test_SpecialPowersExtension.html]
+[test_SpecialPowersExtension2.html]
+support-files = file_SpecialPowersFrame1.html
+[test_SpecialPowersPushPermissions.html]
+support-files =
+ specialPowers_framescript.js
+[test_SpecialPowersPushPrefEnv.html]
+[test_SimpletestGetTestFileURL.html]
+[test_SpecialPowersLoadChromeScript.html]
+support-files = SpecialPowersLoadChromeScript.js
+[test_SpecialPowersLoadChromeScript_function.html]
+[test_SpecialPowersLoadPrivilegedScript.html]
+[test_bug649012.html]
+[test_sanity_cleanup.html]
+[test_sanity_cleanup2.html]
+[test_sanityEventUtils.html]
+skip-if = toolkit == 'android' # bug 688052
+[test_sanitySimpletest.html]
+subsuite = clipboard
+skip-if = toolkit == 'android' # bug 688052
+[test_sanity_manifest.html]
+skip-if = toolkit == 'android' # we use the old manifest style on android
+fail-if = true
+[test_sanity_manifest_pf.html]
+skip-if = toolkit == 'android' # we use the old manifest style on android
+fail-if = true
+[test_spawn_task.html]
+[test_sanity_waitForCondition.html]
diff --git a/testing/mochitest/tests/Harness_sanity/specialPowers_framescript.js b/testing/mochitest/tests/Harness_sanity/specialPowers_framescript.js
new file mode 100644
index 000000000..da1b87782
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/specialPowers_framescript.js
@@ -0,0 +1,13 @@
+Components.utils.import("resource://gre/modules/Services.jsm");
+
+var permChangedObs = {
+ observe: function(subject, topic, data) {
+ if (topic == 'perm-changed') {
+ var permission = subject.QueryInterface(Components.interfaces.nsIPermission);
+ var msg = { op: data, type: permission.type };
+ sendAsyncMessage('perm-changed', msg);
+ }
+ }
+};
+
+Services.obs.addObserver(permChangedObs, 'perm-changed', false);
diff --git a/testing/mochitest/tests/Harness_sanity/test_SimpletestGetTestFileURL.html b/testing/mochitest/tests/Harness_sanity/test_SimpletestGetTestFileURL.html
new file mode 100644
index 000000000..c07d3f7e2
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_SimpletestGetTestFileURL.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for SpecialPowers extension</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+var filename = "MyTestDataFile.txt";
+var url = SimpleTest.getTestFileURL(filename);
+is(url, document.location.href.replace(/test_SimpletestGetTestFileURL\.html.*/, filename));
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_SpecialPowersExtension.html b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersExtension.html
new file mode 100644
index 000000000..299497e15
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersExtension.html
@@ -0,0 +1,192 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for SpecialPowers extension</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body onload="starttest();">
+
+<div id="content" style="display: none">
+ <canvas id="testcanvas" width="200" height="200">
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+var eventCount = 0;
+function testEventListener(e) {
+ ++eventCount;
+}
+
+function testEventListener2(e) {
+ ++eventCount;
+}
+
+function dispatchTestEvent() {
+ var e = document.createEvent("Event");
+ e.initEvent("TestEvent", true, true);
+ window.dispatchEvent(e);
+}
+
+dump("\nSPECIALPTEST:::Test script loaded " + (new Date).getTime() + "\n");
+SimpleTest.waitForExplicitFinish();
+var startTime = new Date();
+function starttest(){
+ dump("\nSPECIALPTEST:::Test script running after load " + (new Date).getTime() + "\n");
+
+ /** Test for SpecialPowers extension **/
+ is(SpecialPowers.sanityCheck(), "foo", "check to see whether the Special Powers extension is installed.");
+
+ // Test a sync call into chrome
+ SpecialPowers.setBoolPref('extensions.checkCompatibility', true);
+ is(SpecialPowers.getBoolPref('extensions.checkCompatibility'), true, "Check to see if we can set a preference properly");
+ SpecialPowers.clearUserPref('extensions.checkCompatibility');
+
+ // Test a int pref
+ SpecialPowers.setIntPref('extensions.foobar', 42);
+ is(SpecialPowers.getIntPref('extensions.foobar'), 42, "Check int pref");
+ SpecialPowers.clearUserPref('extensions.foobar');
+
+ // Test a string pref
+ SpecialPowers.setCharPref("extensions.foobaz", "hi there");
+ is(SpecialPowers.getCharPref("extensions.foobaz"), "hi there", "Check string pref");
+ SpecialPowers.clearUserPref("extensions.foobaz");
+
+ // Test an invalid pref
+ var retVal = null;
+ try {
+ retVal = SpecialPowers.getBoolPref('extensions.checkCompat0123456789');
+ } catch (ex) {
+ retVal = ex;
+ }
+ is(retVal, "Error getting pref 'extensions.checkCompat0123456789'", "received an exception trying to get an unset preference value");
+
+ SpecialPowers.addChromeEventListener("TestEvent", testEventListener, true, true);
+ SpecialPowers.addChromeEventListener("TestEvent", testEventListener2, true, false);
+ dispatchTestEvent();
+ is(eventCount, 1, "Should have got an event!");
+
+ SpecialPowers.removeChromeEventListener("TestEvent", testEventListener, true);
+ SpecialPowers.removeChromeEventListener("TestEvent", testEventListener2, true);
+ dispatchTestEvent();
+ is(eventCount, 1, "Shouldn't have got an event!");
+
+ // Test Complex Pref - TODO: Without chrome access, I don't know how you'd actually
+ // set this preference since you have to create an XPCOM object.
+ // Leaving untested for now.
+
+ // Test a DOMWindowUtils method and property
+ is(SpecialPowers.DOMWindowUtils.getClassName(window), "Proxy");
+ is(SpecialPowers.DOMWindowUtils.docCharsetIsForced, false);
+
+ // QueryInterface and getPrivilegedProps tests
+ is(SpecialPowers.can_QI(SpecialPowers), false);
+ ok(SpecialPowers.can_QI(window));
+ ok(SpecialPowers.do_QueryInterface(window, "nsIDOMWindow"));
+ is(SpecialPowers.getPrivilegedProps(SpecialPowers.do_QueryInterface(window, "nsIDOMWindow"), "document.nodeName"), "#document");
+
+ //try to run garbage collection
+ SpecialPowers.gc();
+
+ //
+ // Test the SpecialPowers wrapper.
+ //
+
+ // Try some basic stuff with XHR.
+ var xhr2 = SpecialPowers.Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(SpecialPowers.Ci.nsIXMLHttpRequest);
+ is(xhr2.readyState, XMLHttpRequest.UNSENT, "Should be able to get props off privileged objects");
+ var testURI = SpecialPowers.Cc['@mozilla.org/network/standard-url;1']
+ .createInstance(SpecialPowers.Ci.nsIURI);
+ testURI.spec = "http://www.foobar.org/";
+ is(testURI.spec, "http://www.foobar.org/", "Getters/Setters should work correctly");
+ is(SpecialPowers.wrap(document).getElementsByTagName('details').length, 0, "Should work with proxy-based DOM bindings.");
+
+ // Play with the window object.
+ var webnav = SpecialPowers.wrap(window).QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
+ .getInterface(SpecialPowers.Ci.nsIWebNavigation);
+ webnav.QueryInterface(SpecialPowers.Ci.nsIDocShell);
+ ok(webnav.allowJavascript, "Able to pull properties off of docshell!");
+
+ // Make sure Xray-wrapped functions work.
+ try {
+ SpecialPowers.wrap(SpecialPowers.Components).ID('{00000000-0000-0000-0000-000000000000}');
+ ok(true, "Didn't throw");
+ }
+ catch (e) {
+ ok(false, "Threw while trying to call Xray-wrapped function.");
+ }
+
+ // Check constructors.
+ var BinaryInputStream = SpecialPowers.wrap(SpecialPowers.Components).Constructor("@mozilla.org/binaryinputstream;1");
+ var bis = new BinaryInputStream();
+ ok(/nsISupports/.exec(bis.toString()), "Should get the proper object out of the constructor");
+ function TestConstructor() {
+ SpecialPowers.wrap(this).foo = 2;
+ }
+ var WrappedConstructor = SpecialPowers.wrap(TestConstructor);
+ is((new WrappedConstructor()).foo, 2, "JS constructors work properly when wrapped");
+
+ // Try messing around with QuickStubbed getters/setters and make sure the wrapper deals.
+ var ctx = SpecialPowers.wrap(document).getElementById('testcanvas').getContext('2d');
+ var pixels = ctx.getImageData(0,0,1,1);
+ try {
+ pixels.data;
+ ok(true, "Didn't throw getting quickstubbed accessor prop from proto");
+ }
+ catch (e) {
+ ok(false, "Threw while getting quickstubbed accessor prop from proto");
+ }
+
+ // Check functions that return null.
+ var returnsNull = function() { return null; }
+ is(SpecialPowers.wrap(returnsNull)(), null, "Should be able to handle functions that return null.");
+
+ // Check a function that throws.
+ var thrower = function() { throw new Error('hah'); }
+ try {
+ SpecialPowers.wrap(thrower)();
+ ok(false, "Should have thrown");
+ } catch (e) {
+ ok(SpecialPowers.isWrapper(e), "Exceptions should be wrapped for call");
+ is(e.message, 'hah', "Correct message");
+ }
+ try {
+ var ctor = SpecialPowers.wrap(thrower);
+ new ctor();
+ ok(false, "Should have thrown");
+ } catch (e) {
+ ok(SpecialPowers.isWrapper(e), "Exceptions should be wrapped for construct");
+ is(e.message, 'hah', "Correct message");
+ }
+
+ // Play around with a JS object to check the non-xray path.
+ var noxray_proto = {a: 3, b: 12};
+ var noxray = {a: 5, c: 32};
+ noxray.__proto__ = noxray_proto;
+ var noxray_wrapper = SpecialPowers.wrap(noxray);
+ is(noxray_wrapper.c, 32, "Regular properties should work.");
+ is(noxray_wrapper.a, 5, "Shadow properties should work.");
+ is(noxray_wrapper.b, 12, "Proto properties should work.");
+ noxray.b = 122;
+ is(noxray_wrapper.b, 122, "Should be able to shadow.");
+
+ // Try setting file input values via an Xray wrapper.
+ SpecialPowers.wrap(document).title = "foo";
+ is(document.title, "foo", "Set property correctly on Xray-wrapped DOM object");
+ is(SpecialPowers.wrap(document).URI, document.URI, "Got property correctly on Xray-wrapped DOM object");
+
+ info("\nProfile::SpecialPowersRunTime: " + (new Date() - startTime) + "\n");
+
+ // bug 855192
+ ok(SpecialPowers.MockPermissionPrompt, "check mock permission prompt");
+
+ // Set a pref using pushPrefEnv to make sure that flushPrefEnv is
+ // automatically called before we invoke
+ // test_SpecialPowersExtension2.html.
+ SpecialPowers.pushPrefEnv({set: [['testing.some_arbitrary_pref', true]]},
+ function() { SimpleTest.finish(); });
+}
+</script>
+</pre>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_SpecialPowersExtension2.html b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersExtension2.html
new file mode 100644
index 000000000..fc77aa82a
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersExtension2.html
@@ -0,0 +1,21 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for SpecialPowers extension</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+
+<div id="content" class="testbody">
+ <script type="text/javascript">
+ dump("\nSPECIALPTEST2:::Loading test2 file now " + (new Date).getTime() + "\n");
+ is(SpecialPowers.sanityCheck(), "foo", "Special Powers top level");
+ ok(!SpecialPowers.Services.prefs.prefHasUserValue('testing.some_arbitrary_pref'),
+ "should not retain pref from previous test");
+ </script>
+ <iframe id="frame1" src="file_SpecialPowersFrame1.html">
+ </iframe>
+</div>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadChromeScript.html b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadChromeScript.html
new file mode 100644
index 000000000..4b78928bf
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadChromeScript.html
@@ -0,0 +1,49 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for SpecialPowers.loadChromeScript</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+
+<pre id="test">
+<script class="testbody" type="text/javascript">
+SimpleTest.waitForExplicitFinish();
+
+var url = SimpleTest.getTestFileURL("SpecialPowersLoadChromeScript.js");
+var script = SpecialPowers.loadChromeScript(url);
+
+var MESSAGE = { bar: true };
+script.addMessageListener("bar", function (message) {
+ is(JSON.stringify(message), JSON.stringify(MESSAGE),
+ "received back message from the chrome script");
+
+ checkAssert();
+});
+
+function checkAssert() {
+ script.sendAsyncMessage("valid-assert");
+ script.addMessageListener("valid-assert-done", endOfTest);
+}
+
+function endOfTest() {
+ script.destroy();
+ SimpleTest.finish();
+}
+
+script.sendAsyncMessage("foo", MESSAGE);
+
+/*
+ * [0][0] is because we're using one real message listener in SpecialPowersObserverAPI.js
+ * and dispatching that to multiple _chromeScriptListeners. The outer array comes
+ * from the message manager since there can be multiple real listeners. The inner
+ * array is for the return values of _chromeScriptListeners.
+ */
+is(script.sendSyncMessage("sync-message")[0][0], "Received a synchronous message.",
+ "Check sync return value");
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadChromeScript_function.html b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadChromeScript_function.html
new file mode 100644
index 000000000..da29eadb8
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadChromeScript_function.html
@@ -0,0 +1,67 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for SpecialPowers.loadChromeScript</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+
+<pre id="test">
+<script class="testbody" type="text/javascript">
+SimpleTest.waitForExplicitFinish();
+
+
+var script = SpecialPowers.loadChromeScript(function loadChromeScriptTest() {
+ // Copied from SpecialPowersLoadChromeScript.js
+
+ // Just receive 'foo' message and forward it back
+ // as 'bar' message
+ addMessageListener("foo", function (message) {
+ sendAsyncMessage("bar", message);
+ });
+
+ addMessageListener("valid-assert", function (message) {
+ assert.ok(true, "valid assertion");
+ assert.equal(1, 1, "another valid assertion");
+ sendAsyncMessage("valid-assert-done");
+ });
+
+ addMessageListener("sync-message", () => {
+ return "Received a synchronous message.";
+ });
+});
+
+var MESSAGE = { bar: true };
+script.addMessageListener("bar", function (message) {
+ is(JSON.stringify(message), JSON.stringify(MESSAGE),
+ "received back message from the chrome script");
+
+ checkAssert();
+});
+
+function checkAssert() {
+ script.sendAsyncMessage("valid-assert");
+ script.addMessageListener("valid-assert-done", endOfTest);
+}
+
+function endOfTest() {
+ script.destroy();
+ SimpleTest.finish();
+}
+
+script.sendAsyncMessage("foo", MESSAGE);
+
+/*
+ * [0][0] is because we're using one real message listener in SpecialPowersObserverAPI.js
+ * and dispatching that to multiple _chromeScriptListeners. The outer array comes
+ * from the message manager since there can be multiple real listeners. The inner
+ * array is for the return values of _chromeScriptListeners.
+ */
+is(script.sendSyncMessage("sync-message")[0][0], "Received a synchronous message.",
+ "Check sync return value");
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadPrivilegedScript.html b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadPrivilegedScript.html
new file mode 100644
index 000000000..e9b545376
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadPrivilegedScript.html
@@ -0,0 +1,37 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for SpecialPowers.loadChromeScript</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+function loadPrivilegedScriptTest() {
+ var Cc = Components.classes;
+ var Ci = Components.interfaces;
+ function isMainProcess() {
+ return Cc["@mozilla.org/xre/app-info;1"].
+ getService(Ci.nsIXULRuntime).
+ processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
+ }
+ port.postMessage({'isMainProcess': isMainProcess()});
+}
+
+var contentProcessType = SpecialPowers.isMainProcess();
+var port;
+try {
+ port = SpecialPowers.loadPrivilegedScript(loadPrivilegedScriptTest.toSource());
+} catch (e) {
+ ok(false, "loadPrivilegedScript shoulde not throw");
+}
+port.onmessage = (e) => {
+ is(contentProcessType, e.data['isMainProcess'], "content and the script should be in the same process");
+ SimpleTest.finish();
+};
+</script>
diff --git a/testing/mochitest/tests/Harness_sanity/test_SpecialPowersPushPermissions.html b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersPushPermissions.html
new file mode 100644
index 000000000..709d2cc7d
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersPushPermissions.html
@@ -0,0 +1,237 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for SpecialPowers extension</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body onload="starttest();">
+
+<pre id="test">
+<script class="testbody" type="text/javascript">
+const ALLOW_ACTION = SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION;
+const DENY_ACTION = SpecialPowers.Ci.nsIPermissionManager.DENY_ACTION;
+const UNKNOWN_ACTION = SpecialPowers.Ci.nsIPermissionManager.UNKNOWN_ACTION;
+const PROMPT_ACTION = SpecialPowers.Ci.nsIPermissionManager.PROMPT_ACTION;
+const ACCESS_SESSION = SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION;
+const ACCESS_ALLOW_FIRST_PARTY_ONLY = SpecialPowers.Ci.nsICookiePermission.ACCESS_ALLOW_FIRST_PARTY_ONLY;
+const ACCESS_LIMIT_THIRD_PARTY = SpecialPowers.Ci.nsICookiePermission.ACCESS_LIMIT_THIRD_PARTY;
+
+const EXPIRE_TIME = SpecialPowers.Ci.nsIPermissionManager.EXPIRE_TIME;
+// expire Setting:
+// start expire time point
+// ----|------------------------|-----------
+// <------------------------>
+// PERIOD
+var start;
+// PR_Now() that called in nsPermissionManager to get the system time
+// is sometimes 100ms~600s more than Date.now() on Android 4.3 API11.
+// Thus, the PERIOD should be larger than 600ms in this test.
+const PERIOD = 900;
+var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('specialPowers_framescript.js'));
+SimpleTest.requestFlakyTimeout("untriaged");
+
+function starttest(){
+ SpecialPowers.addPermission("pPROMPT", PROMPT_ACTION, document);
+ SpecialPowers.addPermission("pALLOW", ALLOW_ACTION, document);
+ SpecialPowers.addPermission("pDENY", DENY_ACTION, document);
+ SpecialPowers.addPermission("pREMOVE", ALLOW_ACTION, document);
+ SpecialPowers.addPermission("pSESSION", ACCESS_SESSION, document);
+ SpecialPowers.addPermission("pFIRSTPARTY", ACCESS_ALLOW_FIRST_PARTY_ONLY, document);
+ SpecialPowers.addPermission("pTHIRDPARTY", ACCESS_LIMIT_THIRD_PARTY, document);
+
+ setTimeout(test1, 0);
+}
+
+SimpleTest.waitForExplicitFinish();
+
+function test1() {
+ if (!SpecialPowers.testPermission('pALLOW', ALLOW_ACTION, document)) {
+ dump('/**** allow not set ****/\n');
+ setTimeout(test1, 0);
+ } else if (!SpecialPowers.testPermission('pDENY', DENY_ACTION, document)) {
+ dump('/**** deny not set ****/\n');
+ setTimeout(test1, 0);
+ } else if (!SpecialPowers.testPermission('pPROMPT', PROMPT_ACTION, document)) {
+ dump('/**** prompt not set ****/\n');
+ setTimeout(test1, 0);
+ } else if (!SpecialPowers.testPermission('pREMOVE', ALLOW_ACTION, document)) {
+ dump('/**** remove not set ****/\n');
+ setTimeout(test1, 0);
+ } else if (!SpecialPowers.testPermission('pSESSION', ACCESS_SESSION, document)) {
+ dump('/**** ACCESS_SESSION not set ****/\n');
+ setTimeout(test1, 0);
+ } else if (!SpecialPowers.testPermission('pFIRSTPARTY', ACCESS_ALLOW_FIRST_PARTY_ONLY, document)) {
+ dump('/**** ACCESS_ALLOW_FIRST_PARTY_ONLY not set ****/\n');
+ setTimeout(test1, 0);
+ } else if (!SpecialPowers.testPermission('pTHIRDPARTY', ACCESS_LIMIT_THIRD_PARTY, document)) {
+ dump('/**** ACCESS_LIMIT_THIRD_PARTY not set ****/\n');
+ setTimeout(test1, 0);
+ } else {
+ test2();
+ }
+}
+
+function test2() {
+ ok(SpecialPowers.testPermission('pUNKNOWN', UNKNOWN_ACTION, document), 'pUNKNOWN value should have UNKOWN permission');
+ SpecialPowers.pushPermissions([{'type': 'pUNKNOWN', 'allow': true, 'context': document}, {'type': 'pALLOW', 'allow': false, 'context': document}, {'type': 'pDENY', 'allow': true, 'context': document}, {'type': 'pPROMPT', 'allow': true, 'context': document}, {'type': 'pSESSION', 'allow': true, 'context': document}, {'type': 'pFIRSTPARTY', 'allow': true, 'context': document}, {'type': 'pTHIRDPARTY', 'allow': true, 'context': document}, {'type': 'pREMOVE', 'remove': true, 'context': document}], test3);
+}
+
+function test3() {
+ ok(SpecialPowers.testPermission('pUNKNOWN', ALLOW_ACTION, document), 'pUNKNOWN value should have ALLOW permission');
+ ok(SpecialPowers.testPermission('pPROMPT', ALLOW_ACTION, document), 'pPROMPT value should have ALLOW permission');
+ ok(SpecialPowers.testPermission('pALLOW', DENY_ACTION, document), 'pALLOW should have DENY permission');
+ ok(SpecialPowers.testPermission('pDENY', ALLOW_ACTION, document), 'pDENY should have ALLOW permission');
+ ok(SpecialPowers.testPermission('pREMOVE', UNKNOWN_ACTION, document), 'pREMOVE should have REMOVE permission');
+ ok(SpecialPowers.testPermission('pSESSION', ALLOW_ACTION, document), 'pSESSION should have ALLOW permission');
+ ok(SpecialPowers.testPermission('pFIRSTPARTY', ALLOW_ACTION, document), 'pFIRSTPARTY should have ALLOW permission');
+ ok(SpecialPowers.testPermission('pTHIRDPARTY', ALLOW_ACTION, document), 'pTHIRDPARTY should have ALLOW permission');
+
+ // only pPROMPT (last one) is different, the other stuff is just to see if it doesn't cause test failures
+ SpecialPowers.pushPermissions([{'type': 'pUNKNOWN', 'allow': true, 'context': document}, {'type': 'pALLOW', 'allow': false, 'context': document}, {'type': 'pDENY', 'allow': true, 'context': document}, {'type': 'pPROMPT', 'allow': false, 'context': document}, {'type': 'pREMOVE', 'remove': true, 'context': document}], test3b);
+}
+
+function test3b() {
+ ok(SpecialPowers.testPermission('pPROMPT', DENY_ACTION, document), 'pPROMPT value should have DENY permission');
+ SpecialPowers.pushPermissions([{'type': 'pUNKNOWN', 'allow': DENY_ACTION, 'context': document}, {'type': 'pALLOW', 'allow': PROMPT_ACTION, 'context': document}, {'type': 'pDENY', 'allow': PROMPT_ACTION, 'context': document}, {'type': 'pPROMPT', 'allow': ALLOW_ACTION, 'context': document}], test4);
+}
+
+function test4() {
+ ok(SpecialPowers.testPermission('pUNKNOWN', DENY_ACTION, document), 'pUNKNOWN value should have DENY permission');
+ ok(SpecialPowers.testPermission('pPROMPT', ALLOW_ACTION, document), 'pPROMPT value should have ALLOW permission');
+ ok(SpecialPowers.testPermission('pALLOW', PROMPT_ACTION, document), 'pALLOW should have PROMPT permission');
+ ok(SpecialPowers.testPermission('pDENY', PROMPT_ACTION, document), 'pDENY should have PROMPT permission');
+ //this should reset all the permissions to before all the pushPermissions calls
+ SpecialPowers.flushPermissions(test5);
+}
+
+
+function test5() {
+ ok(SpecialPowers.testPermission('pUNKNOWN', UNKNOWN_ACTION, document), 'pUNKNOWN should have UNKNOWN permission');
+ ok(SpecialPowers.testPermission('pALLOW', ALLOW_ACTION, document), 'pALLOW should have ALLOW permission');
+ ok(SpecialPowers.testPermission('pDENY', DENY_ACTION, document), 'pDENY should have DENY permission');
+ ok(SpecialPowers.testPermission('pPROMPT', PROMPT_ACTION, document), 'pPROMPT should have PROMPT permission');
+ ok(SpecialPowers.testPermission('pREMOVE', ALLOW_ACTION, document), 'pREMOVE should have ALLOW permission');
+ ok(SpecialPowers.testPermission('pSESSION', ACCESS_SESSION, document), 'pSESSION should have ACCESS_SESSION permission');
+ ok(SpecialPowers.testPermission('pFIRSTPARTY', ACCESS_ALLOW_FIRST_PARTY_ONLY, document), 'pFIRSTPARTY should have ACCESS_ALLOW_FIRST_PARTY_ONLY permission');
+ ok(SpecialPowers.testPermission('pTHIRDPARTY', ACCESS_LIMIT_THIRD_PARTY, document), 'pTHIRDPARTY should have ACCESS_LIMIT_THIRD_PARTY permission');
+
+ SpecialPowers.removePermission("pPROMPT", document);
+ SpecialPowers.removePermission("pALLOW", document);
+ SpecialPowers.removePermission("pDENY", document);
+ SpecialPowers.removePermission("pREMOVE", document);
+ SpecialPowers.removePermission("pSESSION", document);
+ SpecialPowers.removePermission("pFIRSTPARTY", document);
+ SpecialPowers.removePermission("pTHIRDPARTY", document);
+
+ setTimeout(test6, 0);
+}
+
+function test6() {
+ if (!SpecialPowers.testPermission('pALLOW', UNKNOWN_ACTION, document)) {
+ dump('/**** allow still set ****/\n');
+ setTimeout(test6, 0);
+ } else if (!SpecialPowers.testPermission('pDENY', UNKNOWN_ACTION, document)) {
+ dump('/**** deny still set ****/\n');
+ setTimeout(test6, 0);
+ } else if (!SpecialPowers.testPermission('pPROMPT', UNKNOWN_ACTION, document)) {
+ dump('/**** prompt still set ****/\n');
+ setTimeout(test6, 0);
+ } else if (!SpecialPowers.testPermission('pREMOVE', UNKNOWN_ACTION, document)) {
+ dump('/**** remove still set ****/\n');
+ setTimeout(test6, 0);
+ } else if (!SpecialPowers.testPermission('pSESSION', UNKNOWN_ACTION, document)) {
+ dump('/**** pSESSION still set ****/\n');
+ setTimeout(test6, 0);
+ } else if (!SpecialPowers.testPermission('pFIRSTPARTY', UNKNOWN_ACTION, document)) {
+ dump('/**** pFIRSTPARTY still set ****/\n');
+ setTimeout(test6, 0);
+ } else if (!SpecialPowers.testPermission('pTHIRDPARTY', UNKNOWN_ACTION, document)) {
+ dump('/**** pTHIRDPARTY still set ****/\n');
+ setTimeout(test6, 0);
+ } else {
+ test7();
+ }
+}
+
+function test7() {
+ afterPermissionChanged('pEXPIRE', 'deleted', test8);
+ afterPermissionChanged('pEXPIRE', 'added', permissionPollingCheck);
+ start = Number(Date.now());
+ SpecialPowers.addPermission('pEXPIRE',
+ true,
+ document,
+ EXPIRE_TIME,
+ (start + PERIOD + getPlatformInfo().timeCompensation));
+}
+
+function test8() {
+ afterPermissionChanged('pEXPIRE', 'deleted', SimpleTest.finish);
+ afterPermissionChanged('pEXPIRE', 'added', permissionPollingCheck);
+ start = Number(Date.now());
+ SpecialPowers.pushPermissions([
+ { 'type': 'pEXPIRE',
+ 'allow': true,
+ 'expireType': EXPIRE_TIME,
+ 'expireTime': (start + PERIOD + getPlatformInfo().timeCompensation),
+ 'context': document
+ }], function() {
+ info("Wait for permission-changed signal!");
+ }
+ );
+}
+
+function afterPermissionChanged(type, op, callback) {
+ // handle the message from specialPowers_framescript.js
+ gScript.addMessageListener('perm-changed', function onChange(msg) {
+ if (msg.type == type && msg.op == op) {
+ gScript.removeMessageListener('perm-changed', onChange);
+ callback();
+ }
+ });
+}
+
+function permissionPollingCheck() {
+ var now = Number(Date.now());
+ if (now < (start + PERIOD)) {
+ if (SpecialPowers.testPermission('pEXPIRE', ALLOW_ACTION, document)) {
+ // To make sure that permission will be expired in next round,
+ // the next permissionPollingCheck calling will be fired 100ms later after
+ // permission is out-of-period.
+ setTimeout(permissionPollingCheck, PERIOD + 100);
+ return;
+ }
+
+ errorHandler('unexpired permission should be allowed!');
+ }
+
+ // The permission is already expired!
+ if (SpecialPowers.testPermission('pEXPIRE', ALLOW_ACTION, document)) {
+ errorHandler('expired permission should be removed!');
+ }
+}
+
+function getPlatformInfo() {
+ var version = SpecialPowers.Services.sysinfo.getProperty('version');
+ version = parseFloat(version);
+
+ // PR_Now() that called in nsPermissionManager to get the system time and
+ // Date.now() are out of sync on win32 platform(XP/win7). The PR_Now() is
+ // 15~20ms less than Date.now(). Unfortunately, this time skew can't be
+ // avoided, so it needs to add a time buffer to compensate.
+ // Version 5.1 is win XP, 6.1 is win7
+ if (navigator.platform.startsWith('Win32') && (version <= 6.1)) {
+ return { platform: "Win32", timeCompensation: -100 };
+ }
+
+ return { platform: "NoMatter", timeCompensation: 0 };
+}
+
+function errorHandler(msg) {
+ ok(false, msg);
+ SimpleTest.finish();
+}
+</script>
+</pre>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_SpecialPowersPushPrefEnv.html b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersPushPrefEnv.html
new file mode 100644
index 000000000..cc352aeaa
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersPushPrefEnv.html
@@ -0,0 +1,211 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for SpecialPowers extension</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body onload="starttest();">
+
+<pre id="test">
+<script class="testbody" type="text/javascript">
+function starttest() {
+ try {
+ SpecialPowers.setBoolPref("test.bool", 1);
+ } catch(e) {
+ SpecialPowers.setBoolPref("test.bool", true);
+ }
+ try {
+ SpecialPowers.setIntPref("test.int", true);
+ } catch(e) {
+ SpecialPowers.setIntPref("test.int", 1);
+ }
+ SpecialPowers.setCharPref("test.char", 'test');
+
+ setTimeout(test1, 0, 0);
+}
+
+SimpleTest.waitForExplicitFinish();
+
+function test1(aCount) {
+ if (aCount >= 20) {
+ ok(false, "Too many times attempting to set pref, aborting");
+ SimpleTest.finish();
+ return;
+ }
+
+ try {
+ is(SpecialPowers.getBoolPref('test.bool'), true, 'test.bool should be true');
+ } catch(e) {
+ setTimeout(test1, 0, ++aCount);
+ return;
+ }
+
+ try {
+ is(SpecialPowers.getIntPref('test.int'), 1, 'test.int should be 1');
+ } catch(e) {
+ setTimeout(test1, 0, ++aCount);
+ return;
+ }
+
+ try {
+ is(SpecialPowers.getCharPref('test.char'), 'test', 'test.char should be test');
+ } catch(e) {
+ setTimeout(test1, 0, ++aCount);
+ return;
+ }
+
+ test2();
+}
+
+function test2() {
+ // test non-changing values
+ SpecialPowers.pushPrefEnv({"set": [["test.bool", true], ["test.int", 1], ["test.char", "test"]]}, test3);
+}
+
+function test3() {
+ // test changing char pref using the Promise
+ is(SpecialPowers.getBoolPref('test.bool'), true, 'test.bool should be true');
+ is(SpecialPowers.getIntPref('test.int'), 1, 'test.int should be 1');
+ is(SpecialPowers.getCharPref('test.char'), 'test', 'test.char should be test');
+ SpecialPowers.pushPrefEnv({"set": [["test.bool", true], ["test.int", 1], ["test.char", "test2"]]}).then(test4);
+}
+
+function test4() {
+ // test changing all values and adding test.char2 pref
+ is(SpecialPowers.getCharPref('test.char'), 'test2', 'test.char should be test2');
+ SpecialPowers.pushPrefEnv({"set": [["test.bool", false], ["test.int", 10], ["test.char", "test2"], ["test.char2", "test"]]}, test5);
+}
+
+function test5() {
+ // test flushPrefEnv
+ is(SpecialPowers.getBoolPref('test.bool'), false, 'test.bool should be false');
+ is(SpecialPowers.getIntPref('test.int'), 10, 'test.int should be 10');
+ is(SpecialPowers.getCharPref('test.char'), 'test2', 'test.char should be test2');
+ is(SpecialPowers.getCharPref('test.char2'), 'test', 'test.char2 should be test');
+ SpecialPowers.flushPrefEnv(test6);
+}
+
+function test6() {
+ // test clearing prefs
+ is(SpecialPowers.getBoolPref('test.bool'), true, 'test.bool should be true');
+ is(typeof SpecialPowers.getBoolPref('test.bool'), typeof true, 'test.bool should be boolean');
+ is(SpecialPowers.getIntPref('test.int'), 1, 'test.int should be 1');
+ is(typeof SpecialPowers.getIntPref('test.int'), typeof 1, 'test.int should be integer');
+ is(SpecialPowers.getCharPref('test.char'), 'test', 'test.char should be test');
+ is(typeof SpecialPowers.getCharPref('test.char'), typeof 'test', 'test.char should be String');
+ try {
+ SpecialPowers.getCharPref('test.char2');
+ ok(false, 'This ok should not be reached!');
+ } catch(e) {
+ ok(true, 'getCharPref("test.char2") should throw');
+ }
+ SpecialPowers.pushPrefEnv({"clear": [["test.bool"], ["test.int"], ["test.char"], ["test.char2"]]}, test6b);
+}
+
+function test6b() {
+ // test if clearing another time doesn't cause issues
+ SpecialPowers.pushPrefEnv({"clear": [["test.bool"], ["test.int"], ["test.char"], ["test.char2"]]}, test7);
+}
+
+function test7() {
+ try {
+ SpecialPowers.getBoolPref('test.bool');
+ ok(false, 'This ok should not be reached!');
+ } catch(e) {
+ ok(true, 'getBoolPref("test.bool") should throw');
+ }
+
+ try {
+ SpecialPowers.getIntPref('test.int');
+ ok(false, 'This ok should not be reached!');
+ } catch(e) {
+ ok(true, 'getIntPref("test.int") should throw');
+ }
+
+ try {
+ SpecialPowers.getCharPref('test.char');
+ ok(false, 'This ok should not be reached!');
+ } catch(e) {
+ ok(true, 'getCharPref("test.char") should throw');
+ }
+
+ try {
+ SpecialPowers.getCharPref('test.char2');
+ ok(false, 'This ok should not be reached!');
+ } catch(e) {
+ ok(true, 'getCharPref("test.char2") should throw');
+ }
+
+ SpecialPowers.flushPrefEnv().then(test8);
+}
+
+function test8() {
+ is(SpecialPowers.getBoolPref('test.bool'), true, 'test.bool should be true');
+ is(typeof SpecialPowers.getBoolPref('test.bool'), typeof true, 'test.bool should be boolean');
+ is(SpecialPowers.getIntPref('test.int'), 1, 'test.int should be 1');
+ is(typeof SpecialPowers.getIntPref('test.int'), typeof 1, 'test.int should be integer');
+ is(SpecialPowers.getCharPref('test.char'), 'test', 'test.char should be test');
+ is(typeof SpecialPowers.getCharPref('test.char'), typeof 'test', 'test.char should be String');
+ try {
+ SpecialPowers.getCharPref('test.char2');
+ ok(false, 'This ok should not be reached!');
+ } catch(e) {
+ ok(true, 'getCharPref("test.char2") should throw');
+ }
+ SpecialPowers.clearUserPref("test.bool");
+ SpecialPowers.clearUserPref("test.int");
+ SpecialPowers.clearUserPref("test.char");
+ setTimeout(test9, 0, 0);
+}
+
+function test9(aCount) {
+ if (aCount >= 20) {
+ ok(false, "Too many times attempting to set pref, aborting");
+ SimpleTest.finish();
+ return;
+ }
+
+ try {
+ SpecialPowers.getBoolPref('test.bool');
+ setTimeout(test9, 0, ++aCount);
+ } catch(e) {
+ test10(0);
+ }
+}
+
+function test10(aCount) {
+ if (aCount >= 20) {
+ ok(false, "Too many times attempting to set pref, aborting");
+ SimpleTest.finish();
+ return;
+ }
+
+ try {
+ SpecialPowers.getIntPref('test.int');
+ setTimeout(test10, 0, ++aCount);
+ } catch(e) {
+ test11(0);
+ }
+}
+
+function test11(aCount) {
+ if (aCount >= 20) {
+ ok(false, "Too many times attempting to set pref, aborting");
+ SimpleTest.finish();
+ return;
+ }
+
+ try {
+ SpecialPowers.getCharPref('test.char');
+ setTimeout(test11, 0, ++aCount);
+ } catch(e) {
+ SimpleTest.finish();
+ }
+}
+// todo - test non-changing values, test complex values, test mixing of pushprefEnv 'set' and 'clear'
+// When bug 776424 gets fixed, getPref doesn't throw anymore, so this test would have to be changed accordingly
+</script>
+</pre>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_TestsRunningAfterSimpleTestFinish.html b/testing/mochitest/tests/Harness_sanity/test_TestsRunningAfterSimpleTestFinish.html
new file mode 100644
index 000000000..7d2a97eb5
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_TestsRunningAfterSimpleTestFinish.html
@@ -0,0 +1,23 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for whether SimpLeTest.ok after SimpleTest.finish is causing an error to be logged</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+
+<div id="content" class="testbody">
+ <script type="text/javascript">
+ SimpleTest.waitForExplicitFinish();
+ addLoadEvent(function() {
+ ok(true, "This should pass");
+ SimpleTest.finish();
+ });
+ window.onbeforeunload = function() {
+ ok(true, "This should cause failures in the harness, because it's run after SimpleTest.finish()");
+ }
+ </script>
+</div>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_add_task.html b/testing/mochitest/tests/Harness_sanity/test_add_task.html
new file mode 100644
index 000000000..0b551e453
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_add_task.html
@@ -0,0 +1,38 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for mochitest add_task, found in SpawnTask.js</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug 1187701</a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+// Check that we can 'add_task' a few times and all tasks run asynchronously before test finishes.
+
+add_task(function* () {
+ var x = yield Promise.resolve(1);
+ is(x, 1, "task yields Promise value as expected");
+});
+
+add_task(function* () {
+ var x = yield [Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)];
+ is(x.join(""), "123", "task yields Promise value as expected");
+});
+
+add_task(function* () {
+ var x = yield (function* () {
+ return 3;
+ }());
+ is(x, 3, "task yields generator function return value as expected");
+});
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/testing/mochitest/tests/Harness_sanity/test_bug649012.html b/testing/mochitest/tests/Harness_sanity/test_bug649012.html
new file mode 100644
index 000000000..d6205da34
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_bug649012.html
@@ -0,0 +1,38 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=649012
+-->
+<head>
+ <title>Test for Bug 649012</title>
+ <script type="application/javascript" src="/MochiKit/packed.js"></script>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=649012">Mozilla Bug 649012</a>
+<p id="display"></p>
+<div id="content">
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 649012 **/
+SimpleTest.waitForExplicitFinish();
+addLoadEvent(function() {
+ // Test that setTimeout(f, 0) doesn't raise an error
+ setTimeout(function() {
+ // Test that setTimeout(f, t) where t > 0 doesn't raise an error if we've used
+ // SimpleTest.requestFlakyTimeout
+ SimpleTest.requestFlakyTimeout("Just testing to make sure things work. I would never do this in real life of course!");
+ setTimeout(function() {
+ SimpleTest.finish();
+ }, 1);
+ }, 0);
+});
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_createFiles.html b/testing/mochitest/tests/Harness_sanity/test_createFiles.html
new file mode 100644
index 000000000..502592acc
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_createFiles.html
@@ -0,0 +1,91 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for SpecialPowers.createFiles</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+
+<div id="content" class="testbody">
+ <script type="text/javascript">
+ // Creating one file, followed by failing to create a file.
+ function test1() {
+ const fileType = "some file type";
+ let fdata = "this is same data for a file";
+ SpecialPowers.createFiles([{name: "test1.txt", data:fdata, options:{type:fileType}}],
+ function (files) {
+ is(files.length, 1, "Created 1 file");
+ let f = files[0];
+ is("[object File]", f.toString(), "first thing in array is a file");
+ is(f.size, fdata.length, "test1 size of first file should be length of its data");
+ is("test1.txt", f.name, "test1 test file should have the right name");
+ is(f.type, fileType, "File should have the specified type");
+ test2();
+ },
+ function (msg) { ok(false, "Should be able to create a file without an error"); test2(); }
+ );
+ }
+
+ // Failing to create a file, followed by creating a file.
+ function test2() {
+ function test3Check(passed) {
+ ok(passed, "Should trigger the error handler for a bad file name.");
+ test3();
+ };
+
+ SpecialPowers.createFiles([{name: "/\/\/\/\/\/\/\/\/\/\/\invalidname",}],
+ function () { test3Check(false); },
+ function (msg) { test3Check(true); }
+ );
+ }
+
+ // Creating two files at the same time.
+ function test3() {
+ let f1data = "hello";
+ SpecialPowers.createFiles([{name: "test3_file.txt", data:f1data}, {name: "emptyfile.txt"}],
+ function (files) {
+ is(files.length, 2, "Expected two files to be created");
+ let f1 = files[0];
+ let f2 = files[1];
+ is("[object File]", f1.toString(), "first thing in array is a file");
+ is("[object File]", f2.toString(), "second thing in array is a file");
+ is("test3_file.txt", f1.name, "first test3 test file should have the right name");
+ is("emptyfile.txt", f2.name, "second test3 test file should have the right name");
+ is(f1.size, f1data.length, "size of first file should be length of its data");
+ is(f2.size, 0, "size of second file should be 0");
+ test4();
+ },
+ function (msg) {
+ ok(false, "Failed to create files: " + msg);
+ test4();
+ }
+ );
+ };
+
+ // Creating a file without specifying a name should work.
+ function test4() {
+ let fdata = "this is same data for a file";
+ SpecialPowers.createFiles([{data:fdata}],
+ function (files) {
+ is(files.length, 1, "Created 1 file");
+ let f = files[0];
+ is("[object File]", f.toString(), "first thing in array is a file");
+ is(f.size, fdata.length, "test4 size of first file should be length of its data");
+ ok(f.name, "test4 test file should have a name");
+ SimpleTest.finish();
+ },
+ function (msg) {
+ ok(false, "Should be able to create a file without a name without an error");
+ SimpleTest.finish();
+ }
+ );
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ test1();
+
+ </script>
+</div>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_importInMainProcess.html b/testing/mochitest/tests/Harness_sanity/test_importInMainProcess.html
new file mode 100644
index 000000000..569966074
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_importInMainProcess.html
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for SpecialPowers.importInMainProcess</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+
+<div id="content" class="testbody">
+ <script type="text/javascript">
+ SimpleTest.waitForExplicitFinish();
+
+ var failed = false;
+ try {
+ SpecialPowers.importInMainProcess("invalid file for import");
+ } catch (e) {
+ ok(e.toString().indexOf("NS_ERROR_MALFORMED_URI") > -1, "Exception should be for a malformed URI");
+ failed = true;
+ }
+ ok(failed, "An invalid import should throw");
+
+ const testingResource = "resource://testing-common/ImportTesting.jsm";
+ var script = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('importtesting_chromescript.js'));
+
+ script.addMessageListener("ImportTesting:IsModuleLoadedReply", handleFirstReply);
+ script.sendAsyncMessage("ImportTesting:IsModuleLoaded", testingResource);
+
+ function handleFirstReply(aMsg) {
+ ok(!aMsg, "ImportTesting.jsm shouldn't be loaded before we import it");
+
+ try {
+ SpecialPowers.importInMainProcess(testingResource);
+ } catch (e) {
+ ok(false, "Unexpected exception when importing a valid resource: " + e.toString());
+ }
+
+ script.removeMessageListener("ImportTesting:IsModuleLoadedReply", handleFirstReply);
+ script.addMessageListener("ImportTesting:IsModuleLoadedReply", handleSecondReply);
+ script.sendAsyncMessage("ImportTesting:IsModuleLoaded", testingResource);
+ }
+
+ function handleSecondReply(aMsg) {
+ script.removeMessageListener("ImportTesting:IsModuleLoadedReply", handleSecondReply);
+
+ ok(aMsg, "ImportTesting.jsm should be loaded after we import it");
+
+ SimpleTest.finish();
+ }
+
+ </script>
+</div>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_sanity.html b/testing/mochitest/tests/Harness_sanity/test_sanity.html
new file mode 100644
index 000000000..3c9266685
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_sanity.html
@@ -0,0 +1,63 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for mochitest harness sanity</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
+<p id="display">
+ <input id="testKeyEvent1" onkeypress="press1 = true">
+ <input id="testKeyEvent2" onkeydown="return false;" onkeypress="press2 = true">
+ <input id="testKeyEvent3" onkeypress="press3 = true">
+ <input id="testKeyEvent4" onkeydown="return false;" onkeypress="press4 = true">
+</p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/** Test for sanity **/
+ok(true, "true must be ok");
+isnot(1, true, "1 must not be true");
+isnot(1, false, "1 must not be false");
+isnot(0, false, "0 must not be false");
+isnot(0, true, "0 must not be true");
+isnot("", 0, "Empty string must not be 0");
+isnot("1", 1, "Numeric string must not equal the number");
+isnot("", null, "Empty string must not be null");
+isnot(undefined, null, "Undefined must not be null");
+
+var press1 = false;
+$("testKeyEvent1").focus();
+synthesizeKey("x", {});
+is($("testKeyEvent1").value, "x", "synthesizeKey should work");
+is(press1, true, "synthesizeKey should dispatch keyPress");
+
+var press2 = false;
+$("testKeyEvent2").focus();
+synthesizeKey("x", {});
+is($("testKeyEvent2").value, "", "synthesizeKey should respect keydown preventDefault");
+is(press2, false, "synthesizeKey should not dispatch keyPress with default prevented");
+
+var press3 = false;
+$("testKeyEvent3").focus();
+sendChar("x")
+is($("testKeyEvent3").value, "x", "sendChar should work");
+is(press3, true, "sendChar should dispatch keyPress");
+
+var press4 = false;
+$("testKeyEvent4").focus();
+sendChar("x")
+is($("testKeyEvent4").value, "", "sendChar should respect keydown preventDefault");
+is(press4, false, "sendChar should not dispatch keyPress with default prevented");
+
+
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/testing/mochitest/tests/Harness_sanity/test_sanityEventUtils.html b/testing/mochitest/tests/Harness_sanity/test_sanityEventUtils.html
new file mode 100644
index 000000000..07efaaf4d
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_sanityEventUtils.html
@@ -0,0 +1,188 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Profiling test suite for EventUtils</title>
+ <script type="text/javascript">
+ var start = new Date();
+ </script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+ <script type="text/javascript">
+ var loadTime = new Date();
+ </script>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body onload="starttest()">
+<input type="radio" id="radioTarget1" name="group">Radio Target 1</input>
+<input id="textBoxA">
+<input id="textBoxB">
+<input id="testMouseEvent" type="button" value="click">
+<input id="testKeyEvent" >
+<input id="testStrEvent" >
+<div id="scrollB" style="width: 190px;height: 250px;overflow:auto">
+<p>blah blah blah blah</p>
+<p>blah blah blah blah</p>
+<p>blah blah blah blah</p>
+<p>blah blah blah blah</p>
+<p>blah blah blah blah</p>
+<p>blah blah blah blah</p>
+<p>blah blah blah blah</p>
+<p>blah blah blah blah</p>
+</div>
+<script class="testbody" type="text/javascript">
+info("\nProfile::EventUtilsLoadTime: " + (loadTime - start) + "\n");
+function starttest() {
+ SimpleTest.waitForFocus(
+ function () {
+ SimpleTest.waitForExplicitFinish();
+ var startTime = new Date();
+ var check = false;
+
+ /* test send* functions */
+ $("testMouseEvent").addEventListener("click", function() { check=true; }, false);
+ sendMouseEvent({type:'click'}, "testMouseEvent");
+ is(check, true, 'sendMouseEvent should dispatch click event');
+
+ check = false;
+ $("testKeyEvent").addEventListener("keypress", function() { check = true; }, false);
+ $("testKeyEvent").focus();
+ sendChar("x");
+ is($("testKeyEvent").value, "x", "sendChar should work");
+ is(check, true, "sendChar should dispatch keyPress");
+ $("testKeyEvent").value = "";
+
+ $("testStrEvent").focus();
+ sendString("string");
+ is($("testStrEvent").value, "string", "sendString should work");
+ $("testStrEvent").value = "";
+
+ check = false;
+ $("testKeyEvent").focus();
+ sendKey("DOWN");
+ is(check, true, "sendKey should dispatch keyPress");
+
+ /* test synthesizeMouse* */
+ //focus trick enables us to run this in iframes
+ $("radioTarget1").addEventListener('focus', function (aEvent) {
+ $("radioTarget1").removeEventListener('focus', arguments.callee, false);
+ synthesizeMouse($("radioTarget1"), 1, 1, {});
+ is($("radioTarget1").checked, true, "synthesizeMouse should work")
+ $("radioTarget1").checked = false;
+ disableNonTestMouseEvents(true);
+ synthesizeMouse($("radioTarget1"), 1, 1, {});
+ is($("radioTarget1").checked, true, "synthesizeMouse should still work with non-test mouse events disabled");
+ $("radioTarget1").checked = false;
+ disableNonTestMouseEvents(false);
+ });
+ $("radioTarget1").focus();
+
+ //focus trick enables us to run this in iframes
+ $("textBoxA").addEventListener("focus", function (aEvent) {
+ $("textBoxA").removeEventListener("focus", arguments.callee, false);
+ check = false;
+ $("textBoxA").addEventListener("click", function() { check = true; }, false);
+ synthesizeMouseAtCenter($("textBoxA"), {});
+ is(check, true, 'synthesizeMouse should dispatch mouse event');
+
+ check = false;
+ synthesizeMouseExpectEvent($("textBoxA"), 1, 1, {}, $("textBoxA"), "click", "synthesizeMouseExpectEvent should fire click event");
+ is(check, true, 'synthesizeMouse should dispatch mouse event');
+ });
+ $("textBoxA").focus();
+
+ /**
+ * TODO: testing synthesizeWheel requires a setTimeout
+ * since there is delay between the scroll event and a check, so for now just test
+ * that we can successfully call it to avoid having setTimeout vary the runtime metric.
+ * Testing of this method is currently done here:
+ * toolkit/content/tests/chrome/test_mousescroll.xul
+ */
+ synthesizeWheel($("scrollB"), 5, 5, {'deltaY': 10.0, deltaMode: WheelEvent.DOM_DELTA_LINE});
+
+ /* test synthesizeKey* */
+ check = false;
+ $("testKeyEvent").addEventListener("keypress", function() { check = true; }, false);
+ $("testKeyEvent").focus();
+ synthesizeKey("a", {});
+ is($("testKeyEvent").value, "a", "synthesizeKey should work");
+ is(check, true, "synthesizeKey should dispatch keyPress");
+ $("testKeyEvent").value = "";
+
+ check = false;
+ synthesizeKeyExpectEvent("a", {}, $("testKeyEvent"), "keypress");
+ is($("testKeyEvent").value, "a", "synthesizeKey should work");
+ is(check, true, "synthesizeKey should dispatch keyPress");
+ $("testKeyEvent").value = "";
+
+ /* test synthesizeComposition */
+ $("textBoxB").focus();
+ check = false;
+ window.addEventListener("compositionstart", function() { check = true; }, false);
+ synthesizeComposition({ type: "compositionstart" });
+ is(check, true, 'synthesizeComposition() should dispatch compositionstart');
+
+ check = false;
+ window.addEventListener("compositionupdate", function() { check = true; }, false);
+ synthesizeComposition({ type: "compositionupdate", data: "a" });
+ is(check, false, 'synthesizeComposition() should not dispatch compositionupdate without error');
+
+ check = false;
+ window.addEventListener("text", function() { check = true; }, false);
+ synthesizeCompositionChange(
+ { "composition":
+ { "string": "a",
+ "clauses":
+ [
+ { "length": 1, "attr": COMPOSITION_ATTR_RAW_CLAUSE }
+ ]
+ },
+ "caret": { "start": 1, "length": 0 }
+ }
+ );
+ is(check, true, "synthesizeCompositionChange should cause dispatching a DOM text event");
+
+ synthesizeCompositionChange(
+ { "composition":
+ { "string": "a",
+ "clauses":
+ [
+ { "length": 0, "attr": 0 }
+ ]
+ },
+ "caret": { "start": 1, "length": 0 }
+ }
+ );
+
+ check = false;
+ window.addEventListener("compositionend", function() { check = true; }, false);
+ synthesizeComposition({ type: "compositionend", data: "a" });
+ is(check, false, 'synthesizeComposition() should not dispatch compositionend');
+
+ synthesizeComposition({ type: "compositioncommit", data: "a" });
+ is(check, true, 'synthesizeComposition() should dispatch compositionend');
+
+ var querySelectedText = synthesizeQuerySelectedText();
+ ok(querySelectedText, "query selected text event result is null");
+ ok(querySelectedText.succeeded, "query selected text event failed");
+ is(querySelectedText.offset, 1,
+ "query selected text event returns wrong offset");
+ is(querySelectedText.text, "",
+ "query selected text event returns wrong selected text");
+ $("textBoxB").value = "";
+
+ querySelectedText = synthesizeQuerySelectedText();
+ ok(querySelectedText, "query selected text event result is null");
+ ok(querySelectedText.succeeded, "query selected text event failed");
+ is(querySelectedText.offset, 0,
+ "query selected text event returns wrong offset");
+ is(querySelectedText.text, "",
+ "query selected text event returns wrong selected text");
+ var endTime = new Date();
+ info("\nProfile::EventUtilsRunTime: " + (endTime-startTime) + "\n");
+ SimpleTest.finish();
+ }
+ );
+};
+</script>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_sanityException.html b/testing/mochitest/tests/Harness_sanity/test_sanityException.html
new file mode 100644
index 000000000..e1ed14836
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_sanityException.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Test that uncaught exceptions in mochitests cause failures</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=670817">Mozilla Bug 670817</a>
+<script>
+ok(true, "a call to ok");
+SimpleTest.expectUncaughtException();
+throw "an uncaught exception";
+</script>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_sanityException2.html b/testing/mochitest/tests/Harness_sanity/test_sanityException2.html
new file mode 100644
index 000000000..57d04764f
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_sanityException2.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Test that uncaught exceptions in mochitests cause failures</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=670817">Mozilla Bug 670817</a>
+<script>
+SimpleTest.waitForExplicitFinish();
+ok(true, "a call to ok");
+SimpleTest.executeSoon(function() {
+ SimpleTest.expectUncaughtException();
+ throw "an uncaught exception";
+});
+SimpleTest.executeSoon(function() {
+ SimpleTest.finish();
+});
+</script>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_sanityParams.html b/testing/mochitest/tests/Harness_sanity/test_sanityParams.html
new file mode 100644
index 000000000..0d870f77f
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_sanityParams.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for exposing test suite information</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 class="testbody" type="text/javascript">
+ok(SimpleTest.harnessParameters, "Should have parameters.");
+</script>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_sanityRegisteredServiceWorker.html b/testing/mochitest/tests/Harness_sanity/test_sanityRegisteredServiceWorker.html
new file mode 100644
index 000000000..6c8fc3524
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_sanityRegisteredServiceWorker.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Test that service worker registrations not cleaned up in mochitests cause failures</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+</head>
+<body>
+<script>
+SimpleTest.waitForExplicitFinish();
+SimpleTest.expectRegisteredServiceWorker();
+SpecialPowers.pushPrefEnv({"set": [
+ ["dom.serviceWorkers.exemptFromPerDomainMax", true],
+ ["dom.serviceWorkers.enabled", true],
+ ["dom.serviceWorkers.testing.enabled", true]
+]}, function() {
+ navigator.serviceWorker.register("empty.js", {scope: "scope"})
+ .then(function(registration) {
+ ok(registration, "Registration succeeded");
+ SimpleTest.finish();
+ });
+});
+</script>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_sanityRegisteredServiceWorker2.html b/testing/mochitest/tests/Harness_sanity/test_sanityRegisteredServiceWorker2.html
new file mode 100644
index 000000000..105fa6614
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_sanityRegisteredServiceWorker2.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Test that service worker registrations not cleaned up in mochitests cause failures</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+</head>
+<body>
+<script>
+SimpleTest.waitForExplicitFinish();
+SpecialPowers.pushPrefEnv({"set": [
+ ["dom.serviceWorkers.exemptFromPerDomainMax", true],
+ ["dom.serviceWorkers.enabled", true],
+ ["dom.serviceWorkers.testing.enabled", true]
+]}, function() {
+ navigator.serviceWorker.getRegistration("scope")
+ .then(function(registration) {
+ ok(registration, "Registration successfully obtained");
+ return registration.unregister();
+ }).then(function() {
+ SimpleTest.finish();
+ });
+});
+</script>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_sanitySimpletest.html b/testing/mochitest/tests/Harness_sanity/test_sanitySimpletest.html
new file mode 100644
index 000000000..1dc49a5d7
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_sanitySimpletest.html
@@ -0,0 +1,95 @@
+<!--This test should be updated each time new functionality is added to SimpleTest-->
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Profiling test suite for SimpleTest</title>
+ <script type="text/javascript">
+ var start = new Date();
+ </script>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+ <script type="text/javascript">
+ var loadTime = new Date();
+ </script>
+</head>
+<body>
+<input id="textB"/>
+<script class="testbody" type="text/javascript">
+info("Profile::SimpleTestLoadTime: " + (loadTime - start));
+var startTime = new Date();
+SimpleTest.waitForExplicitFinish();
+function starttest() {
+ SimpleTest.waitForFocus(
+ function() {
+ //test log
+ info("Logging some info")
+
+ //basic usage
+ ok(true, "test ok", "This should be true");
+ is(0, 0, "is() test failed");
+ isnot(0, 1, "isnot() test failed");
+
+ //todo tests
+ todo(false, "test todo", "todo() test should not pass");
+ todo_is(false, true, "test todo_is");
+ todo_isnot(true, true, "test todo_isnot");
+
+ //misc
+ SimpleTest.requestLongerTimeout(1);
+
+ //note: this test may alter runtimes as it waits
+ var check = false;
+ $('textB').focus();
+ SimpleTest.waitForClipboard("a",
+ function () {
+ SpecialPowers.clipboardCopyString("a");
+ },
+ function () {
+ check = true;
+ },
+ function () {
+ check = false;
+ }
+ );
+ is(check, true, "waitForClipboard should work");
+
+ //use helper functions
+ var div1 = createEl('div', {'id': 'somediv', 'display': 'block'}, "I am a div");
+ document.body.appendChild(div1);
+ var divObj = this.getElement('somediv');
+ is(divObj, div1, 'createEl did not create element as expected');
+ is($('somediv'), divObj, '$ helper did not get element as expected');
+ is(computedStyle(divObj, 'display'), 'block', 'computedStyle did not get right display value');
+ document.body.removeChild(div1);
+
+ /* note: expectChildProcessCrash is not being tested here, as it causes wildly variable
+ * run times. It is currently being tested in:
+ * dom/plugins/test/test_hanging.html and dom/plugins/test/test_crashing.html
+ */
+
+ //note: this also adds a short wait period
+ SimpleTest.executeSoon(
+ function () {
+ //finish() calls a slew of SimpleTest functions
+ SimpleTest.finish();
+ //call this after finish so we can make sure it works and doesn't hang our process
+ var endTime = new Date();
+ info("Profile::SimpleTestRunTime: " + (endTime-startTime));
+ //expect and throw exception here. Otherwise, any code that follows the throw call will never be executed
+ SimpleTest.expectUncaughtException();
+ //make sure we catch this error
+ throw "i am an uncaught exception"
+ }
+ );
+ }
+ );
+};
+//use addLoadEvent
+addLoadEvent(
+ function() {
+ starttest();
+ }
+);
+</script>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_sanityWindowSnapshot.html b/testing/mochitest/tests/Harness_sanity/test_sanityWindowSnapshot.html
new file mode 100644
index 000000000..4b8e9f3a4
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_sanityWindowSnapshot.html
@@ -0,0 +1,35 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Profiling test suite for WindowSnapshot</title>
+ <script type="text/javascript">
+ var start = new Date();
+ </script>
+ <script type="text/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
+ <script type="text/javascript">
+ var loadTime = new Date();
+ </script>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body onload="starttest()">
+<script class="testbody" type="text/javascript">
+info("\nProfile::WindowSnapshotLoadTime: " + (loadTime - start) + "\n");
+function starttest() {
+ SimpleTest.waitForExplicitFinish();
+ var startTime = new Date();
+ var snap = snapshotWindow(window, false);
+ var snap2 = snapshotWindow(window, false);
+ is(compareSnapshots(snap, snap2, true)[0], true, "this should be true");
+ var div1 = createEl('div', {'id': 'somediv', 'display': 'block'}, "I am a div");
+ document.body.appendChild(div1);
+ snap2 = snapshotWindow(window, false);
+ is(compareSnapshots(snap, snap2, true)[0], false, "this should be false");
+ document.body.removeChild(div1);
+ var endTime = new Date();
+ info("\nProfile::WindowSnapshotRunTime: " + (endTime-startTime) + "\n");
+ SimpleTest.finish();
+};
+</script>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_sanity_cleanup.html b/testing/mochitest/tests/Harness_sanity/test_sanity_cleanup.html
new file mode 100644
index 000000000..af8d4fd31
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_sanity_cleanup.html
@@ -0,0 +1,30 @@
+<!-- Any copyright is dedicated to the Public Domain.
+ - http://creativecommons.org/publicdomain/zero/1.0/ -->
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>SimpleTest.registerCleanupFunction test</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 class="testbody" type="text/javascript">
+// Not a great example, since we have the pushPrefEnv API to cover
+// this use case, but I want to be able to test that the cleanup
+// function gets run, so setting and clearing a pref seems straightforward.
+function do_cleanup1() {
+ SpecialPowers.clearUserPref("simpletest.cleanup.1");
+ info("do_cleanup1 run!");
+}
+function do_cleanup2() {
+ SpecialPowers.clearUserPref("simpletest.cleanup.2");
+ info("do_cleanup2 run!");
+}
+SpecialPowers.setBoolPref("simpletest.cleanup.1", true);
+SpecialPowers.setBoolPref("simpletest.cleanup.2", true);
+SimpleTest.registerCleanupFunction(do_cleanup1);
+SimpleTest.registerCleanupFunction(do_cleanup2);
+ok(true, "dummy check");
+</script>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_sanity_cleanup2.html b/testing/mochitest/tests/Harness_sanity/test_sanity_cleanup2.html
new file mode 100644
index 000000000..169d43a61
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_sanity_cleanup2.html
@@ -0,0 +1,24 @@
+<!-- Any copyright is dedicated to the Public Domain.
+ - http://creativecommons.org/publicdomain/zero/1.0/ -->
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>SimpleTest.registerCleanupFunction test</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 class="testbody" type="text/javascript">
+for (pref of [1, 2]) {
+ try {
+ SpecialPowers.getBoolPref("simpletest.cleanup." + pref);
+ ok(false, "Cleanup function should have unset pref");
+ }
+ catch(ex) {
+ ok(true, "Pref was not set");
+ }
+}
+
+</script>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_sanity_manifest.html b/testing/mochitest/tests/Harness_sanity/test_sanity_manifest.html
new file mode 100644
index 000000000..d8c791b4e
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_sanity_manifest.html
@@ -0,0 +1,16 @@
+<!-- Any copyright is dedicated to the Public Domain.
+ - http://creativecommons.org/publicdomain/zero/1.0/ -->
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>SimpleTest.expected = 'fail' test</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 class="testbody" type="text/javascript">
+ok(false, "We expect this to fail");
+
+</script>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_sanity_manifest_pf.html b/testing/mochitest/tests/Harness_sanity/test_sanity_manifest_pf.html
new file mode 100644
index 000000000..1f71fdd5a
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_sanity_manifest_pf.html
@@ -0,0 +1,17 @@
+<!-- Any copyright is dedicated to the Public Domain.
+ - http://creativecommons.org/publicdomain/zero/1.0/ -->
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>SimpleTest.expected = 'fail' test</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 class="testbody" type="text/javascript">
+ok(true, "We expect this to pass");
+ok(false, "We expect this to fail");
+
+</script>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_sanity_waitForCondition.html b/testing/mochitest/tests/Harness_sanity/test_sanity_waitForCondition.html
new file mode 100644
index 000000000..5ac1daf2e
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_sanity_waitForCondition.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="UTF-8">
+ <title>SimpleTest.waitForCondition test</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
+</head>
+<body>
+<script>
+
+var captureFailure = false;
+var capturedFailures = [];
+window.ok = function (cond, name, diag) {
+ if (!captureFailure) {
+ SimpleTest.ok(cond, name, diag);
+ } else {
+ if (cond) {
+ SimpleTest.ok(false, `Expect a failure with "${name}"`);
+ } else {
+ capturedFailures.push(name);
+ }
+ }
+};
+
+SimpleTest.waitForExplicitFinish();
+SimpleTest.requestFlakyTimeout("test behavior SimpleTest.waitForCondition");
+
+addLoadEvent(testNormal);
+
+function testNormal() {
+ var condition = false;
+ SimpleTest.waitForCondition(() => condition, () => {
+ ok(condition, "Should only be called when condition is true");
+ SimpleTest.executeSoon(testTimeout);
+ }, "Shouldn't timeout");
+ setTimeout(() => { condition = true; }, 1000);
+}
+
+function testTimeout() {
+ captureFailure = true;
+ SimpleTest.waitForCondition(() => false, () => {
+ captureFailure = false;
+ is(capturedFailures.length, 1, "Should captured one failure");
+ is(capturedFailures[0], "Should timeout",
+ "Should capture the failure passed in");
+ SimpleTest.executeSoon(() => SimpleTest.finish());
+ }, "Should timeout");
+}
+
+</script>
+</body>
+</html>
diff --git a/testing/mochitest/tests/Harness_sanity/test_spawn_task.html b/testing/mochitest/tests/Harness_sanity/test_spawn_task.html
new file mode 100644
index 000000000..326318746
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_spawn_task.html
@@ -0,0 +1,73 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for mochitest SpawnTask.js sanity</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug 1078657</a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/** Test for sanity **/
+SimpleTest.waitForExplicitFinish();
+
+var externalGeneratorFunction = function* () {
+ return 8;
+};
+
+var nestedFunction = function* () {
+ return yield function* () {
+ return yield function* () {
+ return yield function* () {
+ return yield Promise.resolve(9);
+ }();
+ }();
+ }();
+}
+
+var variousTests = function* () {
+ var val1 = yield [Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)];
+ is(val1.join(""), "123", "Array of promises -> Promise.all");
+ var val2 = yield Promise.resolve(2);
+ is(val2, 2, "Resolved promise yields value.");
+ var val3 = yield function* () { return 3; };
+ is(val3, 3, "Generator functions are spawned.");
+ //var val4 = yield function () { return 4; };
+ //is(val4, 4, "Plain functions run and return.");
+ var val5 = yield (function* () { return 5; }());
+ is(val5, 5, "Generators are spawned.");
+ try {
+ var val6 = yield Promise.reject(Error("error6"));
+ ok(false, "Shouldn't reach this line.");
+ } catch (error) {
+ is(error.message, "error6", "Rejected promise throws error.");
+ }
+ try {
+ var val7 = yield function* () { throw Error("error7"); };
+ ok(false, "Shouldn't reach this line.");
+ } catch (error) {
+ is(error.message, "error7", "Thrown error propagates.");
+ }
+ var val8 = yield externalGeneratorFunction();
+ is(val8, 8, "External generator also spawned.");
+ var val9 = yield nestedFunction();
+ is(val9, 9, "Nested generator functions work.");
+ return 10;
+};
+
+spawn_task(variousTests).then(function(result) {
+ is(result, 10, "spawn_task(...) returns promise");
+ SimpleTest.finish();
+});
+
+
+</script>
+</pre>
+</body>
+</html>
+