diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /toolkit/components/startup/tests/browser | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/startup/tests/browser')
7 files changed, 229 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..1698d533de --- /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" && 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..f009f2c941 --- /dev/null +++ b/toolkit/components/startup/tests/browser/browser_Telemetry_timestamp_test.js @@ -0,0 +1,35 @@ +"use strict"; + +const { TelemetryController } = ChromeUtils.importESModule( + "resource://gre/modules/TelemetryController.sys.mjs" +); +const { TelemetrySession } = ChromeUtils.importESModule( + "resource://gre/modules/TelemetrySession.sys.mjs" +); + +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..c080a1596f --- /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..4006869601 --- /dev/null +++ b/toolkit/components/startup/tests/browser/browser_bug537449.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"; + +SpecialPowers.pushPrefEnv({ + set: [["dom.require_user_interaction_for_beforeunload", 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..4ebc19f80e --- /dev/null +++ b/toolkit/components/startup/tests/browser/head.js @@ -0,0 +1,28 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { PromptTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/PromptTestUtils.sys.mjs" +); + +function whenBrowserLoaded(browser, callback) { + return BrowserTestUtils.browserLoaded(browser).then(callback); +} + +function waitForOnBeforeUnloadDialog(browser, callback) { + PromptTestUtils.waitForPrompt(browser, { + modalType: Services.prompt.MODAL_TYPE_CONTENT, + promptType: "confirmEx", + }).then(dialog => { + SimpleTest.waitForCondition( + () => Services.focus.activeWindow == browser.ownerGlobal, + function () { + let { button0, button1 } = dialog.ui; + callback(button0, button1); + }, + "Waited too long for window with dialog to focus" + ); + }); +} |