summaryrefslogtreecommitdiffstats
path: root/toolkit/components/startup/tests/browser
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /toolkit/components/startup/tests/browser
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/startup/tests/browser')
-rw-r--r--toolkit/components/startup/tests/browser/beforeunload.html10
-rw-r--r--toolkit/components/startup/tests/browser/browser.ini10
-rw-r--r--toolkit/components/startup/tests/browser/browser_Telemetry_timestamp_test.js31
-rw-r--r--toolkit/components/startup/tests/browser/browser_bug511456.js58
-rw-r--r--toolkit/components/startup/tests/browser/browser_bug537449.js62
-rw-r--r--toolkit/components/startup/tests/browser/browser_crash_detection.js30
-rw-r--r--toolkit/components/startup/tests/browser/head.js30
7 files changed, 231 insertions, 0 deletions
diff --git a/toolkit/components/startup/tests/browser/beforeunload.html b/toolkit/components/startup/tests/browser/beforeunload.html
new file mode 100644
index 0000000000..81fa1b57bc
--- /dev/null
+++ b/toolkit/components/startup/tests/browser/beforeunload.html
@@ -0,0 +1,10 @@
+<html>
+ <script>
+ window.onbeforeunload = function(event) {
+ event.returnValue = "Test beforeunload handler";
+ };
+ </script>
+ <body>
+ Test page
+ </body>
+</html>
diff --git a/toolkit/components/startup/tests/browser/browser.ini b/toolkit/components/startup/tests/browser/browser.ini
new file mode 100644
index 0000000000..2520709b05
--- /dev/null
+++ b/toolkit/components/startup/tests/browser/browser.ini
@@ -0,0 +1,10 @@
+[DEFAULT]
+support-files =
+ head.js
+ beforeunload.html
+
+[browser_bug511456.js]
+skip-if = (os == "linux" && !e10s) || (os == "linux" && bits == 64 && os_version == "18.04") # Bug 1334729, Bug 1546252; Bug 1582549
+[browser_bug537449.js]
+[browser_crash_detection.js]
+[browser_Telemetry_timestamp_test.js]
diff --git a/toolkit/components/startup/tests/browser/browser_Telemetry_timestamp_test.js b/toolkit/components/startup/tests/browser/browser_Telemetry_timestamp_test.js
new file mode 100644
index 0000000000..f9b044dbe0
--- /dev/null
+++ b/toolkit/components/startup/tests/browser/browser_Telemetry_timestamp_test.js
@@ -0,0 +1,31 @@
+"use strict";
+
+ChromeUtils.import("resource://gre/modules/TelemetryController.jsm", this);
+ChromeUtils.import("resource://gre/modules/TelemetrySession.jsm", this);
+
+add_task(async function test() {
+ let now = Services.telemetry.msSinceProcessStart();
+ let payload = TelemetrySession.getPayload("main");
+
+ // Check the first_paint scalar.
+ ok(
+ "scalars" in payload.processes.parent,
+ "Scalars are present in the payload."
+ );
+ ok(
+ "timestamps.first_paint" in payload.processes.parent.scalars,
+ "The first_paint timestamp is present in the payload."
+ );
+ Assert.greater(
+ payload.processes.parent.scalars["timestamps.first_paint"],
+ 0,
+ "first_paint scalar is greater than 0."
+ );
+ Assert.greater(now, 0, "Browser test runtime is greater than zero.");
+ // Check that the first_paint scalar is less than the current time.
+ Assert.greater(
+ now,
+ payload.processes.parent.scalars["timestamps.first_paint"],
+ "first_paint is less than total browser test runtime."
+ );
+});
diff --git a/toolkit/components/startup/tests/browser/browser_bug511456.js b/toolkit/components/startup/tests/browser/browser_bug511456.js
new file mode 100644
index 0000000000..d8b99417d0
--- /dev/null
+++ b/toolkit/components/startup/tests/browser/browser_bug511456.js
@@ -0,0 +1,58 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const TEST_URL =
+ "http://example.com/browser/toolkit/components/startup/tests/browser/beforeunload.html";
+
+SpecialPowers.pushPrefEnv({
+ set: [["dom.require_user_interaction_for_beforeunload", false]],
+});
+
+function test() {
+ waitForExplicitFinish();
+ ignoreAllUncaughtExceptions();
+
+ // Create foreground window
+ let win2 = window.openDialog(
+ location,
+ "",
+ "chrome,all,dialog=no",
+ "about:blank"
+ );
+ win2.addEventListener(
+ "load",
+ function() {
+ // Create background test tab
+ let browser = BrowserTestUtils.addTab(gBrowser, TEST_URL).linkedBrowser;
+
+ whenBrowserLoaded(browser, function() {
+ let seenDialog = false;
+
+ // Cancel the prompt the first time.
+ waitForOnBeforeUnloadDialog(browser, (btnLeave, btnStay) => {
+ seenDialog =
+ Services.focus.activeWindow == window &&
+ gBrowser.selectedBrowser == browser;
+ btnStay.click();
+ });
+
+ Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit);
+ ok(seenDialog, "Should have seen a prompt dialog");
+ ok(!win2.closed, "Shouldn't have closed the additional window");
+ win2.close();
+
+ // Leave the page the second time.
+ waitForOnBeforeUnloadDialog(browser, (btnLeave, btnStay) => {
+ btnLeave.click();
+ });
+
+ gBrowser.removeTab(gBrowser.selectedTab);
+ executeSoon(finish);
+ });
+ },
+ { once: true }
+ );
+}
diff --git a/toolkit/components/startup/tests/browser/browser_bug537449.js b/toolkit/components/startup/tests/browser/browser_bug537449.js
new file mode 100644
index 0000000000..ecadcf70a1
--- /dev/null
+++ b/toolkit/components/startup/tests/browser/browser_bug537449.js
@@ -0,0 +1,62 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+SpecialPowers.pushPrefEnv({
+ set: [["dom.require_user_interaction_for_beforeunload", false]],
+});
+
+SpecialPowers.pushPrefEnv({
+ set: [["prompts.contentPromptSubDialog", false]],
+});
+
+const TEST_URL =
+ "http://example.com/browser/toolkit/components/startup/tests/browser/beforeunload.html";
+
+function test() {
+ waitForExplicitFinish();
+
+ gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, TEST_URL);
+ let browser = gBrowser.selectedBrowser;
+
+ whenBrowserLoaded(browser, function() {
+ let seenDialog = false;
+
+ // Cancel the prompt the first time.
+ waitForOnBeforeUnloadDialog(browser, (btnLeave, btnStay) => {
+ seenDialog = true;
+ btnStay.click();
+ });
+
+ Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit);
+ ok(seenDialog, "Should have seen a prompt dialog");
+ ok(!window.closed, "Shouldn't have closed the window");
+
+ let win2 = window.openDialog(
+ location,
+ "",
+ "chrome,all,dialog=no",
+ "about:blank"
+ );
+ ok(win2 != null, "Should have been able to open a new window");
+ win2.addEventListener(
+ "load",
+ () => {
+ executeSoon(() => {
+ win2.close();
+
+ // Leave the page the second time.
+ waitForOnBeforeUnloadDialog(browser, (btnLeave, btnStay) => {
+ btnLeave.click();
+ });
+
+ gBrowser.removeTab(gBrowser.selectedTab);
+ finish();
+ });
+ },
+ { once: true }
+ );
+ });
+}
diff --git a/toolkit/components/startup/tests/browser/browser_crash_detection.js b/toolkit/components/startup/tests/browser/browser_crash_detection.js
new file mode 100644
index 0000000000..a53669452d
--- /dev/null
+++ b/toolkit/components/startup/tests/browser/browser_crash_detection.js
@@ -0,0 +1,30 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+/* eslint-disable mozilla/no-arbitrary-setTimeout */
+
+function test() {
+ function checkLastSuccess() {
+ let lastSuccess = Services.prefs.getIntPref("toolkit.startup.last_success");
+ let si = Services.startup.getStartupInfo();
+ is(
+ lastSuccess,
+ parseInt(si.main.getTime() / 1000, 10),
+ "Startup tracking pref should be set after a delay at the end of startup"
+ );
+ finish();
+ }
+
+ if (
+ Services.prefs.getPrefType("toolkit.startup.max_resumed_crashes") ==
+ Services.prefs.PREF_INVALID
+ ) {
+ info("Skipping this test since startup crash detection is disabled");
+ return;
+ }
+
+ const startupCrashEndDelay = 35 * 1000;
+ waitForExplicitFinish();
+ requestLongerTimeout(2);
+ setTimeout(checkLastSuccess, startupCrashEndDelay);
+}
diff --git a/toolkit/components/startup/tests/browser/head.js b/toolkit/components/startup/tests/browser/head.js
new file mode 100644
index 0000000000..55c4528e13
--- /dev/null
+++ b/toolkit/components/startup/tests/browser/head.js
@@ -0,0 +1,30 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+SpecialPowers.pushPrefEnv({
+ set: [["prompts.contentPromptSubDialog", false]],
+});
+
+function whenBrowserLoaded(browser, callback) {
+ return BrowserTestUtils.browserLoaded(browser).then(callback);
+}
+
+function waitForOnBeforeUnloadDialog(browser, callback) {
+ browser.addEventListener(
+ "DOMWillOpenModalDialog",
+ function onModalDialog(event) {
+ SimpleTest.waitForCondition(
+ () => Services.focus.activeWindow == browser.ownerGlobal,
+ function() {
+ let prompt = browser.tabModalPromptBox.listPrompts()[0];
+ let { button0, button1 } = prompt.ui;
+ callback(button0, button1);
+ },
+ "Waited too long for window with dialog to focus"
+ );
+ },
+ { capture: true, once: true }
+ );
+}