Backed out changeset da9706e0d3c2 (bug 1403686) for ESlint failures on browser_screenshots_cropping.js r=backout on a CLOSED TREE
authorBrindusan Cristian <cbrindusan@mozilla.com>
Mon, 20 Nov 2017 21:19:56 +0200
changeset 392728 a1f2e0532e8e7e3cbe0c39975e43ee103d8e3c72
parent 392727 79ac723d679bf6d6b563d540253e632b757b4ed1
child 392729 54ce507fdd658413ce130cca1b25a35e2c6abade
child 392782 0bbed2e6a4cc96649fc925cf6f8795b67956ed82
push id55681
push usercbrindusan@mozilla.com
push dateMon, 20 Nov 2017 19:20:17 +0000
treeherderautoland@a1f2e0532e8e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs1403686
milestone59.0a1
backs outda9706e0d3c20adc5c10c492d9950c7d7064407b
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 da9706e0d3c2 (bug 1403686) for ESlint failures on browser_screenshots_cropping.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/configurations/TabsInTitlebar.jsm
browser/tools/mozscreenshots/mozscreenshots/extension/lib/robot_center.png
browser/tools/mozscreenshots/mozscreenshots/extension/lib/robot_uncropped.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,82 +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";
-
-Cu.import("resource://gre/modules/Geometry.jsm", this);
-
-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"),
-      new Rect(0, 0, 32, 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"),
-      new Rect(16, 16, 32, 32)
-  ), 0, "The image should be cropped to the center of the image");
-
-  is(await cropAndCompare(
-      window,
-      "chrome://mozscreenshots/content/lib/robot.png",
-      "chrome://mozscreenshots/content/lib/robot_uncropped.png",
-      OS.Path.join(tmp, "test_uncropped.png"),
-      new Rect(-8, -9, 80, 80)
-  ), 0, "The image should be not be cropped, and the cropping region should be clipped to the size of the image");
-})
--- 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() {
-        // Clip the cropping region to the size of the screenshot
-        // This is necessary mostly to deal with offscreen windows, since we
-        // are capturing an image of the operating system's desktop.
-        rect.left = Math.max(0, rect.left);
-        rect.right = Math.min(img.naturalWidth, rect.right);
-        rect.top = Math.max(0, rect.top);
-        rect.bottom = Math.min(img.naturalHeight, rect.bottom);
-
-        // 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++) {
--- a/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/TabsInTitlebar.jsm
+++ b/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/TabsInTitlebar.jsm
@@ -24,16 +24,16 @@ this.TabsInTitlebar = {
           return Promise.reject("TabsInTitlebar isn't supported on Linux");
         }
         Services.prefs.setBoolPref(PREF_TABS_IN_TITLEBAR, true);
         return undefined;
       },
     },
 
     tabsOutsideTitlebar: {
-      selectors: ["#navigator-toolbox"].concat(Services.appinfo.OS == "Linux" ? [] : ["#titlebar"]),
+      selectors: ["#navigator-toolbox", "#titlebar"],
       async applyConfig() {
         Services.prefs.setBoolPref(PREF_TABS_IN_TITLEBAR, false);
       },
     },
 
   },
 };
deleted file mode 100644
index ecaaf1b02e2228a912b57bd4cf7c3ce79215a382..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index ce271b1007e0ffc028a471ee39f95a036b3d1966..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index f1f0a04412e66a12f89d580c4ad1e44b0b2c4ffc..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001