summaryrefslogtreecommitdiffstats
path: root/gfx/tests/chrome
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 /gfx/tests/chrome
parentInitial commit. (diff)
downloadfirefox-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/chrome')
-rw-r--r--gfx/tests/chrome/chrome.ini4
-rw-r--r--gfx/tests/chrome/test_device_reset.html88
2 files changed, 92 insertions, 0 deletions
diff --git a/gfx/tests/chrome/chrome.ini b/gfx/tests/chrome/chrome.ini
new file mode 100644
index 0000000000..6c5ba90a0d
--- /dev/null
+++ b/gfx/tests/chrome/chrome.ini
@@ -0,0 +1,4 @@
+[DEFAULT]
+
+[test_device_reset.html]
+subsuite = gpu
diff --git a/gfx/tests/chrome/test_device_reset.html b/gfx/tests/chrome/test_device_reset.html
new file mode 100644
index 0000000000..19fd2d365e
--- /dev/null
+++ b/gfx/tests/chrome/test_device_reset.html
@@ -0,0 +1,88 @@
+<!DOCTYPE html>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1274663
+-->
+ <head>
+ <meta charset="utf-8">
+ <title>Test device reset</title>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+ </head>
+ <body>
+ <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1274663">Mozilla Bug 1274663</a>
+ <script>
+ var importObj = {};
+
+ var windows = SpecialPowers.Services.ww.getWindowEnumerator();
+ var windowutils;
+ while (windows.hasMoreElements()) {
+ windowutils = windows.getNext().windowUtils;
+ }
+
+ const PAGE_WIDTH = 200;
+ const PAGE_HEIGHT = 200;
+
+ // Helper functions
+
+ function testCompositor(ctx) {
+ takeWindowSnapshot(ctx);
+ var testPassed = true;
+
+ if (!verifyCanvasRendering(ctx)) {
+ testPassed = false;
+ }
+
+ return testPassed;
+ }
+
+ function testPixel(ctx, x, y, r, g, b, a, fuzz) {
+ var data = ctx.getImageData(x, y, 1, 1);
+
+ if (Math.abs(data.data[0] - r) <= fuzz &&
+ Math.abs(data.data[1] - g) <= fuzz &&
+ Math.abs(data.data[2] - b) <= fuzz &&
+ Math.abs(data.data[3] - a) <= fuzz) {
+ return true;
+ }
+ return false;
+ }
+
+ function verifyCanvasRendering(ctx) {
+ return testPixel(ctx, 20, 20, 140, 25, 86, 255, 0);
+ }
+
+ function takeWindowSnapshot(ctx) {
+ var flags = ctx.DRAWWINDOW_DRAW_CARET | ctx.DRAWWINDOW_DRAW_VIEW | ctx.DRAWWINDOW_USE_WIDGET_LAYERS;
+ ctx.drawWindow(window, 0, 0, PAGE_WIDTH, PAGE_HEIGHT, "rgb(140,25,86)", flags);
+ }
+
+ function createCanvas() {
+ let canvas = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
+
+ canvas.setAttribute("width", PAGE_WIDTH + "px");
+ canvas.setAttribute("height", PAGE_HEIGHT + "px");
+
+ return canvas;
+ }
+
+ // Test runner code
+ windowutils.triggerDeviceReset();
+
+ SimpleTest.waitForExplicitFinish();
+ window.addEventListener("MozAfterPaint", function paintHandle(e) {
+ runCanvasTest();
+ window.removeEventListener("MozAfterPaint", paintHandle);
+ });
+
+ function runCanvasTest() {
+ const canvas = createCanvas();
+ const ctx = canvas.getContext("2d");
+ document.body.appendChild(canvas);
+
+ ok(testCompositor(ctx), "Canvas did not get rendered after device reset");
+ SimpleTest.finish();
+ }
+ </script>
+ </body>
+</html>