Backed out changeset fd1ee37cb15c (bug 1403686) for failing ss in browser/tools/mozscreenshots/controlCenter/browser_controlCenter.js r=backout on a CLOSED TREE
authorMargareta Eliza Balazs <ebalazs@mozilla.com>
Tue, 07 Nov 2017 21:07:11 +0200
changeset 390568 1f99c3d97c245a5233c952944ef8d46d7611a637
parent 390567 95ab305666d4cc3759f93579c6c9cad8e82f3be8
child 390569 ba9156f71b7673f4d97608176fcaa83bcd3c0ed6
push id54923
push userebalazs@mozilla.com
push dateTue, 07 Nov 2017 19:08:02 +0000
treeherderautoland@1f99c3d97c24 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs1403686
milestone58.0a1
backs outfd1ee37cb15c9060e845f5df58eb210a465c10dd
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
Backed out changeset fd1ee37cb15c (bug 1403686) for failing ss in browser/tools/mozscreenshots/controlCenter/browser_controlCenter.js r=backout on a CLOSED TREE
browser/tools/mozscreenshots/browser.ini
browser/tools/mozscreenshots/browser_screenshots_cropping.js
browser/tools/mozscreenshots/mozscreenshots/extension/Screenshot.jsm
browser/tools/mozscreenshots/mozscreenshots/extension/TestRunner.jsm
browser/tools/mozscreenshots/mozscreenshots/extension/lib/robot_center.png
browser/tools/mozscreenshots/mozscreenshots/extension/lib/robot_upperleft.png
--- a/browser/tools/mozscreenshots/browser.ini
+++ b/browser/tools/mozscreenshots/browser.ini
@@ -1,8 +1,7 @@
 [DEFAULT]
 subsuite = screenshots
 support-files =
   head.js
 
 [browser_screenshots.js]
-[browser_screenshots_cropping.js]
 [browser_boundingbox.js]
deleted file mode 100644
--- a/browser/tools/mozscreenshots/browser_screenshots_cropping.js
+++ /dev/null
@@ -1,84 +0,0 @@
-/* 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/. */
-
-"use strict";
-
-async function draw(window, src) {
-  const { document, Image } = window;
-
-  const promise = new Promise((resolve, reject) => {
-    const img = new Image();
-
-    img.onload = function() {
-      // Create a new offscreen canvas
-      const canvas = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
-      canvas.width = img.naturalWidth;
-      canvas.height = img.naturalHeight;
-      const ctx = canvas.getContext("2d");
-
-      ctx.drawImage(img, 0, 0);
-
-      resolve(canvas);
-    };
-
-    img.onerror = function() {
-      reject(`error loading image ${src}`);
-    }
-
-    // Load the src image for drawing
-    img.src = src;
-  });
-
-  return promise;
-}
-
-async function compareImages(window, expected, test) {
-  const testCanvas = await draw(window, test);
-  const expectedCanvas = await draw(window, expected);
-
-  is(testCanvas.width, expectedCanvas.width, "The test and expected images must be the same size");
-  is(testCanvas.height, expectedCanvas.height, "The test and expected images must be the same size");
-
-  const nsIDOMWindowUtils = window.getInterface(Ci.nsIDOMWindowUtils);
-  return nsIDOMWindowUtils.compareCanvases(expectedCanvas, testCanvas, {});
-}
-
-async function cropAndCompare(window, src, expected, test, region) {
-  await TestRunner._cropImage(window, src, region, test);
-
-  return compareImages(window, expected, OS.Path.toFileURI(test));
-}
-
-add_task(async function crop() {
-  const window = Services.wm.getMostRecentWindow("navigator:browser");
-
-  const tmp = OS.Constants.Path.tmpDir;
-  is(await cropAndCompare(
-      window,
-      "chrome://mozscreenshots/content/lib/robot.png",
-      "chrome://mozscreenshots/content/lib/robot_upperleft.png",
-      OS.Path.join(tmp, "test_cropped_upperleft.png"),
-      {x: 0, y: 0, width: 32, height: 32}
-  ), 0, "The image should be cropped to the upper left quadrant");
-
-  is(await cropAndCompare(
-      window,
-      "chrome://mozscreenshots/content/lib/robot.png",
-      "chrome://mozscreenshots/content/lib/robot_center.png",
-      OS.Path.join(tmp, "test_cropped_center.png"),
-      {x: 16, y: 16, width: 32, height: 32}
-  ), 0, "The image should be cropped to the center of the image");
-
-  await cropAndCompare(
-      window,
-      "chrome://mozscreenshots/content/lib/robot.png",
-      "chrome://mozscreenshots/content/lib/robot.png",
-      OS.Path.join(tmp, "test_cropped_center.png"),
-      {x: 16, y: 16, width: 64, height: 64}
-  ).then(() => {
-    ok(false, "Cropping region should have been too large");
-  }, () => {
-    ok(true, "Cropping region is too large as expected")
-  });
-})
--- a/browser/tools/mozscreenshots/mozscreenshots/extension/Screenshot.jsm
+++ b/browser/tools/mozscreenshots/mozscreenshots/extension/Screenshot.jsm
@@ -59,21 +59,21 @@ this.Screenshot = {
     }
   },
 
   _buildImagePath(baseName) {
     return OS.Path.join(this._path, this._imagePrefix + baseName + this._imageExtension);
   },
 
   // Capture the whole screen using an external application.
-  async captureExternal(filename) {
+  captureExternal(filename) {
     let imagePath = this._buildImagePath(filename);
-    await this._screenshotFunction(imagePath);
-    log.debug("saved screenshot: " + filename);
-    return imagePath;
+    return this._screenshotFunction(imagePath).then(() => {
+      log.debug("saved screenshot: " + filename);
+    });
   },
 
   // helpers
 
   _screenshotWindows(filename) {
     return new Promise((resolve, reject) => {
       let exe = Services.dirsvc.get("GreBinD", Ci.nsIFile);
       exe.append("screenshot.exe");
@@ -97,16 +97,22 @@ this.Screenshot = {
         let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
         file.initWithPath("/usr/sbin/screencapture");
 
         let process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
         process.init(file);
 
         // Run the process.
         let args = ["-x", "-t", "png"];
+        // Darwin version number for OS X 10.6 is 10.x
+        if (windowID && Services.sysinfo.getProperty("version").indexOf("10.") !== 0) {
+          // Capture only that window on 10.7+
+          args.push("-l");
+          args.push(windowID);
+        }
         args.push(filename);
         process.runAsync(args, args.length, this._processObserver(resolve, reject));
       });
     };
 
     function readWindowID() {
       let decoder = new TextDecoder();
       let promise = OS.File.read("/tmp/mozscreenshots-windowid");
--- a/browser/tools/mozscreenshots/mozscreenshots/extension/TestRunner.jsm
+++ b/browser/tools/mozscreenshots/mozscreenshots/extension/TestRunner.jsm
@@ -15,17 +15,17 @@ Cu.import("resource://gre/modules/FileUt
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/Timer.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/osfile.jsm");
 Cu.import("resource://gre/modules/Geometry.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "BrowserTestUtils",
                                   "resource://testing-common/BrowserTestUtils.jsm");
-// Screenshot.jsm must be imported this way for xpcshell tests to work
+
 XPCOMUtils.defineLazyModuleGetter(this, "Screenshot", "chrome://mozscreenshots/content/Screenshot.jsm");
 
 // Create a new instance of the ConsoleAPI so we can control the maxLogLevel with a pref.
 // See LOG_LEVELS in Console.jsm. Common examples: "All", "Info", "Warn", & "Error".
 const PREF_LOG_LEVEL = "extensions.mozscreenshots@mozilla.org.loglevel";
 XPCOMUtils.defineLazyGetter(this, "log", () => {
   let ConsoleAPI = Cu.import("resource://gre/modules/Console.jsm", {}).ConsoleAPI;
   let consoleOptions = {
@@ -319,97 +319,39 @@ this.TestRunner = {
       log.warn("\tskipped configuration: " + ex);
       // Don't set lastCombo here so that we properly know which configurations
       // need to be applied since the last screenshot
 
       // Return so we don't take a screenshot.
       return;
     }
 
-    // Collect selectors from combo configs for cropping region
-    let windowType;
-    const finalSelectors = [];
-    for (const obj of combo) {
-      if (!windowType) {
-        windowType = obj.windowType;
-      } else if (windowType !== obj.windowType) {
-        log.warn("\tConfigurations with multiple window types are not allowed");
-        return;
-      }
-      for (const selector of obj.selectors) {
-        finalSelectors.push(selector);
-      }
-    }
-
-    const rect = this._findBoundingBox(finalSelectors, windowType);
-    await this._onConfigurationReady(combo, rect);
+    await this._onConfigurationReady(combo);
   },
 
-  async _onConfigurationReady(combo, rect) {
-    let filename = padLeft(this.currentComboIndex + 1,
-                           String(this.combos.length).length) + this._comboName(combo);
-    const imagePath = await Screenshot.captureExternal(filename);
+  _onConfigurationReady(combo) {
+    let delayedScreenshot = () => {
+      let filename = padLeft(this.currentComboIndex + 1,
+                             String(this.combos.length).length) + this._comboName(combo);
+      return Screenshot.captureExternal(filename)
+        .then(() => {
+          this.completedCombos++;
+        });
+    };
 
-    let browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
-    await this._cropImage(browserWindow, OS.Path.toFileURI(imagePath), rect, imagePath);
-    this.completedCombos++;
     log.debug("_onConfigurationReady");
+    return delayedScreenshot();
   },
 
   _comboName(combo) {
     return combo.reduce(function(a, b) {
       return a + "_" + b.name;
     }, "");
   },
 
-  async _cropImage(window, srcPath, rect, targetPath) {
-    const { document, Image } = window;
-    const promise = new Promise((resolve, reject) => {
-      const img = new Image();
-      img.onload = function() {
-        // Make sure that the cropping region is valid and that the cropping
-        // region is inside the screenshot we are cropping
-        if (rect.x < 0 || rect.y < 0 || rect.width < 0 || rect.height < 0 ||
-            img.naturalWidth < rect.x + rect.width ||
-            img.naturalHeight < rect.y + rect.height) {
-          reject("Invalid cropping region");
-          return;
-        }
-        // Create a new offscreen canvas, with the width and height given by the
-        // size of the region we want to crop to
-        const canvas = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
-        canvas.width = rect.width;
-        canvas.height = rect.height;
-        const ctx = canvas.getContext("2d");
-        // By drawing the image with the negative offset, the unwanted regions
-        // are drawn off canvas, and are not captured when the canvas is saved.
-        ctx.drawImage(img, -rect.x, -rect.y);
-        // Converts the canvas to a binary blob, which can be saved to a png
-        canvas.toBlob((blob) => {
-          // Use a filereader to convert the raw binary blob into a writable buffer
-          const fr = new FileReader();
-          fr.onload = function(e) {
-            const buffer = new Uint8Array(e.target.result);
-            // Save the file and complete the promise
-            OS.File.writeAtomic(targetPath, buffer, {}).then(resolve);
-          };
-          // Do the conversion
-          fr.readAsArrayBuffer(blob);
-        });
-      };
-
-      img.onerror = function() {
-        reject(`error loading image ${srcPath}`);
-      };
-      // Load the src image for drawing
-      img.src = srcPath;
-    });
-    return promise;
-  },
-
   /**
    * Finds the index of the first comma that is not enclosed within square brackets.
    * @param {String} envVar - the string that needs to be searched
    * @return {Integer} index of valid comma or -1 if not found.
    */
   findComma(envVar) {
     let nestingDepth = 0;
     for (let i = 0; i < envVar.length; i++) {
deleted file mode 100644
index ecaaf1b02e2228a912b57bd4cf7c3ce79215a382..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index f1f0a04412e66a12f89d580c4ad1e44b0b2c4ffc..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001