summaryrefslogtreecommitdiffstats
path: root/toolkit/components/aboutperformance/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/aboutperformance/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/aboutperformance/tests/browser')
-rw-r--r--toolkit/components/aboutperformance/tests/browser/browser.ini7
-rw-r--r--toolkit/components/aboutperformance/tests/browser/browser_aboutperformance.js106
-rw-r--r--toolkit/components/aboutperformance/tests/browser/browser_compartments.html21
-rw-r--r--toolkit/components/aboutperformance/tests/browser/browser_compartments_frame.html13
-rw-r--r--toolkit/components/aboutperformance/tests/browser/browser_compartments_script.js11
5 files changed, 158 insertions, 0 deletions
diff --git a/toolkit/components/aboutperformance/tests/browser/browser.ini b/toolkit/components/aboutperformance/tests/browser/browser.ini
new file mode 100644
index 0000000000..c36144fc2a
--- /dev/null
+++ b/toolkit/components/aboutperformance/tests/browser/browser.ini
@@ -0,0 +1,7 @@
+[DEFAULT]
+support-files =
+ browser_compartments.html
+ browser_compartments_frame.html
+ browser_compartments_script.js
+
+[browser_aboutperformance.js]
diff --git a/toolkit/components/aboutperformance/tests/browser/browser_aboutperformance.js b/toolkit/components/aboutperformance/tests/browser/browser_aboutperformance.js
new file mode 100644
index 0000000000..ae4e1d0bae
--- /dev/null
+++ b/toolkit/components/aboutperformance/tests/browser/browser_aboutperformance.js
@@ -0,0 +1,106 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const URL =
+ "http://example.com/browser/toolkit/components/aboutperformance/tests/browser/browser_compartments.html?test=" +
+ Math.random();
+
+add_task(async function init() {
+ info("Setting up about:performance");
+ let tabAboutPerformance = (gBrowser.selectedTab = BrowserTestUtils.addTab(
+ gBrowser,
+ "about:performance"
+ ));
+
+ await BrowserTestUtils.browserLoaded(tabAboutPerformance.linkedBrowser);
+
+ info(`Setting up ${URL}`);
+ let tabContent = BrowserTestUtils.addTab(gBrowser, URL);
+ await BrowserTestUtils.browserLoaded(tabContent.linkedBrowser);
+
+ let doc = tabAboutPerformance.linkedBrowser.contentDocument;
+ let tbody = doc.getElementById("dispatch-tbody");
+
+ // Wait until the table has first been populated.
+ await TestUtils.waitForCondition(() => tbody.childElementCount);
+
+ // And wait for another update using a mutation observer, to give our newly created test tab some time
+ // to burn some CPU.
+ await new Promise(resolve => {
+ let observer = new doc.ownerGlobal.MutationObserver(() => {
+ observer.disconnect();
+ resolve();
+ });
+ observer.observe(tbody, { childList: true });
+ });
+
+ // Find the row for our test tab.
+ let row = tbody.firstChild;
+ while (
+ row &&
+ row.firstChild.textContent !=
+ "Main frame for test browser_aboutperformance.js"
+ ) {
+ row = row.nextSibling;
+ }
+
+ Assert.ok(row, "found a table row for our test tab");
+ Assert.equal(
+ row.windowId,
+ tabContent.linkedBrowser.outerWindowID,
+ "the correct window id is set"
+ );
+
+ // Ensure it is reported as a medium or high energy impact.
+ let l10nId = row.children[2].getAttribute("data-l10n-id");
+ Assert.ok(
+ ["energy-impact-medium", "energy-impact-high"].includes(l10nId),
+ "our test tab is medium or high energy impact"
+ );
+
+ // Verify selecting a row works.
+ EventUtils.synthesizeMouseAtCenter(
+ row,
+ {},
+ tabAboutPerformance.linkedBrowser.contentWindow
+ );
+
+ Assert.equal(
+ row.getAttribute("selected"),
+ "true",
+ "doing a single click selects the row"
+ );
+
+ // Verify selecting a tab with a double click.
+ Assert.equal(
+ gBrowser.selectedTab,
+ tabAboutPerformance,
+ "the about:performance tab is selected"
+ );
+ EventUtils.synthesizeMouseAtCenter(
+ row,
+ { clickCount: 2 },
+ tabAboutPerformance.linkedBrowser.contentWindow
+ );
+ Assert.equal(
+ gBrowser.selectedTab,
+ tabContent,
+ "after a double click the test tab is selected"
+ );
+
+ // Verify we can close a tab using the X button.
+ // Switch back to about:performance...
+ await BrowserTestUtils.switchTab(gBrowser, tabAboutPerformance);
+ // ... and click the X button at the end of the row.
+ let tabClosing = BrowserTestUtils.waitForTabClosing(tabContent);
+ EventUtils.synthesizeMouseAtCenter(
+ row.children[4],
+ {},
+ tabAboutPerformance.linkedBrowser.contentWindow
+ );
+ await tabClosing;
+
+ BrowserTestUtils.removeTab(tabAboutPerformance);
+});
diff --git a/toolkit/components/aboutperformance/tests/browser/browser_compartments.html b/toolkit/components/aboutperformance/tests/browser/browser_compartments.html
new file mode 100644
index 0000000000..379422d7ac
--- /dev/null
+++ b/toolkit/components/aboutperformance/tests/browser/browser_compartments.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="UTF-8">
+ <title>
+ Main frame for test browser_aboutperformance.js
+ </title>
+</head>
+<body>
+Main frame.
+
+<iframe src="browser_compartments_frame.html?frame=1">
+ Subframe 1
+</iframe>
+
+<iframe src="browser_compartments_frame.html?frame=2">
+ Subframe 2.
+</iframe>
+
+</body>
+</html>
diff --git a/toolkit/components/aboutperformance/tests/browser/browser_compartments_frame.html b/toolkit/components/aboutperformance/tests/browser/browser_compartments_frame.html
new file mode 100644
index 0000000000..44a073d3bb
--- /dev/null
+++ b/toolkit/components/aboutperformance/tests/browser/browser_compartments_frame.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="UTF-8">
+ <title>
+ Subframe for test browser_compartments.html (do not change this title)
+ </title>
+ <script src="browser_compartments_script.js"></script>
+</head>
+<body>
+Subframe loaded.
+</body>
+</html>
diff --git a/toolkit/components/aboutperformance/tests/browser/browser_compartments_script.js b/toolkit/components/aboutperformance/tests/browser/browser_compartments_script.js
new file mode 100644
index 0000000000..2547a1a010
--- /dev/null
+++ b/toolkit/components/aboutperformance/tests/browser/browser_compartments_script.js
@@ -0,0 +1,11 @@
+// Use some CPU.
+var interval = window.setInterval(() => {
+ // Compute an arbitrary value, print it out to make sure that the JS
+ // engine doesn't discard all our computation.
+ var date = Date.now();
+ var array = [];
+ var i = 0;
+ while (Date.now() - date <= 100) {
+ array[i % 2] = i++;
+ }
+}, 300);