diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /gfx/tests/browser | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/tests/browser')
-rw-r--r-- | gfx/tests/browser/browser.ini | 8 | ||||
-rw-r--r-- | gfx/tests/browser/browser_native_font_cache_macos.js | 115 | ||||
-rw-r--r-- | gfx/tests/browser/browser_windowless_troubleshoot_crash.js | 58 | ||||
-rw-r--r-- | gfx/tests/browser/file_native_font_cache_macos.html | 15 |
4 files changed, 196 insertions, 0 deletions
diff --git a/gfx/tests/browser/browser.ini b/gfx/tests/browser/browser.ini new file mode 100644 index 0000000000..042f361a58 --- /dev/null +++ b/gfx/tests/browser/browser.ini @@ -0,0 +1,8 @@ +[DEFAULT] +support-files = + +[browser_native_font_cache_macos.js] +support-files = + file_native_font_cache_macos.html +skip-if = (os != 'mac') +[browser_windowless_troubleshoot_crash.js] diff --git a/gfx/tests/browser/browser_native_font_cache_macos.js b/gfx/tests/browser/browser_native_font_cache_macos.js new file mode 100644 index 0000000000..6bef437b62 --- /dev/null +++ b/gfx/tests/browser/browser_native_font_cache_macos.js @@ -0,0 +1,115 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async () => { + // Create a tab that loads a system font. + const CROSS_ORIGIN_DOMAIN = "https://example.com"; + const TARGET_URL = `${CROSS_ORIGIN_DOMAIN}/browser/gfx/tests/browser/file_native_font_cache_macos.html`; + await BrowserTestUtils.withNewTab( + { gBrowser, url: TARGET_URL }, + async browser => { + await SpecialPowers.spawn(browser, [], async () => { + // Capture a snapshot of the tab, which will load the system font in the + // parent process. + const TARGET_WIDTH = 200; + const TARGET_HEIGHT = 100; + + const rect = new content.window.DOMRect( + 0, + 0, + TARGET_WIDTH, + TARGET_HEIGHT + ); + await SpecialPowers.snapshotContext(content.window, rect, "white"); + }); + } + ); + + // Now create a tab that shows the memory reporter. + await BrowserTestUtils.withNewTab( + { gBrowser, url: "about:memory" }, + async browser => { + // Click the "Measure" button. + await SpecialPowers.spawn(browser, [], () => { + let measureButton = content.document.getElementById("measureButton"); + measureButton.click(); + }); + + // Copy the page text and check for an expected start with string. + let copiedText = await new Promise(resolve => { + const REPORT_TIMEOUT_MS = 15 * 1e3; + const EXPECTED_START_WITH = "Main Process"; + let mostRecentTextOnClipboard = ""; + + SimpleTest.waitForClipboard( + textOnClipboard => { + mostRecentTextOnClipboard = textOnClipboard; + const gotExpected = textOnClipboard.startsWith(EXPECTED_START_WITH); + if (!gotExpected) { + // Try copying again. + EventUtils.synthesizeKey("A", { accelKey: true }); + EventUtils.synthesizeKey("C", { accelKey: true }); + } + return gotExpected; + }, + () => { + EventUtils.synthesizeKey("A", { accelKey: true }); + EventUtils.synthesizeKey("C", { accelKey: true }); + }, + () => { + resolve(mostRecentTextOnClipboard); + }, + () => { + info(`Didn't find expected text within ${REPORT_TIMEOUT_MS}ms.`); + dump("*******ACTUAL*******\n"); + dump("<<<" + mostRecentTextOnClipboard + ">>>\n"); + dump("********************\n"); + resolve(""); + }, + "text/unicode", + REPORT_TIMEOUT_MS + ); + }); + + isnot(copiedText, "", "Got some text from clipboard."); + + // Search the copied text for our desired pattern. Initially, check for + // a line with "native-font-resource-mac". If that exists, ensure that it + // has less than a maximum MB. If that doesn't exist, check instead for + // a line with "gfx" before the "Other Measurements" section. If that + // exists, it is tested against the same MB limit. If it doesn't exist, + // that is an indication that "gfx" doesn't occur in the first section + // "Explicit Allocations', and therefore isn't holding memory at all. + const MB_EXCLUSIVE_MAX = 20; + const nfrm_line = /^.*?(\d+)\.\d+ MB.*-- native-font-resource-mac/m; + const nfrm_match = nfrm_line.exec(copiedText); + if (nfrm_match) { + const nfrm_mb = nfrm_match[1]; + ok( + nfrm_mb < MB_EXCLUSIVE_MAX, + `native-font-resource-mac ${nfrm_mb} MB should be less than ${MB_EXCLUSIVE_MAX} MB.` + ); + } else { + // Figure out where the "Other Measurements" section begins. + const om_line = /^Other Measurements$/m; + const om_match = om_line.exec(copiedText); + + // Find the first gfx line, and if it occurs before the "Other + // Measurements" section, check its size. + const gfx_line = /^.*?(\d+)\.\d+ MB.*-- gfx/m; + const gfx_match = gfx_line.exec(copiedText); + if (gfx_match && gfx_match.index < om_match.index) { + const gfx_mb = gfx_match[1]; + ok( + gfx_mb < MB_EXCLUSIVE_MAX, + `Explicit Allocations gfx ${gfx_mb} MB should be less than ${MB_EXCLUSIVE_MAX} MB.` + ); + } else { + ok(true, "Explicit Allocations gfx is not listed."); + } + } + } + ); +}); diff --git a/gfx/tests/browser/browser_windowless_troubleshoot_crash.js b/gfx/tests/browser/browser_windowless_troubleshoot_crash.js new file mode 100644 index 0000000000..9afce41163 --- /dev/null +++ b/gfx/tests/browser/browser_windowless_troubleshoot_crash.js @@ -0,0 +1,58 @@ +add_task(async function test_windowlessBrowserTroubleshootCrash() { + let webNav = Services.appShell.createWindowlessBrowser(false); + + let onLoaded = new Promise((resolve, reject) => { + let docShell = webNav.docShell; + let listener = { + observe(contentWindow, topic, data) { + let observedDocShell = contentWindow.docShell.sameTypeRootTreeItem.QueryInterface( + Ci.nsIDocShell + ); + if (docShell === observedDocShell) { + Services.obs.removeObserver( + listener, + "content-document-global-created" + ); + resolve(); + } + }, + }; + Services.obs.addObserver(listener, "content-document-global-created"); + }); + let loadURIOptions = { + triggeringPrincipal: Services.scriptSecurityManager.createNullPrincipal({}), + }; + webNav.loadURI("about:blank", loadURIOptions); + + await onLoaded; + + let winUtils = webNav.document.defaultView.windowUtils; + try { + is( + winUtils.layerManagerType, + "Basic", + "windowless browser's layerManagerType should be 'Basic'" + ); + } catch (e) { + // The windowless browser may not have a layermanager at all yet, and that's ok. + // The troubleshooting code similarly skips over windows with no layer managers. + } + ok(true, "not crashed"); + + var Troubleshoot = ChromeUtils.import( + "resource://gre/modules/Troubleshoot.jsm", + {} + ).Troubleshoot; + var data = await new Promise((resolve, reject) => { + Troubleshoot.snapshot(data => { + resolve(data); + }); + }); + + ok( + data.graphics.windowLayerManagerType !== "None", + "windowless browser window should not set windowLayerManagerType to 'None'" + ); + + webNav.close(); +}); diff --git a/gfx/tests/browser/file_native_font_cache_macos.html b/gfx/tests/browser/file_native_font_cache_macos.html new file mode 100644 index 0000000000..84692a4ca7 --- /dev/null +++ b/gfx/tests/browser/file_native_font_cache_macos.html @@ -0,0 +1,15 @@ +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"/> +<style> +html { + font-size: 40px; + font-family: apple color emoji; +} +</style> +</head> +<body> +🔍🍔🔥 +</body> +</html> |