From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- .../aboutperformance/tests/browser/browser.ini | 7 ++ .../tests/browser/browser_aboutperformance.js | 106 +++++++++++++++++++++ .../tests/browser/browser_compartments.html | 21 ++++ .../tests/browser/browser_compartments_frame.html | 13 +++ .../tests/browser/browser_compartments_script.js | 11 +++ 5 files changed, 158 insertions(+) create mode 100644 toolkit/components/aboutperformance/tests/browser/browser.ini create mode 100644 toolkit/components/aboutperformance/tests/browser/browser_aboutperformance.js create mode 100644 toolkit/components/aboutperformance/tests/browser/browser_compartments.html create mode 100644 toolkit/components/aboutperformance/tests/browser/browser_compartments_frame.html create mode 100644 toolkit/components/aboutperformance/tests/browser/browser_compartments_script.js (limited to 'toolkit/components/aboutperformance/tests') 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 @@ + + + + + + Main frame for test browser_aboutperformance.js + + + +Main frame. + + + + + + + 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 @@ + + + + + + Subframe for test browser_compartments.html (do not change this title) + + + + +Subframe loaded. + + 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); -- cgit v1.2.3