Backed out changeset 64e8532c9a0b (bug 1682634) for causing bc failures in browser_screenshots_dimensions.js. CLOSED TREE
authorBrindusan Cristian <cbrindusan@mozilla.com>
Thu, 03 Jun 2021 03:14:56 +0300
changeset 654271 a81b46bef82fcd2f0e63cae11464283abe9a2fce
parent 654270 52dd9f9ddded7472fc023ad0fc466118a51611e9
child 654272 429670fd06703ceeac80fe306104d6b604f01052
push id2623
push userffxbld-merge
push dateMon, 02 Aug 2021 14:47:51 +0000
treeherdermozilla-release@8500ce65f7c6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1682634
milestone91.0a1
backs out64e8532c9a0bb62a68cd7d078a4f387c22d337bc
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 64e8532c9a0b (bug 1682634) for causing bc failures in browser_screenshots_dimensions.js. CLOSED TREE
browser/extensions/screenshots/test/browser/.eslintrc.yml
browser/extensions/screenshots/test/browser/browser.ini
browser/extensions/screenshots/test/browser/browser_screenshots_dimensions.js
browser/extensions/screenshots/test/browser/green2vh.html
browser/extensions/screenshots/test/browser/head.js
new file mode 100644
--- /dev/null
+++ b/browser/extensions/screenshots/test/browser/.eslintrc.yml
@@ -0,0 +1,5 @@
+env:
+  node: true
+
+extends:
+  - plugin:mozilla/browser-test
--- a/browser/extensions/screenshots/test/browser/browser.ini
+++ b/browser/extensions/screenshots/test/browser/browser.ini
@@ -1,15 +1,8 @@
 [DEFAULT]
 prefs =
   # The Screenshots extension is disabled by default in Mochitests. We re-enable
   # it here, since it's a more realistic configuration.
   extensions.screenshots.disabled=false
 [browser_screenshots_injection.js]
-
-support-files =
-  head.js
-  injection-page.html
-  green2vh.html
-
+support-files = injection-page.html
 [browser_screenshot_button.js]
-[browser_screenshots_dimensions.js]
-skip-if = headless # Bug 1714210
deleted file mode 100644
--- a/browser/extensions/screenshots/test/browser/browser_screenshots_dimensions.js
+++ /dev/null
@@ -1,107 +0,0 @@
-add_task(async function test_fullPageScreenshot() {
-  await BrowserTestUtils.withNewTab(
-    {
-      gBrowser,
-      url: TEST_GREEN_PAGE,
-    },
-    async browser => {
-      let helper = new ScreenshotsHelper(browser);
-      let contentInfo = await helper.getContentDimensions();
-      ok(contentInfo, "Got dimensions back from the content");
-
-      await helper.triggerUIFromToolbar();
-
-      await helper.clickUIElement(
-        helper.selector.preselectIframe,
-        helper.selector.fullPageButton
-      );
-
-      info("Waiting for the preview UI and the copy button");
-      await helper.waitForUIContent(
-        helper.selector.previewIframe,
-        helper.selector.copyButton
-      );
-
-      let deactivatedPromise = helper.waitForToolbarButtonDeactivation();
-      let clipboardChanged = waitForRawClipboardChange();
-
-      await helper.clickUIElement(
-        helper.selector.previewIframe,
-        helper.selector.copyButton
-      );
-
-      info("Waiting for clipboard change");
-      await clipboardChanged;
-
-      await deactivatedPromise;
-      info("Screenshots is deactivated");
-
-      let result = await getImageSizeFromClipboard(browser);
-      is(
-        result.width,
-        contentInfo.documentWidth,
-        "Got expected screenshot width"
-      );
-      is(
-        result.height,
-        contentInfo.documentHeight,
-        "Got expected screenshot height"
-      );
-    }
-  );
-});
-
-add_task(async function test_visiblePageScreenshot() {
-  await BrowserTestUtils.withNewTab(
-    {
-      gBrowser,
-      url: TEST_GREEN_PAGE,
-    },
-    async browser => {
-      let helper = new ScreenshotsHelper(browser);
-      let contentInfo = await helper.getContentDimensions();
-      ok(contentInfo, "Got dimensions back from the content");
-
-      await helper.triggerUIFromToolbar();
-
-      await helper.clickUIElement(
-        helper.selector.preselectIframe,
-        helper.selector.visiblePageButton
-      );
-
-      info("Waiting for the preview UI and the copy button");
-      await helper.waitForUIContent(
-        helper.selector.previewIframe,
-        helper.selector.copyButton
-      );
-
-      let deactivatedPromise = helper.waitForToolbarButtonDeactivation();
-      let clipboardChanged = waitForRawClipboardChange();
-
-      await helper.clickUIElement(
-        helper.selector.previewIframe,
-        helper.selector.copyButton
-      );
-
-      info("Waiting for clipboard change");
-      await clipboardChanged;
-
-      await deactivatedPromise;
-      info("Screenshots is deactivated");
-
-      let result = await getImageSizeFromClipboard(browser);
-      info("result: " + JSON.stringify(result, null, 2));
-      info("contentInfo: " + JSON.stringify(contentInfo, null, 2));
-      todo_is(
-        result.width,
-        contentInfo.documentWidth,
-        "Got expected screenshot width"
-      );
-      todo_is(
-        result.height,
-        contentInfo.clientHeight,
-        "Got expected screenshot height"
-      );
-    }
-  );
-});
deleted file mode 100644
--- a/browser/extensions/screenshots/test/browser/green2vh.html
+++ /dev/null
@@ -1,23 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-  <meta charset="utf-8">
-  <style>
-    html, body {
-      padding: 0;
-      margin: 0;
-    }
-    body {
-      background: rgb(0,255,0);
-      min-height: 200vh;
-    }
-  </style>
-  <script>
-    window.addEventListener("DOMContentLoaded", () => {
-      console.log(window.screen);
-    });
-  </script>
-</head>
-<body>
-</body>
-</html>
deleted file mode 100644
--- a/browser/extensions/screenshots/test/browser/head.js
+++ /dev/null
@@ -1,236 +0,0 @@
-"use strict";
-
-const { AddonManager } = ChromeUtils.import(
-  "resource://gre/modules/AddonManager.jsm"
-);
-const { ContentTaskUtils } = ChromeUtils.import(
-  "resource://testing-common/ContentTaskUtils.jsm"
-);
-
-const TEST_ROOT = getRootDirectory(gTestPath).replace(
-  "chrome://mochitests/content",
-  "http://example.com"
-);
-const TEST_GREEN_PAGE = TEST_ROOT + "green2vh.html";
-
-const gScreenshotUISelectors = {
-  preselectIframe: "#firefox-screenshots-preselection-iframe",
-  fullPageButton: "button.full-page",
-  visiblePageButton: "button.visible",
-  previewIframe: "#firefox-screenshots-preview-iframe",
-  copyButton: "button.highlight-button-copy",
-};
-
-class ScreenshotsHelper {
-  constructor(browser) {
-    this.browser = browser;
-    this.selector = gScreenshotUISelectors;
-  }
-
-  get toolbarButton() {
-    return document.getElementById("screenshot-button");
-  }
-
-  async triggerUIFromToolbar() {
-    let button = this.toolbarButton;
-    ok(
-      BrowserTestUtils.is_visible(button),
-      "The screenshot toolbar button is visible"
-    );
-    EventUtils.synthesizeMouseAtCenter(button, {});
-    // Make sure the Screenshots UI is loaded before yielding
-    await this.waitForUIContent(
-      this.selector.preselectIframe,
-      this.selector.fullPageButton
-    );
-  }
-
-  async waitForUIContent(iframeSel, elemSel) {
-    await SpecialPowers.spawn(
-      this.browser,
-      [iframeSel, elemSel],
-      async function(iframeSelector, elemSelector) {
-        info(
-          `in waitForUIContent content function, iframeSelector: ${iframeSelector}, elemSelector: ${elemSelector}`
-        );
-        let iframe;
-        await ContentTaskUtils.waitForCondition(() => {
-          iframe = content.document.querySelector(iframeSelector);
-          if (!iframe || !ContentTaskUtils.is_visible(iframe)) {
-            info("in waitForUIContent, no visible iframe yet");
-            return false;
-          }
-          let elem = iframe.contentDocument.querySelector(elemSelector);
-          info(
-            "in waitForUIContent, got visible elem: " +
-              (elem && ContentTaskUtils.is_visible(elem))
-          );
-          return elem && ContentTaskUtils.is_visible(elem);
-        });
-        // wait a frame for the screenshots UI to finish any init
-        await new content.Promise(res => content.requestAnimationFrame(res));
-      }
-    );
-  }
-
-  async clickUIElement(iframeSel, elemSel) {
-    await SpecialPowers.spawn(
-      this.browser,
-      [iframeSel, elemSel],
-      async function(iframeSelector, elemSelector) {
-        info(
-          `in clickScreenshotsUIElement content function, iframeSelector: ${iframeSelector}, elemSelector: ${elemSelector}`
-        );
-        const EventUtils = ContentTaskUtils.getEventUtils(content);
-        let iframe = content.document.querySelector(iframeSelector);
-        let elem = iframe.contentDocument.querySelector(elemSelector);
-        info(`Found the thing to click: ${elemSelector}: ${!!elem}`);
-
-        EventUtils.synthesizeMouseAtCenter(elem, {}, iframe.contentWindow);
-        await new content.Promise(res => content.requestAnimationFrame(res));
-      }
-    );
-  }
-
-  waitForToolbarButtonDeactivation() {
-    return BrowserTestUtils.waitForCondition(() => {
-      return !this.toolbarButton.style.cssText.includes("icon-highlight");
-    });
-  }
-
-  getContentDimensions() {
-    return SpecialPowers.spawn(this.browser, [], async function() {
-      let doc = content.document;
-      let rect = doc.documentElement.getBoundingClientRect();
-      return {
-        clientHeight: doc.documentElement.clientHeight,
-        clientWidth: doc.documentElement.clientWidth,
-        currentURI: doc.documentURI,
-        documentHeight: Math.round(rect.height),
-        documentWidth: Math.round(rect.width),
-      };
-    });
-  }
-}
-
-function waitForRawClipboardChange() {
-  const initialClipboardData = Date.now().toString();
-  SpecialPowers.clipboardCopyString(initialClipboardData);
-
-  let promiseChanged = BrowserTestUtils.waitForCondition(() => {
-    let data;
-    try {
-      data = getRawClipboardData("image/png");
-    } catch (e) {
-      console.log("Failed to get image/png clipboard data:", e);
-      return false;
-    }
-    return data && initialClipboardData !== data;
-  });
-  return promiseChanged;
-}
-
-function getRawClipboardData(flavor) {
-  const whichClipboard = Services.clipboard.kGlobalClipboard;
-  const xferable = Cc["@mozilla.org/widget/transferable;1"].createInstance(
-    Ci.nsITransferable
-  );
-  xferable.init(null);
-  xferable.addDataFlavor(flavor);
-  Services.clipboard.getData(xferable, whichClipboard);
-  let data = {};
-  try {
-    xferable.getTransferData(flavor, data);
-  } catch (e) {}
-  data = data.value || null;
-  return data;
-}
-
-/**
- * A helper that returns the size of the image that was just put into the clipboard by the
- * :screenshot command.
- * @return The {width, height} dimension object.
- */
-async function getImageSizeFromClipboard(browser) {
-  let flavor = "image/png";
-  let image = getRawClipboardData(flavor);
-  ok(image, "screenshot data exists on the clipboard");
-
-  // Due to the differences in how images could be stored in the clipboard the
-  // checks below are needed. The clipboard could already provide the image as
-  // byte streams or as image container. If it's not possible obtain a
-  // byte stream, the function throws.
-
-  if (image instanceof Ci.imgIContainer) {
-    image = Cc["@mozilla.org/image/tools;1"]
-      .getService(Ci.imgITools)
-      .encodeImage(image, flavor);
-  }
-
-  if (!(image instanceof Ci.nsIInputStream)) {
-    throw new Error("Unable to read image data");
-  }
-
-  const binaryStream = Cc["@mozilla.org/binaryinputstream;1"].createInstance(
-    Ci.nsIBinaryInputStream
-  );
-  binaryStream.setInputStream(image);
-  const available = binaryStream.available();
-  const buffer = new ArrayBuffer(available);
-  is(
-    binaryStream.readArrayBuffer(available, buffer),
-    available,
-    "Read expected amount of data"
-  );
-
-  // We are going to load the image in the content page to measure its size.
-  // We don't want to insert the image directly in the browser's document
-  // which could mess all sorts of things up
-  return SpecialPowers.spawn(browser, [buffer], async function(_buffer) {
-    const img = content.document.createElement("img");
-    const loaded = new Promise(r => {
-      img.addEventListener("load", r, { once: true });
-    });
-
-    const url = content.URL.createObjectURL(
-      new Blob([_buffer], { type: "image/png" })
-    );
-
-    img.src = url;
-    content.document.documentElement.appendChild(img);
-
-    info("Waiting for the clipboard image to load in the content page");
-    await loaded;
-
-    img.remove();
-    content.URL.revokeObjectURL(url);
-
-    // TODO: could get pixel data as well so we can check colors at specific locations
-    return {
-      width: img.width,
-      height: img.height,
-    };
-  });
-}
-
-add_task(async function common_initialize() {
-  // Ensure Screenshots is initially enabled for all tests
-  const addon = await AddonManager.getAddonByID("screenshots@mozilla.org");
-  const isEnabled = addon.enabled;
-  if (!isEnabled) {
-    await addon.enable({ allowSystemAddons: true });
-    registerCleanupFunction(async () => {
-      await addon.disable({ allowSystemAddons: true });
-    });
-  }
-  // Add the Screenshots button to the toolbar for all tests
-  CustomizableUI.addWidgetToArea(
-    "screenshot-button",
-    CustomizableUI.AREA_NAVBAR
-  );
-  registerCleanupFunction(() =>
-    CustomizableUI.removeWidgetFromArea("screenshot-button")
-  );
-  let screenshotBtn = document.getElementById("screenshot-button");
-  Assert.ok(screenshotBtn, "The screenshots button was added to the nav bar");
-});