summaryrefslogtreecommitdiffstats
path: root/testing/mochitest/tests/browser
diff options
context:
space:
mode:
Diffstat (limited to 'testing/mochitest/tests/browser')
-rw-r--r--testing/mochitest/tests/browser/browser.ini49
-rw-r--r--testing/mochitest/tests/browser/browser_BrowserTestUtils.js70
-rw-r--r--testing/mochitest/tests/browser/browser_add_task.js31
-rw-r--r--testing/mochitest/tests/browser/browser_async.js8
-rw-r--r--testing/mochitest/tests/browser/browser_browserLoaded_content_loaded.js46
-rw-r--r--testing/mochitest/tests/browser/browser_fail.js8
-rw-r--r--testing/mochitest/tests/browser/browser_fail_add_task.js57
-rw-r--r--testing/mochitest/tests/browser/browser_fail_async_throw.js7
-rw-r--r--testing/mochitest/tests/browser/browser_fail_fp.js4
-rw-r--r--testing/mochitest/tests/browser/browser_fail_pf.js4
-rw-r--r--testing/mochitest/tests/browser/browser_fail_throw.js3
-rw-r--r--testing/mochitest/tests/browser/browser_fail_timeout.js8
-rw-r--r--testing/mochitest/tests/browser/browser_fail_unexpectedTimeout.js12
-rw-r--r--testing/mochitest/tests/browser/browser_getTestFile.js44
-rw-r--r--testing/mochitest/tests/browser/browser_head.js12
-rw-r--r--testing/mochitest/tests/browser/browser_parameters.js4
-rw-r--r--testing/mochitest/tests/browser/browser_pass.js13
-rw-r--r--testing/mochitest/tests/browser/browser_popupNode.js4
-rw-r--r--testing/mochitest/tests/browser/browser_popupNode_check.js3
-rw-r--r--testing/mochitest/tests/browser/browser_privileges.js16
-rw-r--r--testing/mochitest/tests/browser/browser_requestLongerTimeout.js9
-rw-r--r--testing/mochitest/tests/browser/browser_sanityException.js5
-rw-r--r--testing/mochitest/tests/browser/browser_sanityException2.js11
-rw-r--r--testing/mochitest/tests/browser/browser_waitForFocus.js69
-rw-r--r--testing/mochitest/tests/browser/browser_zz_fail_openwindow.js12
-rw-r--r--testing/mochitest/tests/browser/dummy.html6
-rw-r--r--testing/mochitest/tests/browser/head.js12
-rw-r--r--testing/mochitest/tests/browser/test-dir/test-file1
-rw-r--r--testing/mochitest/tests/browser/waitForFocusPage.html4
29 files changed, 532 insertions, 0 deletions
diff --git a/testing/mochitest/tests/browser/browser.ini b/testing/mochitest/tests/browser/browser.ini
new file mode 100644
index 000000000..091ccb68e
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser.ini
@@ -0,0 +1,49 @@
+[DEFAULT]
+support-files =
+ head.js
+
+[browser_browserLoaded_content_loaded.js]
+[browser_add_task.js]
+[browser_async.js]
+[browser_BrowserTestUtils.js]
+support-files =
+ dummy.html
+[browser_head.js]
+[browser_pass.js]
+[browser_parameters.js]
+[browser_popupNode.js]
+[browser_popupNode_check.js]
+[browser_privileges.js]
+[browser_sanityException.js]
+[browser_sanityException2.js]
+[browser_waitForFocus.js]
+skip-if = (os == "win" && e10s && debug)
+[browser_getTestFile.js]
+support-files =
+ test-dir/*
+ waitForFocusPage.html
+
+# Disabled because it would take too long, useful to check functionality though.
+# browser_requestLongerTimeout.js
+[browser_zz_fail_openwindow.js]
+skip-if = true # this catches outside of the main loop to find an extra window
+[browser_fail.js]
+skip-if = true
+[browser_fail_add_task.js]
+skip-if = true # fail-if doesnt catch an exception outside the test
+[browser_fail_async_throw.js]
+skip-if = true # fail-if doesnt catch an exception outside the test
+[browser_fail_fp.js]
+fail-if = true
+[browser_fail_pf.js]
+fail-if = true
+[browser_fail_throw.js]
+skip-if = true # fail-if doesnt catch an exception outside the test
+
+# Disabled beacuse it takes too long (bug 1178959)
+[browser_fail_timeout.js]
+skip-if = true
+# Disabled beacuse it takes too long (bug 1178959)
+[browser_fail_unexpectedTimeout.js]
+skip-if = true
+
diff --git a/testing/mochitest/tests/browser/browser_BrowserTestUtils.js b/testing/mochitest/tests/browser/browser_BrowserTestUtils.js
new file mode 100644
index 000000000..0b3700263
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_BrowserTestUtils.js
@@ -0,0 +1,70 @@
+function getLastEventDetails(browser)
+{
+ return ContentTask.spawn(browser, {}, function* () {
+ return content.document.getElementById('out').textContent;
+ });
+}
+
+add_task(function* () {
+ let onClickEvt = 'document.getElementById("out").textContent = event.target.localName + "," + event.clientX + "," + event.clientY;'
+ const url = "<body onclick='" + onClickEvt + "' style='margin: 0'>" +
+ "<button id='one' style='margin: 0; margin-left: 16px; margin-top: 14px; width: 30px; height: 40px;'>Test</button>" +
+ "<div onmousedown='event.preventDefault()' style='margin: 0; width: 80px; height: 60px;'>Other</div>" +
+ "<span id='out'></span></body>";
+ let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "data:text/html," + url);
+
+ let browser = tab.linkedBrowser;
+ yield BrowserTestUtils.synthesizeMouseAtCenter("#one", {}, browser);
+ let details = yield getLastEventDetails(browser);
+
+ is(details, "button,31,34", "synthesizeMouseAtCenter");
+
+ yield BrowserTestUtils.synthesizeMouse("#one", 4, 9, {}, browser);
+ details = yield getLastEventDetails(browser);
+ is(details, "button,20,23", "synthesizeMouse");
+
+ yield BrowserTestUtils.synthesizeMouseAtPoint(15, 6, {}, browser);
+ details = yield getLastEventDetails(browser);
+ is(details, "body,15,6", "synthesizeMouseAtPoint on body");
+
+ yield BrowserTestUtils.synthesizeMouseAtPoint(20, 22, {}, browser);
+ details = yield getLastEventDetails(browser);
+ is(details, "button,20,22", "synthesizeMouseAtPoint on button");
+
+ yield BrowserTestUtils.synthesizeMouseAtCenter("body > div", {}, browser);
+ details = yield getLastEventDetails(browser);
+ is(details, "div,40,84", "synthesizeMouseAtCenter with complex selector");
+
+ let cancelled = yield BrowserTestUtils.synthesizeMouseAtCenter("body > div", { type: "mousedown" }, browser);
+ details = yield getLastEventDetails(browser);
+ is(details, "div,40,84", "synthesizeMouseAtCenter mousedown with complex selector");
+ ok(cancelled, "synthesizeMouseAtCenter mousedown with complex selector not cancelled");
+
+ cancelled = yield BrowserTestUtils.synthesizeMouseAtCenter("body > div", { type: "mouseup" }, browser);
+ details = yield getLastEventDetails(browser);
+ is(details, "div,40,84", "synthesizeMouseAtCenter mouseup with complex selector");
+ ok(!cancelled, "synthesizeMouseAtCenter mouseup with complex selector cancelled");
+
+ gBrowser.removeTab(tab);
+});
+
+add_task(function* () {
+ yield BrowserTestUtils.registerAboutPage(
+ registerCleanupFunction, "about-pages-are-cool",
+ getRootDirectory(gTestPath) + "dummy.html", 0);
+ let tab = yield BrowserTestUtils.openNewForegroundTab(
+ gBrowser, "about:about-pages-are-cool", true);
+ ok(tab, "Successfully created an about: page and loaded it.");
+ yield BrowserTestUtils.removeTab(tab);
+ try {
+ yield BrowserTestUtils.unregisterAboutPage("about-pages-are-cool");
+ ok(true, "Successfully unregistered the about page.");
+ } catch (ex) {
+ ok(false, "Should not throw unregistering a known about: page");
+ }
+ yield BrowserTestUtils.unregisterAboutPage("random-other-about-page").then(() => {
+ ok(false, "Should not have succeeded unregistering an unknown about: page.");
+ }, () => {
+ ok(true, "Should have returned a rejected promise trying to unregister an unknown about page");
+ });
+});
diff --git a/testing/mochitest/tests/browser/browser_add_task.js b/testing/mochitest/tests/browser/browser_add_task.js
new file mode 100644
index 000000000..5318b09d4
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_add_task.js
@@ -0,0 +1,31 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+var test1Complete = false;
+var test2Complete = false;
+
+function executeWithTimeout() {
+ return new Promise(resolve =>
+ executeSoon(function() {
+ ok(true, "we get here after a timeout");
+ resolve();
+ })
+ );
+}
+
+add_task(function* asyncTest_no1() {
+ yield executeWithTimeout();
+ test1Complete = true;
+});
+
+add_task(function* asyncTest_no2() {
+ yield executeWithTimeout();
+ test2Complete = true;
+});
+
+add_task(function() {
+ ok(test1Complete, "We have been through test 1");
+ ok(test2Complete, "We have been through test 2");
+});
diff --git a/testing/mochitest/tests/browser/browser_async.js b/testing/mochitest/tests/browser/browser_async.js
new file mode 100644
index 000000000..51ba0700e
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_async.js
@@ -0,0 +1,8 @@
+function test() {
+ waitForExplicitFinish();
+ function done() {
+ ok(true, "timeout ran");
+ finish();
+ }
+ setTimeout(done, 10000);
+}
diff --git a/testing/mochitest/tests/browser/browser_browserLoaded_content_loaded.js b/testing/mochitest/tests/browser/browser_browserLoaded_content_loaded.js
new file mode 100644
index 000000000..5de7794f5
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_browserLoaded_content_loaded.js
@@ -0,0 +1,46 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+'use strict';
+
+function isDOMLoaded(browser) {
+ return ContentTask.spawn(browser, null, function*() {
+ Assert.equal(content.document.readyState, "complete",
+ "Browser should be loaded.");
+ });
+}
+
+// It checks if calling BrowserTestUtils.browserLoaded() yields
+// browser object.
+add_task(function*() {
+ let tab = gBrowser.addTab('http://example.com');
+ let browser = tab.linkedBrowser;
+ yield BrowserTestUtils.browserLoaded(browser);
+ yield isDOMLoaded(browser);
+ gBrowser.removeTab(tab);
+});
+
+// It checks that BrowserTestUtils.browserLoaded() works well with
+// promise.all().
+add_task(function*() {
+ let tabURLs = [
+ `http://example.org`,
+ `http://mochi.test:8888`,
+ `http://test:80`,
+ ];
+ //Add tabs, get the respective browsers
+ let browsers = [
+ for (u of tabURLs) gBrowser.addTab(u).linkedBrowser
+ ];
+ //wait for promises to settle
+ yield Promise.all((
+ for (b of browsers) BrowserTestUtils.browserLoaded(b)
+ ));
+ let expected = 'Expected all promised browsers to have loaded.';
+ for (const browser of browsers) {
+ yield isDOMLoaded(browser);
+ }
+ //cleanup
+ browsers
+ .map(browser => gBrowser.getTabForBrowser(browser))
+ .forEach(tab => gBrowser.removeTab(tab));
+});
diff --git a/testing/mochitest/tests/browser/browser_fail.js b/testing/mochitest/tests/browser/browser_fail.js
new file mode 100644
index 000000000..3d91439ea
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_fail.js
@@ -0,0 +1,8 @@
+function test() {
+ ok(false, "fail ok");
+ is(true, false, "fail is");
+ isnot(true, true, "fail isnot");
+ todo(true, "fail todo");
+ todo_is(true, true, "fail todo_is");
+ todo_isnot(true, false, "fail todo_isnot");
+}
diff --git a/testing/mochitest/tests/browser/browser_fail_add_task.js b/testing/mochitest/tests/browser/browser_fail_add_task.js
new file mode 100644
index 000000000..9ef20f7c7
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_fail_add_task.js
@@ -0,0 +1,57 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// This test is designed to fail.
+// It ensures that throwing an asynchronous error from add_task will
+// fail the test.
+
+var passedTests = 0;
+
+function rejectWithTimeout(error = undefined) {
+ let deferred = Promise.defer();
+ executeSoon(function() {
+ ok(true, "we get here after a timeout");
+ deferred.reject(error);
+ });
+ return deferred.promise;
+}
+
+add_task(function failWithoutError() {
+ try {
+ yield rejectWithTimeout();
+ } finally {
+ ++passedTests;
+ }
+});
+
+add_task(function failWithString() {
+ try {
+ yield rejectWithTimeout("Meaningless error");
+ } finally {
+ ++passedTests;
+ }
+});
+
+add_task(function failWithoutInt() {
+ try {
+ yield rejectWithTimeout(42);
+ } finally {
+ ++passedTests;
+ }
+});
+
+
+// This one should display a stack trace
+add_task(function failWithError() {
+ try {
+ yield rejectWithTimeout(new Error("This is an error"));
+ } finally {
+ ++passedTests;
+ }
+});
+
+add_task(function done() {
+ is(passedTests, 4, "Passed all tests");
+});
diff --git a/testing/mochitest/tests/browser/browser_fail_async_throw.js b/testing/mochitest/tests/browser/browser_fail_async_throw.js
new file mode 100644
index 000000000..201cb241e
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_fail_async_throw.js
@@ -0,0 +1,7 @@
+function test() {
+ function end() {
+ throw "thrown exception";
+ }
+ waitForExplicitFinish();
+ setTimeout(end, 1000);
+}
diff --git a/testing/mochitest/tests/browser/browser_fail_fp.js b/testing/mochitest/tests/browser/browser_fail_fp.js
new file mode 100644
index 000000000..04cae37cd
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_fail_fp.js
@@ -0,0 +1,4 @@
+function test() {
+ ok(false, "first fail ok");
+ ok(true, "then pass ok");
+}
diff --git a/testing/mochitest/tests/browser/browser_fail_pf.js b/testing/mochitest/tests/browser/browser_fail_pf.js
new file mode 100644
index 000000000..88ed1d949
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_fail_pf.js
@@ -0,0 +1,4 @@
+function test() {
+ ok(true, "first pass ok");
+ ok(false, "then fail ok");
+}
diff --git a/testing/mochitest/tests/browser/browser_fail_throw.js b/testing/mochitest/tests/browser/browser_fail_throw.js
new file mode 100644
index 000000000..aee0238df
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_fail_throw.js
@@ -0,0 +1,3 @@
+function test() {
+ throw "thrown exception";
+}
diff --git a/testing/mochitest/tests/browser/browser_fail_timeout.js b/testing/mochitest/tests/browser/browser_fail_timeout.js
new file mode 100644
index 000000000..6b99693d9
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_fail_timeout.js
@@ -0,0 +1,8 @@
+function test() {
+ function end() {
+ ok(false, "should have timed out");
+ finish();
+ }
+ waitForExplicitFinish();
+ setTimeout(end, 40000);
+}
diff --git a/testing/mochitest/tests/browser/browser_fail_unexpectedTimeout.js b/testing/mochitest/tests/browser/browser_fail_unexpectedTimeout.js
new file mode 100644
index 000000000..2175eea27
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_fail_unexpectedTimeout.js
@@ -0,0 +1,12 @@
+function test() {
+ function message() {
+ info("This should delay timeout");
+ }
+ function end() {
+ ok(true, "Should have not timed out, but notified long running test");
+ finish();
+ }
+ waitForExplicitFinish();
+ setTimeout(message, 20000);
+ setTimeout(end, 40000);
+}
diff --git a/testing/mochitest/tests/browser/browser_getTestFile.js b/testing/mochitest/tests/browser/browser_getTestFile.js
new file mode 100644
index 000000000..99456b633
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_getTestFile.js
@@ -0,0 +1,44 @@
+function test() {
+ let {Promise} = Components.utils.import("resource://gre/modules/Promise.jsm");
+ Components.utils.import("resource://gre/modules/osfile.jsm");
+ let decoder = new TextDecoder();
+
+ waitForExplicitFinish();
+
+ SimpleTest.doesThrow(function () {
+ getTestFilePath("/browser_getTestFile.js")
+ }, "getTestFilePath rejects absolute paths");
+
+ Promise.all([
+ OS.File.exists(getTestFilePath("browser_getTestFile.js"))
+ .then(function (exists) {
+ ok(exists, "getTestFilePath consider the path as being relative");
+ }),
+
+ OS.File.exists(getTestFilePath("./browser_getTestFile.js"))
+ .then(function (exists) {
+ ok(exists, "getTestFilePath also accepts explicit relative path");
+ }),
+
+ OS.File.exists(getTestFilePath("./browser_getTestFileTypo.xul"))
+ .then(function (exists) {
+ ok(!exists, "getTestFilePath do not throw if the file doesn't exists");
+ }),
+
+ OS.File.read(getTestFilePath("test-dir/test-file"))
+ .then(function (array) {
+ is(decoder.decode(array), "foo\n", "getTestFilePath can reach sub-folder files 1/2");
+ }),
+
+ OS.File.read(getTestFilePath("./test-dir/test-file"))
+ .then(function (array) {
+ is(decoder.decode(array), "foo\n", "getTestFilePath can reach sub-folder files 2/2");
+ })
+
+ ]).then(function () {
+ finish();
+ }, function (error) {
+ ok(false, error);
+ finish();
+ });
+}
diff --git a/testing/mochitest/tests/browser/browser_head.js b/testing/mochitest/tests/browser/browser_head.js
new file mode 100644
index 000000000..0e1f7dd25
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_head.js
@@ -0,0 +1,12 @@
+var testVar;
+
+registerCleanupFunction(function() {
+ ok(true, "I'm a cleanup function in test file");
+ is(this.testVar, "I'm a var in test file", "Test cleanup function scope is correct");
+});
+
+function test() {
+ is(headVar, "I'm a var in head file", "Head variables are set");
+ ok(headMethod(), "Head methods are imported");
+ testVar = "I'm a var in test file";
+}
diff --git a/testing/mochitest/tests/browser/browser_parameters.js b/testing/mochitest/tests/browser/browser_parameters.js
new file mode 100644
index 000000000..32ba82d92
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_parameters.js
@@ -0,0 +1,4 @@
+function test() {
+ ok(SimpleTest.harnessParameters, "Should have parameters");
+}
+
diff --git a/testing/mochitest/tests/browser/browser_pass.js b/testing/mochitest/tests/browser/browser_pass.js
new file mode 100644
index 000000000..dbdfa1f17
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_pass.js
@@ -0,0 +1,13 @@
+function test() {
+ SimpleTest.requestCompleteLog();
+ ok(true, "pass ok");
+ is(true, true, "pass is");
+ isnot(false, true, "pass isnot");
+ todo(false, "pass todo");
+ todo_is(false, true, "pass todo_is");
+ todo_isnot(true, true, "pass todo_isnot");
+ info("info message");
+
+ var func = is;
+ func(true, 1, "pass indirect is");
+}
diff --git a/testing/mochitest/tests/browser/browser_popupNode.js b/testing/mochitest/tests/browser/browser_popupNode.js
new file mode 100644
index 000000000..c6042011c
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_popupNode.js
@@ -0,0 +1,4 @@
+function test() {
+ document.popupNode = document;
+ isnot(document.popupNode, null, "document.popupNode has been correctly set");
+}
diff --git a/testing/mochitest/tests/browser/browser_popupNode_check.js b/testing/mochitest/tests/browser/browser_popupNode_check.js
new file mode 100644
index 000000000..fb85378d9
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_popupNode_check.js
@@ -0,0 +1,3 @@
+function test() {
+ is(document.popupNode, null, "document.popupNode has been correctly cleared");
+}
diff --git a/testing/mochitest/tests/browser/browser_privileges.js b/testing/mochitest/tests/browser/browser_privileges.js
new file mode 100644
index 000000000..7b6b1978c
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_privileges.js
@@ -0,0 +1,16 @@
+function test() {
+ // simple test to confirm we have chrome privileges
+ let hasPrivileges = true;
+
+ // this will throw an exception if we are not running with privileges
+ try {
+ var prefs = Components.classes["@mozilla.org/preferences-service;1"].
+ getService(Components.interfaces.nsIPrefBranch);
+ }
+ catch (e) {
+ hasPrivileges = false;
+ }
+
+ // if we get here, we must have chrome privileges
+ ok(hasPrivileges, "running with chrome privileges");
+}
diff --git a/testing/mochitest/tests/browser/browser_requestLongerTimeout.js b/testing/mochitest/tests/browser/browser_requestLongerTimeout.js
new file mode 100644
index 000000000..cb53e13a2
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_requestLongerTimeout.js
@@ -0,0 +1,9 @@
+function test() {
+ requestLongerTimeout(2);
+ function end() {
+ ok(true, "should not time out");
+ finish();
+ }
+ waitForExplicitFinish();
+ setTimeout(end, 40000);
+}
diff --git a/testing/mochitest/tests/browser/browser_sanityException.js b/testing/mochitest/tests/browser/browser_sanityException.js
new file mode 100644
index 000000000..2039946f9
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_sanityException.js
@@ -0,0 +1,5 @@
+function test() {
+ ok(true, "ok called");
+ expectUncaughtException();
+ throw "this is a deliberately thrown exception";
+}
diff --git a/testing/mochitest/tests/browser/browser_sanityException2.js b/testing/mochitest/tests/browser/browser_sanityException2.js
new file mode 100644
index 000000000..0b9296041
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_sanityException2.js
@@ -0,0 +1,11 @@
+function test() {
+ waitForExplicitFinish();
+ ok(true, "ok called");
+ executeSoon(function() {
+ expectUncaughtException();
+ throw "this is a deliberately thrown exception";
+ });
+ executeSoon(function() {
+ finish();
+ });
+}
diff --git a/testing/mochitest/tests/browser/browser_waitForFocus.js b/testing/mochitest/tests/browser/browser_waitForFocus.js
new file mode 100644
index 000000000..8f9e27586
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_waitForFocus.js
@@ -0,0 +1,69 @@
+
+const gBaseURL = "https://example.com/browser/testing/mochitest/tests/browser/";
+
+function *promiseTabLoadEvent(tab, url)
+{
+ return new Promise(function (resolve, reject) {
+ function handleLoadEvent(event) {
+ if (event.originalTarget != tab.linkedBrowser.contentDocument ||
+ event.target.location.href == "about:blank" ||
+ (url && event.target.location.href != url)) {
+ return;
+ }
+
+ tab.linkedBrowser.removeEventListener("load", handleLoadEvent, true);
+ resolve(event);
+ }
+
+ tab.linkedBrowser.addEventListener("load", handleLoadEvent, true, true);
+ if (url)
+ tab.linkedBrowser.loadURI(url);
+ });
+}
+
+// Load a new blank tab
+add_task(function *() {
+ yield BrowserTestUtils.openNewForegroundTab(gBrowser);
+
+ gURLBar.focus();
+
+ let browser = gBrowser.selectedBrowser;
+ yield SimpleTest.promiseFocus(browser.contentWindowAsCPOW, true);
+
+ is(document.activeElement, browser, "Browser is focused when about:blank is loaded");
+
+ gBrowser.removeCurrentTab();
+ gURLBar.focus();
+});
+
+// Load a tab with a subframe inside it and wait until the subframe is focused
+add_task(function *() {
+ let tab = gBrowser.addTab();
+ gBrowser.selectedTab = tab;
+
+ let browser = gBrowser.getBrowserForTab(tab);
+ yield promiseTabLoadEvent(tab, gBaseURL + "waitForFocusPage.html");
+
+ yield SimpleTest.promiseFocus(browser.contentWindowAsCPOW);
+
+ is(document.activeElement, browser, "Browser is focused when page is loaded");
+
+ yield SimpleTest.promiseFocus(browser.contentWindowAsCPOW.frames[0]);
+
+ is(browser.contentWindowAsCPOW.document.activeElement.localName, "iframe", "Child iframe is focused");
+
+ gBrowser.removeCurrentTab();
+});
+
+// Pass a browser to promiseFocus
+add_task(function *() {
+ yield BrowserTestUtils.openNewForegroundTab(gBrowser, gBaseURL + "waitForFocusPage.html");
+
+ gURLBar.focus();
+
+ yield SimpleTest.promiseFocus(gBrowser.selectedBrowser);
+
+ is(document.activeElement, gBrowser.selectedBrowser, "Browser is focused when promiseFocus is passed a browser");
+
+ gBrowser.removeCurrentTab();
+});
diff --git a/testing/mochitest/tests/browser/browser_zz_fail_openwindow.js b/testing/mochitest/tests/browser/browser_zz_fail_openwindow.js
new file mode 100644
index 000000000..e9fe71d14
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_zz_fail_openwindow.js
@@ -0,0 +1,12 @@
+function test() {
+ waitForExplicitFinish();
+ function done() {
+ ok(true, "timeout ran");
+ finish();
+ }
+
+ ok(OpenBrowserWindow(), "opened browser window");
+ // and didn't close it!
+
+ setTimeout(done, 10000);
+}
diff --git a/testing/mochitest/tests/browser/dummy.html b/testing/mochitest/tests/browser/dummy.html
new file mode 100644
index 000000000..c49925c19
--- /dev/null
+++ b/testing/mochitest/tests/browser/dummy.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+ <title>This is a dummy page</title>
+ <meta charset="utf-8">
+ <body>This is a dummy page</body>
+</html>
diff --git a/testing/mochitest/tests/browser/head.js b/testing/mochitest/tests/browser/head.js
new file mode 100644
index 000000000..279333791
--- /dev/null
+++ b/testing/mochitest/tests/browser/head.js
@@ -0,0 +1,12 @@
+var headVar = "I'm a var in head file";
+
+function headMethod() {
+ return true;
+};
+
+ok(true, "I'm a test in head file");
+
+registerCleanupFunction(function() {
+ ok(true, "I'm a cleanup function in head file");
+ is(this.headVar, "I'm a var in head file", "Head cleanup function scope is correct");
+});
diff --git a/testing/mochitest/tests/browser/test-dir/test-file b/testing/mochitest/tests/browser/test-dir/test-file
new file mode 100644
index 000000000..257cc5642
--- /dev/null
+++ b/testing/mochitest/tests/browser/test-dir/test-file
@@ -0,0 +1 @@
+foo
diff --git a/testing/mochitest/tests/browser/waitForFocusPage.html b/testing/mochitest/tests/browser/waitForFocusPage.html
new file mode 100644
index 000000000..286ad7849
--- /dev/null
+++ b/testing/mochitest/tests/browser/waitForFocusPage.html
@@ -0,0 +1,4 @@
+<body>
+ <input>
+ <iframe id="f" src="data:text/plain,Test" width=80 height=80></iframe>
+</body>