Bug 1274663 - Add mochitest. r=dvander
authordomfarolino@gmail.com <domfarolino@gmail.com>
Thu, 15 Jun 2017 14:35:00 -0400
changeset 364296 03681158d59c708f6f68328e2f6a576be50f851e
parent 364295 db5cc36763c1dff6c285011f30ded88304ca42b9
child 364297 50f92f81d4da42b796fd28bdaf1986c4de2046bd
push id32037
push userarchaeopteryx@coole-files.de
push dateFri, 16 Jun 2017 07:50:18 +0000
treeherdermozilla-central@fe809f57bf22 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander
bugs1274663
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1274663 - Add mochitest. r=dvander
gfx/tests/chrome/chrome.ini
gfx/tests/chrome/test_device_reset.html
gfx/tests/moz.build
new file mode 100644
--- /dev/null
+++ b/gfx/tests/chrome/chrome.ini
@@ -0,0 +1,4 @@
+[DEFAULT]
+
+[test_device_reset.html]
+subsuite = gpu
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/gfx/tests/chrome/test_device_reset.html
@@ -0,0 +1,95 @@
+<!DOCTYPE html>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1274663
+-->
+  <head>
+    <meta charset="utf-8">
+    <title>Test device reset</title>
+    <script type="application/javascript" 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 Cc = SpecialPowers.Cc;
+      var Ci = SpecialPowers.Ci;
+
+      var sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2);
+      var xr = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
+
+      var windows = SpecialPowers.Services.ww.getWindowEnumerator();
+      var windowutils;
+      while (windows.hasMoreElements()) {
+        windowutils = windows.getNext().QueryInterface(Ci.nsIInterfaceRequestor)
+                                       .getInterface(Ci.nsIDOMWindowUtils);
+      }
+
+      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, false);
+      });
+
+      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>
--- a/gfx/tests/moz.build
+++ b/gfx/tests/moz.build
@@ -2,8 +2,9 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
 MOCHITEST_MANIFESTS += ['mochitest/mochitest.ini']
 BROWSER_CHROME_MANIFESTS += ['browser/browser.ini']
+MOCHITEST_CHROME_MANIFESTS += ['chrome/chrome.ini']
\ No newline at end of file