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/mochitest | |
parent | Initial commit. (diff) | |
download | firefox-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 'gfx/tests/mochitest')
-rw-r--r-- | gfx/tests/mochitest/mochitest.ini | 9 | ||||
-rw-r--r-- | gfx/tests/mochitest/test_acceleration.html | 163 | ||||
-rw-r--r-- | gfx/tests/mochitest/test_bug509244.html | 45 | ||||
-rw-r--r-- | gfx/tests/mochitest/test_bug513439.html | 37 | ||||
-rw-r--r-- | gfx/tests/mochitest/test_font_whitelist.html | 90 |
5 files changed, 344 insertions, 0 deletions
diff --git a/gfx/tests/mochitest/mochitest.ini b/gfx/tests/mochitest/mochitest.ini new file mode 100644 index 0000000000..72725d3741 --- /dev/null +++ b/gfx/tests/mochitest/mochitest.ini @@ -0,0 +1,9 @@ +[DEFAULT] + +[test_acceleration.html] +skip-if = (os == 'win') # Bug 1430530 +subsuite = gpu +[test_bug509244.html] +[test_bug513439.html] +[test_font_whitelist.html] +skip-if = debug || asan # Race between pref service and gfx platform IPC causes frequent failures on debug/ASan diff --git a/gfx/tests/mochitest/test_acceleration.html b/gfx/tests/mochitest/test_acceleration.html new file mode 100644 index 0000000000..dd6e146baf --- /dev/null +++ b/gfx/tests/mochitest/test_acceleration.html @@ -0,0 +1,163 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=627498 +--> +<head> + <title>Test hardware acceleration</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=627498">Mozilla Bug 627498</a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script type="application/javascript"> + +// Make sure that acceleration is enabled/disabled the way we expect it to be +// based on platform. + +SimpleTest.waitForExplicitFinish(); + +addEventListener("pageshow", runTest, false); + +function runTest() { + var Cc = SpecialPowers.Cc; + var Ci = SpecialPowers.Ci; + + var sysInfo = SpecialPowers.Services.sysinfo; + var xr = SpecialPowers.Services.appinfo; + + var windows = SpecialPowers.Services.ww.getWindowEnumerator(); + var windowutils; + var acceleratedWindows = 0; + var advancedLayersWindows = 0; + var webrenderWindows = 0; + var layerManagerLog = []; + while (windows.hasMoreElements()) { + windowutils = windows.getNext().windowUtils; + try { + if (windowutils.layerManagerType != "Basic") { + acceleratedWindows++; + } + if (windowutils.layerManagerType == "WebRender") { + webrenderWindows++; + } + if (windowutils.usingAdvancedLayers) { + advancedLayersWindows++; + } + layerManagerLog.push(windowutils.layerManagerType + ":" + + windowutils.usingAdvancedLayers); + } catch (e) { + // The window may not have a layer manager, in which case we get an error. + // Don't count it as an accelerated window. + dump("Didn't get a layer manager! " + e); + } + } + + var osName = sysInfo.getProperty("name"); + switch (osName) { + case "Darwin": // Mac OS X. + // We only enable OpenGL layers on machines that don't support QuickDraw + // plugins. x86-64 architecture is a good proxy for this plugin support. + if (sysInfo.getProperty("arch") != "x86-64") { + is(acceleratedWindows, 0, "Acceleration not supported on x86 OS X"); + } else { + // Workaround for SeaMonkey tinderboxes which don't support acceleration. + if (navigator.userAgent.match(/ SeaMonkey\//)) { + if (acceleratedWindows == 0) { + todo(false, "Acceleration not supported on x86-64 OS X" + + " (This is expected on SeaMonkey (tinderboxes).)"); + break; + } + } + + isnot(acceleratedWindows, 0, "Acceleration enabled on x86-64 OS X"); + } + break; + + case "Windows_NT": // Windows. + var version = parseFloat(sysInfo.getProperty("version")); + if (version == 5.0) { + is(acceleratedWindows, 0, "Acceleration not supported on Windows 2000"); + } else { + // Workaround for SeaMonkey tinderboxes which don't support acceleration. + if (navigator.userAgent.match(/ SeaMonkey\//)) { + if (acceleratedWindows == 0) { + todo(false, "Acceleration not supported on Windows XP or newer" + + " (This is expected on SeaMonkey (tinderboxes).)"); + break; + } + } + + isnot(acceleratedWindows, 0, "Acceleration enabled on Windows XP or newer"); + } + + var gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo); + if (version < 6.2) { + ok(!gfxInfo.D2DEnabled, "Direct2D not supported on Windows 2008 or older"); + if (version < 6.1) { + ok(!gfxInfo.DWriteEnabled, "DirectWrite not supported on Windows 2008 or older"); + } else { + ok(gfxInfo.DWriteEnabled, "DirectWrite enabled on Windows 7 or newer"); + } + } else { + ok(gfxInfo.D2DEnabled, "Direct2D enabled on Windows 8 or newer"); + ok(gfxInfo.DWriteEnabled, "DirectWrite enabled on Windows 7 or newer"); + } + + var shouldGetWR = false; + try { + shouldGetWR = SpecialPowers.DOMWindowUtils.isWebRenderRequested; + } catch (e) {} + + var advancedLayersEnabled = false; + var advancedLayersEnabledOnWin7 = false; + try { + advancedLayersEnabled = SpecialPowers.getBoolPref("layers.mlgpu.enabled"); + advancedLayersEnabledOnWin7 = SpecialPowers.getBoolPref("layers.mlgpu.enable-on-windows7"); + } catch (e) {} + var shouldGetAL = advancedLayersEnabled; + if (version < 6.2) { + shouldGetAL &= advancedLayersEnabledOnWin7; + } + if (shouldGetWR) { + shouldGetAL = false; + } + + if (shouldGetAL) { + isnot(advancedLayersWindows, 0, "Advanced Layers enabled on Windows; " + + layerManagerLog.join(",")); + } else { + is(advancedLayersWindows, 0, "Advanced Layers disabled on Windows"); + } + + if (shouldGetWR) { + isnot(webrenderWindows, 0, "WebRender enabled on Windows"); + } else { + is(webrenderWindows, 0, "WebRender disabled on Windows"); + } + break; + + case "Linux": + todo(false, "Acceleration supported on Linux, but only on taskcluster instances (bug 1296086)"); + break; + + default: + if (xr.OS == "Android") { + isnot(acceleratedWindows, 0, "Acceleration enabled on Android"); + } else { + is(acceleratedWindows, 0, "Acceleration not supported on '" + osName + "'"); + } + } + + SimpleTest.finish(); +} + +</script> +</pre> +</body> +</html> diff --git a/gfx/tests/mochitest/test_bug509244.html b/gfx/tests/mochitest/test_bug509244.html new file mode 100644 index 0000000000..f7348909c2 --- /dev/null +++ b/gfx/tests/mochitest/test_bug509244.html @@ -0,0 +1,45 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=509244 +--> +<head> + <title>Test for Bug 509244</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=509244">Mozilla Bug 509244</a> +<p id="display">A</p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 509244 **/ + +function flush() { document.documentElement.offsetHeight; } + +var text = document.getElementById("display"); + +// layout text, caching monospace font +text.style.fontFamily = "monospace"; +flush(); +// relayout text so that monospace font is no longer used (but cached) +text.style.fontFamily = "sans-serif"; +flush(); + +// flush cache +SpecialPowers.Services.obs.notifyObservers(null, "memory-pressure", "heap-minimize"); + +// reuse font that was flushed from cache +text.style.fontFamily = "monospace"; +flush(); + +ok(true, "not crashed"); + +</script> +</pre> +</body> +</html> diff --git a/gfx/tests/mochitest/test_bug513439.html b/gfx/tests/mochitest/test_bug513439.html new file mode 100644 index 0000000000..6672ae97aa --- /dev/null +++ b/gfx/tests/mochitest/test_bug513439.html @@ -0,0 +1,37 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=513439 +--> +<head> + <title>Test for Bug 513439</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=513439">Mozilla Bug 513439</a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 513439 **/ + +SimpleTest.waitForExplicitFinish(); + +var domWindowUtils = SpecialPowers.DOMWindowUtils; +SpecialPowers.pushPrefEnv({set: [["layout.css.devPixelsPerPx", "2"]]}, () => { + is(domWindowUtils.screenPixelsPerCSSPixel, 2, "devPixelsPerPx wasn't set correctly"); + + SpecialPowers.pushPrefEnv({set: [["layout.css.devPixelsPerPx", "1.5"]]}, () => { + is(domWindowUtils.screenPixelsPerCSSPixel, 1.5, "devPixelsPerPx wasn't set correctly"); + SimpleTest.finish(); + }); +}); + +</script> +</pre> +</body> +</html> diff --git a/gfx/tests/mochitest/test_font_whitelist.html b/gfx/tests/mochitest/test_font_whitelist.html new file mode 100644 index 0000000000..78dd755d54 --- /dev/null +++ b/gfx/tests/mochitest/test_font_whitelist.html @@ -0,0 +1,90 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1121643 +--> +<head> + <title>Test for Bug 1121643</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1121643">Mozilla Bug 1121643</a> +<span id="mono" style="font-family: monospace; font-size: 64px;">M</span> +<span id="sans" style="font-family: sans-serif; font-size: 64px;">M</span> +<span id="serif" style="font-family: serif; font-size: 64px;">M</span> +<div id="content" style="display: none"> + +</div> +<script class="testbody" type="application/javascript"> + +/** Test for Bug 1121643 **/ + +const InspectorUtils = SpecialPowers.InspectorUtils; + +// Given an element id, returns the first font face name encountered. +let fontUsed = id => { + let element = document.getElementById(id), + range = document.createRange(); + range.selectNode(element); + return InspectorUtils.getUsedFontFaces(range)[0].CSSFamilyName; +}; + +// A map of the default mono, sans and serif fonts, obtained when +// whitelisting is disabled. +const fonts = { mono: fontUsed("mono"), + sans: fontUsed("sans"), + serif: fontUsed("serif") }; + +let hack = 0; + +// Set the font whitelist to contain none, some, or all of the +// default mono, sans, and serif fonts. Check that the rendering +// of our three test elements uses only fonts present in the +// whitelist. +let testFontWhitelist = async function(useMono, useSans, useSerif) { + let whitelist = []; + if (useMono) { + whitelist.push(fonts.mono); + } + if (useSans) { + whitelist.push(fonts.sans); + } + if (useSerif) { + whitelist.push(fonts.serif); + } + await SpecialPowers.pushPrefEnv({"set": [["font.system.whitelist", + whitelist.join(", ")]]}); + + await new Promise(SimpleTest.executeSoon); + await SpecialPowers.setIntPref("font.fixme.hack", hack++); + await new Promise(SimpleTest.executeSoon); + + // If whitelist is empty, then whitelisting is considered disabled + // and all fonts are allowed. + info("font whitelist: " + JSON.stringify(whitelist)); + let whitelistEmpty = whitelist.length === 0; + is(useMono || whitelistEmpty, fontUsed("mono") === fonts.mono, + "Correct mono whitelisting state; got " + fontUsed("mono") + ", requested " + fonts.mono); + is(useSans || whitelistEmpty, fontUsed("sans") === fonts.sans, + "Correct sans whitelisting state; got " + fontUsed("sans") + ", requested " + fonts.sans); + is(useSerif || whitelistEmpty, fontUsed("serif") === fonts.serif, + "Correct serif whitelisting state; got " + fontUsed("serif") + ", requested " + fonts.serif); +}; + +// Run tests to confirm that only whitelisting fonts are present in a +// rendered page. Try turning mono, sans, and serif off and on in +// every combination. +add_task(async function() { + for (let useMono of [false, true]) { + for (let useSans of [false, true]) { + for (let useSerif of [false, true]) { + await testFontWhitelist(useMono, useSans, useSerif); + } + } + } +}); + +</script> +</body> +</html> |