summaryrefslogtreecommitdiffstats
path: root/browser/components/screenshots/tests
diff options
context:
space:
mode:
Diffstat (limited to 'browser/components/screenshots/tests')
-rw-r--r--browser/components/screenshots/tests/browser/browser.toml10
-rw-r--r--browser/components/screenshots/tests/browser/browser_screenshots_drag_scroll_test.js17
-rw-r--r--browser/components/screenshots/tests/browser/browser_screenshots_test_downloads.js2
-rw-r--r--browser/components/screenshots/tests/browser/browser_screenshots_test_full_page.js105
-rw-r--r--browser/components/screenshots/tests/browser/browser_screenshots_test_toggle_pref.js97
-rw-r--r--browser/components/screenshots/tests/browser/browser_screenshots_test_visible.js206
-rw-r--r--browser/components/screenshots/tests/browser/browser_test_moving_tab_to_new_window.js123
-rw-r--r--browser/components/screenshots/tests/browser/head.js39
8 files changed, 435 insertions, 164 deletions
diff --git a/browser/components/screenshots/tests/browser/browser.toml b/browser/components/screenshots/tests/browser/browser.toml
index b363c14732..b27d28c677 100644
--- a/browser/components/screenshots/tests/browser/browser.toml
+++ b/browser/components/screenshots/tests/browser/browser.toml
@@ -16,14 +16,22 @@ prefs = [
]
["browser_iframe_test.js"]
+skip-if = ["os == 'linux'"]
["browser_overlay_keyboard_test.js"]
["browser_screenshots_drag_scroll_test.js"]
+skip-if = [
+ "apple_silicon && !debug", # Bug 1804441
+ "apple_catalina", # Bug 1804441
+]
["browser_screenshots_drag_test.js"]
["browser_screenshots_focus_test.js"]
+skip-if = [
+ "os == 'linux' && os_version == '18.04'", # Bug 1803618
+]
["browser_screenshots_overlay_panel_sync.js"]
@@ -52,4 +60,6 @@ skip-if = ["!crashreporter"]
["browser_test_element_picker.js"]
+["browser_test_moving_tab_to_new_window.js"]
+
["browser_test_resize.js"]
diff --git a/browser/components/screenshots/tests/browser/browser_screenshots_drag_scroll_test.js b/browser/components/screenshots/tests/browser/browser_screenshots_drag_scroll_test.js
index 7fdb084ca6..757d721268 100644
--- a/browser/components/screenshots/tests/browser/browser_screenshots_drag_scroll_test.js
+++ b/browser/components/screenshots/tests/browser/browser_screenshots_drag_scroll_test.js
@@ -283,6 +283,23 @@ add_task(async function test_scrollingScreenshotsOpen() {
let { scrollWidth, scrollHeight } =
await helper.getScreenshotsOverlayDimensions();
+ info(
+ JSON.stringify(
+ {
+ left,
+ top,
+ right,
+ bottom,
+ width,
+ height,
+ scrollWidth,
+ scrollHeight,
+ },
+ null,
+ 2
+ )
+ );
+
is(left, startX, "The box left is 10");
is(top, startY, "The box top is 10");
is(
diff --git a/browser/components/screenshots/tests/browser/browser_screenshots_test_downloads.js b/browser/components/screenshots/tests/browser/browser_screenshots_test_downloads.js
index 770a7ae06b..51d5b858b9 100644
--- a/browser/components/screenshots/tests/browser/browser_screenshots_test_downloads.js
+++ b/browser/components/screenshots/tests/browser/browser_screenshots_test_downloads.js
@@ -29,7 +29,7 @@ add_setup(async function () {
],
});
- MockFilePicker.init(window);
+ MockFilePicker.init(window.browsingContext);
MockFilePicker.useAnyFile();
MockFilePicker.returnValue = MockFilePicker.returnOK;
diff --git a/browser/components/screenshots/tests/browser/browser_screenshots_test_full_page.js b/browser/components/screenshots/tests/browser/browser_screenshots_test_full_page.js
index 51cda963d9..006a9819ed 100644
--- a/browser/components/screenshots/tests/browser/browser_screenshots_test_full_page.js
+++ b/browser/components/screenshots/tests/browser/browser_screenshots_test_full_page.js
@@ -3,8 +3,11 @@
"use strict";
-function assertRange(lhs, rhsMin, rhsMax, msg) {
- Assert.ok(lhs >= rhsMin && lhs <= rhsMax, msg);
+function assertPixel(actual, expected, message) {
+ info(message);
+ isfuzzy(actual[0], expected[0], 1, "R color value");
+ isfuzzy(actual[1], expected[1], 1, "G color value");
+ isfuzzy(actual[2], expected[2], 1, "B color value");
}
add_task(async function test_fullpageScreenshot() {
@@ -65,25 +68,36 @@ add_task(async function test_fullpageScreenshot() {
Assert.equal(result.width, expectedWidth, "Widths should be equal");
Assert.equal(result.height, expectedHeight, "Heights should be equal");
- // top left
- assertRange(result.color.topLeft[0], 110, 111, "R color value");
- assertRange(result.color.topLeft[1], 110, 111, "G color value");
- assertRange(result.color.topLeft[2], 110, 111, "B color value");
-
- // top right
- assertRange(result.color.topRight[0], 55, 56, "R color value");
- assertRange(result.color.topRight[1], 155, 156, "G color value");
- assertRange(result.color.topRight[2], 155, 156, "B color value");
-
- // bottom left
- assertRange(result.color.bottomLeft[0], 105, 106, "R color value");
- assertRange(result.color.bottomLeft[1], 55, 56, "G color value");
- assertRange(result.color.bottomLeft[2], 105, 106, "B color value");
-
- // bottom right
- assertRange(result.color.bottomRight[0], 52, 53, "R color value");
- assertRange(result.color.bottomRight[1], 127, 128, "G color value");
- assertRange(result.color.bottomRight[2], 152, 153, "B color value");
+ // Due to https://bugzil.la/1396587, the pasted image colors differ from
+ // the original image on macOS. Once that bug is fixed, we can remove the
+ // special check for macOS.
+ if (AppConstants.platform === "macosx") {
+ assertPixel(result.color.topLeft, [130, 130, 130], "Top left pixel");
+ assertPixel(result.color.topRight, [66, 170, 171], "Top right pixel");
+ assertPixel(
+ result.color.bottomLeft,
+ [125, 75, 125],
+ "Bottom left pixel"
+ );
+ assertPixel(
+ result.color.bottomRight,
+ [64, 145, 169],
+ "Bottom right pixel"
+ );
+ } else {
+ assertPixel(result.color.topLeft, [111, 111, 111], "Top left pixel");
+ assertPixel(result.color.topRight, [55, 155, 155], "Top right pixel");
+ assertPixel(
+ result.color.bottomLeft,
+ [105, 55, 105],
+ "Bottom left pixel"
+ );
+ assertPixel(
+ result.color.bottomRight,
+ [52, 127, 152],
+ "Bottom right pixel"
+ );
+ }
}
);
});
@@ -151,25 +165,36 @@ add_task(async function test_fullpageScreenshotScrolled() {
Assert.equal(result.width, expectedWidth, "Widths should be equal");
Assert.equal(result.height, expectedHeight, "Heights should be equal");
- // top left
- assertRange(result.color.topLeft[0], 110, 111, "R color value");
- assertRange(result.color.topLeft[1], 110, 111, "G color value");
- assertRange(result.color.topLeft[2], 110, 111, "B color value");
-
- // top right
- assertRange(result.color.topRight[0], 55, 56, "R color value");
- assertRange(result.color.topRight[1], 155, 156, "G color value");
- assertRange(result.color.topRight[2], 155, 156, "B color value");
-
- // bottom left
- assertRange(result.color.bottomLeft[0], 105, 106, "R color value");
- assertRange(result.color.bottomLeft[1], 55, 56, "G color value");
- assertRange(result.color.bottomLeft[2], 105, 106, "B color value");
-
- // bottom right
- assertRange(result.color.bottomRight[0], 52, 53, "R color value");
- assertRange(result.color.bottomRight[1], 127, 128, "G color value");
- assertRange(result.color.bottomRight[2], 152, 153, "B color value");
+ // Due to https://bugzil.la/1396587, the pasted image colors differ from
+ // the original image on macOS. Once that bug is fixed, we can remove the
+ // special check for macOS.
+ if (AppConstants.platform === "macosx") {
+ assertPixel(result.color.topLeft, [130, 130, 130], "Top left pixel");
+ assertPixel(result.color.topRight, [66, 170, 171], "Top right pixel");
+ assertPixel(
+ result.color.bottomLeft,
+ [125, 75, 125],
+ "Bottom left pixel"
+ );
+ assertPixel(
+ result.color.bottomRight,
+ [64, 145, 169],
+ "Bottom right pixel"
+ );
+ } else {
+ assertPixel(result.color.topLeft, [111, 111, 111], "Top left pixel");
+ assertPixel(result.color.topRight, [55, 155, 155], "Top right pixel");
+ assertPixel(
+ result.color.bottomLeft,
+ [105, 55, 105],
+ "Bottom left pixel"
+ );
+ assertPixel(
+ result.color.bottomRight,
+ [52, 127, 152],
+ "Bottom right pixel"
+ );
+ }
}
);
});
diff --git a/browser/components/screenshots/tests/browser/browser_screenshots_test_toggle_pref.js b/browser/components/screenshots/tests/browser/browser_screenshots_test_toggle_pref.js
index 0aafba8fb3..ad262a7e67 100644
--- a/browser/components/screenshots/tests/browser/browser_screenshots_test_toggle_pref.js
+++ b/browser/components/screenshots/tests/browser/browser_screenshots_test_toggle_pref.js
@@ -9,6 +9,7 @@ const { sinon } = ChromeUtils.importESModule(
ChromeUtils.defineESModuleGetters(this, {
ScreenshotsUtils: "resource:///modules/ScreenshotsUtils.sys.mjs",
+ AddonManager: "resource://gre/modules/AddonManager.sys.mjs",
});
ChromeUtils.defineLazyGetter(this, "ExtensionManagement", () => {
const { Management } = ChromeUtils.importESModule(
@@ -17,7 +18,11 @@ ChromeUtils.defineLazyGetter(this, "ExtensionManagement", () => {
return Management;
});
-add_task(async function test() {
+const COMPONENT_PREF = "screenshots.browser.component.enabled";
+const SCREENSHOTS_PREF = "extensions.screenshots.disabled";
+const SCREENSHOT_EXTENSION = "screenshots@mozilla.org";
+
+add_task(async function test_toggling_screenshots_pref() {
let observerSpy = sinon.spy();
let notifierSpy = sinon.spy();
@@ -31,13 +36,24 @@ add_task(async function test() {
ScreenshotsUtils.notify.wrappedMethod.apply(this, arguments);
});
+ // wait for startup idle tasks to complete
+ await new Promise(resolve => ChromeUtils.idleDispatch(resolve));
+ ok(Services.prefs.getBoolPref(COMPONENT_PREF), "Component enabled");
+ ok(!Services.prefs.getBoolPref(SCREENSHOTS_PREF), "Screenshots enabled");
+
+ let addon = await AddonManager.getAddonByID(SCREENSHOT_EXTENSION);
+ await BrowserTestUtils.waitForCondition(
+ () => !addon.isActive,
+ "The extension is not active when the component is prefd on"
+ );
+
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: SHORT_TEST_PAGE,
},
async browser => {
- function awaitExtensionEvent(eventName, id) {
+ function extensionEventPromise(eventName, id) {
return new Promise(resolve => {
let listener = (_eventName, ...args) => {
let extension = args[0];
@@ -49,9 +65,21 @@ add_task(async function test() {
ExtensionManagement.on(eventName, listener);
});
}
- const SCREENSHOT_EXTENSION = "screenshots@mozilla.org";
let helper = new ScreenshotsHelper(browser);
+ ok(
+ addon.userDisabled,
+ "The extension is disabled when the component is prefd on"
+ );
+ ok(
+ !addon.isActive,
+ "The extension is not initially active when the component is prefd on"
+ );
+ await BrowserTestUtils.waitForCondition(
+ () => ScreenshotsUtils.initialized,
+ "The component is initialized"
+ );
+ ok(ScreenshotsUtils.initialized, "The component is initialized");
ok(observerSpy.notCalled, "Observer not called");
helper.triggerUIFromToolbar();
@@ -80,12 +108,20 @@ add_task(async function test() {
Assert.equal(observerSpy.callCount, 3, "Observer function called thrice");
- const COMPONENT_PREF = "screenshots.browser.component.enabled";
- await SpecialPowers.pushPrefEnv({
- set: [[COMPONENT_PREF, false]],
- });
+ let extensionReadyPromise = extensionEventPromise(
+ "ready",
+ SCREENSHOT_EXTENSION
+ );
+ Services.prefs.setBoolPref(COMPONENT_PREF, false);
ok(!Services.prefs.getBoolPref(COMPONENT_PREF), "Extension enabled");
- await awaitExtensionEvent("ready", SCREENSHOT_EXTENSION);
+
+ info("Waiting for the extension ready event");
+ await extensionReadyPromise;
+ await BrowserTestUtils.waitForCondition(
+ () => !addon.userDisabled,
+ "The extension gets un-disabled when the component is prefd off"
+ );
+ ok(addon.isActive, "Extension is active");
helper.triggerUIFromToolbar();
Assert.equal(
@@ -94,6 +130,7 @@ add_task(async function test() {
"Observer function still called thrice"
);
+ info("Waiting for the extensions overlay");
await SpecialPowers.spawn(
browser,
["#firefox-screenshots-preselection-iframe"],
@@ -115,6 +152,7 @@ add_task(async function test() {
}
);
+ info("Waiting for the extensions overlay");
helper.triggerUIFromToolbar();
await SpecialPowers.spawn(
browser,
@@ -202,9 +240,7 @@ add_task(async function test() {
"screenshots-component-initialized"
);
- await SpecialPowers.pushPrefEnv({
- set: [[COMPONENT_PREF, true]],
- });
+ Services.prefs.setBoolPref(COMPONENT_PREF, true);
ok(Services.prefs.getBoolPref(COMPONENT_PREF), "Component enabled");
// Needed for component to initialize
await componentReady;
@@ -215,12 +251,6 @@ add_task(async function test() {
4,
"Observer function called four times"
);
-
- const SCREENSHOTS_PREF = "extensions.screenshots.disabled";
- await SpecialPowers.pushPrefEnv({
- set: [[SCREENSHOTS_PREF, true]],
- });
- ok(Services.prefs.getBoolPref(SCREENSHOTS_PREF), "Screenshots disabled");
}
);
@@ -230,7 +260,9 @@ add_task(async function test() {
url: SHORT_TEST_PAGE,
},
async browser => {
- const SCREENSHOTS_PREF = "extensions.screenshots.disabled";
+ Services.prefs.setBoolPref(SCREENSHOTS_PREF, true);
+ Services.prefs.setBoolPref(COMPONENT_PREF, true);
+
ok(Services.prefs.getBoolPref(SCREENSHOTS_PREF), "Screenshots disabled");
ok(
@@ -255,22 +287,23 @@ add_task(async function test() {
menu.hidePopup();
await popuphidden;
- await SpecialPowers.pushPrefEnv({
- set: [[SCREENSHOTS_PREF, false]],
- });
- ok(!Services.prefs.getBoolPref(SCREENSHOTS_PREF), "Screenshots enabled");
- }
- );
+ let componentReady = TestUtils.topicObserved(
+ "screenshots-component-initialized"
+ );
+
+ Services.prefs.setBoolPref(SCREENSHOTS_PREF, false);
- await BrowserTestUtils.withNewTab(
- {
- gBrowser,
- url: SHORT_TEST_PAGE,
- },
- async browser => {
- const SCREENSHOTS_PREF = "extensions.screenshots.disabled";
ok(!Services.prefs.getBoolPref(SCREENSHOTS_PREF), "Screenshots enabled");
+ await componentReady;
+
+ ok(ScreenshotsUtils.initialized, "The component is initialized");
+
+ ok(
+ !document.getElementById("screenshot-button").disabled,
+ "Toolbar button is enabled"
+ );
+
let helper = new ScreenshotsHelper(browser);
helper.triggerUIFromToolbar();
@@ -284,6 +317,4 @@ add_task(async function test() {
observerStub.restore();
notifierStub.restore();
-
- await SpecialPowers.popPrefEnv();
});
diff --git a/browser/components/screenshots/tests/browser/browser_screenshots_test_visible.js b/browser/components/screenshots/tests/browser/browser_screenshots_test_visible.js
index 7b7a46f73d..c53b44d5ea 100644
--- a/browser/components/screenshots/tests/browser/browser_screenshots_test_visible.js
+++ b/browser/components/screenshots/tests/browser/browser_screenshots_test_visible.js
@@ -3,6 +3,13 @@
"use strict";
+function assertPixel(actual, expected, message) {
+ info(message);
+ isfuzzy(actual[0], expected[0], 1, "R color value");
+ isfuzzy(actual[1], expected[1], 1, "G color value");
+ isfuzzy(actual[2], expected[2], 1, "B color value");
+}
+
add_task(async function test_visibleScreenshot() {
await BrowserTestUtils.withNewTab(
{
@@ -65,25 +72,36 @@ add_task(async function test_visibleScreenshot() {
Assert.equal(result.width, expectedWidth, "Widths should be equal");
Assert.equal(result.height, expectedHeight, "Heights should be equal");
- // top left
- Assert.equal(111, result.color.topLeft[0], "R color value");
- Assert.equal(111, result.color.topLeft[1], "G color value");
- Assert.equal(111, result.color.topLeft[2], "B color value");
-
- // top right
- Assert.equal(111, result.color.topRight[0], "R color value");
- Assert.equal(111, result.color.topRight[1], "G color value");
- Assert.equal(111, result.color.topRight[2], "B color value");
-
- // bottom left
- Assert.equal(111, result.color.bottomLeft[0], "R color value");
- Assert.equal(111, result.color.bottomLeft[1], "G color value");
- Assert.equal(111, result.color.bottomLeft[2], "B color value");
-
- // bottom right
- Assert.equal(111, result.color.bottomRight[0], "R color value");
- Assert.equal(111, result.color.bottomRight[1], "G color value");
- Assert.equal(111, result.color.bottomRight[2], "B color value");
+ // Due to https://bugzil.la/1396587, the pasted image colors differ from
+ // the original image on macOS. Once that bug is fixed, we can remove the
+ // special check for macOS.
+ if (AppConstants.platform === "macosx") {
+ assertPixel(result.color.topLeft, [130, 130, 130], "Top left pixel");
+ assertPixel(result.color.topRight, [130, 130, 130], "Top right pixel");
+ assertPixel(
+ result.color.bottomLeft,
+ [130, 130, 130],
+ "Bottom left pixel"
+ );
+ assertPixel(
+ result.color.bottomRight,
+ [130, 130, 130],
+ "Bottom right pixel"
+ );
+ } else {
+ assertPixel(result.color.topLeft, [111, 111, 111], "Top left pixel");
+ assertPixel(result.color.topRight, [111, 111, 111], "Top right pixel");
+ assertPixel(
+ result.color.bottomLeft,
+ [111, 111, 111],
+ "Bottom left pixel"
+ );
+ assertPixel(
+ result.color.bottomRight,
+ [111, 111, 111],
+ "Bottom right pixel"
+ );
+ }
}
);
});
@@ -147,34 +165,42 @@ add_task(async function test_visibleScreenshotScrolledY() {
info("Waiting for clipboard change");
let result = await clipboardChanged;
- // let result = await helper.getImageSizeAndColorFromClipboard();
- // debugger;
-
info("result: " + JSON.stringify(result, null, 2));
info("contentInfo: " + JSON.stringify(contentInfo, null, 2));
Assert.equal(result.width, expectedWidth, "Widths should be equal");
Assert.equal(result.height, expectedHeight, "Heights should be equal");
- // top left
- Assert.equal(105, result.color.topLeft[0], "R color value");
- Assert.equal(55, result.color.topLeft[1], "G color value");
- Assert.equal(105, result.color.topLeft[2], "B color value");
-
- // top right
- Assert.equal(105, result.color.topRight[0], "R color value");
- Assert.equal(55, result.color.topRight[1], "G color value");
- Assert.equal(105, result.color.topRight[2], "B color value");
-
- // bottom left
- Assert.equal(105, result.color.bottomLeft[0], "R color value");
- Assert.equal(55, result.color.bottomLeft[1], "G color value");
- Assert.equal(105, result.color.bottomLeft[2], "B color value");
-
- // bottom right
- Assert.equal(105, result.color.bottomRight[0], "R color value");
- Assert.equal(55, result.color.bottomRight[1], "G color value");
- Assert.equal(105, result.color.bottomRight[2], "B color value");
+ // Due to https://bugzil.la/1396587, the pasted image colors differ from
+ // the original image on macOS. Once that bug is fixed, we can remove the
+ // special check for macOS.
+ if (AppConstants.platform === "macosx") {
+ assertPixel(result.color.topLeft, [125, 75, 125], "Top left pixel");
+ assertPixel(result.color.topRight, [125, 75, 125], "Top right pixel");
+ assertPixel(
+ result.color.bottomLeft,
+ [125, 75, 125],
+ "Bottom left pixel"
+ );
+ assertPixel(
+ result.color.bottomRight,
+ [125, 75, 125],
+ "Bottom right pixel"
+ );
+ } else {
+ assertPixel(result.color.topLeft, [105, 55, 105], "Top left pixel");
+ assertPixel(result.color.topRight, [105, 55, 105], "Top right pixel");
+ assertPixel(
+ result.color.bottomLeft,
+ [105, 55, 105],
+ "Bottom left pixel"
+ );
+ assertPixel(
+ result.color.bottomRight,
+ [105, 55, 105],
+ "Bottom right pixel"
+ );
+ }
}
);
});
@@ -244,25 +270,36 @@ add_task(async function test_visibleScreenshotScrolledX() {
Assert.equal(result.width, expectedWidth, "Widths should be equal");
Assert.equal(result.height, expectedHeight, "Heights should be equal");
- // top left
- Assert.equal(55, result.color.topLeft[0], "R color value");
- Assert.equal(155, result.color.topLeft[1], "G color value");
- Assert.equal(155, result.color.topLeft[2], "B color value");
-
- // top right
- Assert.equal(55, result.color.topRight[0], "R color value");
- Assert.equal(155, result.color.topRight[1], "G color value");
- Assert.equal(155, result.color.topRight[2], "B color value");
-
- // bottom left
- Assert.equal(55, result.color.bottomLeft[0], "R color value");
- Assert.equal(155, result.color.bottomLeft[1], "G color value");
- Assert.equal(155, result.color.bottomLeft[2], "B color value");
-
- // bottom right
- Assert.equal(55, result.color.bottomRight[0], "R color value");
- Assert.equal(155, result.color.bottomRight[1], "G color value");
- Assert.equal(155, result.color.bottomRight[2], "B color value");
+ // Due to https://bugzil.la/1396587, the pasted image colors differ from
+ // the original image on macOS. Once that bug is fixed, we can remove the
+ // special check for macOS.
+ if (AppConstants.platform === "macosx") {
+ assertPixel(result.color.topLeft, [66, 170, 171], "Top left pixel");
+ assertPixel(result.color.topRight, [66, 170, 171], "Top right pixel");
+ assertPixel(
+ result.color.bottomLeft,
+ [66, 170, 171],
+ "Bottom left pixel"
+ );
+ assertPixel(
+ result.color.bottomRight,
+ [66, 170, 171],
+ "Bottom right pixel"
+ );
+ } else {
+ assertPixel(result.color.topLeft, [55, 155, 155], "Top left pixel");
+ assertPixel(result.color.topRight, [55, 155, 155], "Top right pixel");
+ assertPixel(
+ result.color.bottomLeft,
+ [55, 155, 155],
+ "Bottom left pixel"
+ );
+ assertPixel(
+ result.color.bottomRight,
+ [55, 155, 155],
+ "Bottom right pixel"
+ );
+ }
}
);
});
@@ -332,25 +369,36 @@ add_task(async function test_visibleScreenshotScrolledXAndY() {
Assert.equal(result.width, expectedWidth, "Widths should be equal");
Assert.equal(result.height, expectedHeight, "Heights should be equal");
- // top left
- Assert.equal(52, result.color.topLeft[0], "R color value");
- Assert.equal(127, result.color.topLeft[1], "G color value");
- Assert.equal(152, result.color.topLeft[2], "B color value");
-
- // top right
- Assert.equal(52, result.color.topRight[0], "R color value");
- Assert.equal(127, result.color.topRight[1], "G color value");
- Assert.equal(152, result.color.topRight[2], "B color value");
-
- // bottom left
- Assert.equal(52, result.color.bottomLeft[0], "R color value");
- Assert.equal(127, result.color.bottomLeft[1], "G color value");
- Assert.equal(152, result.color.bottomLeft[2], "B color value");
-
- // bottom right
- Assert.equal(52, result.color.bottomRight[0], "R color value");
- Assert.equal(127, result.color.bottomRight[1], "G color value");
- Assert.equal(152, result.color.bottomRight[2], "B color value");
+ // Due to https://bugzil.la/1396587, the pasted image colors differ from
+ // the original image on macOS. Once that bug is fixed, we can remove the
+ // special check for macOS.
+ if (AppConstants.platform === "macosx") {
+ assertPixel(result.color.topLeft, [64, 145, 169], "Top left pixel");
+ assertPixel(result.color.topRight, [64, 145, 169], "Top right pixel");
+ assertPixel(
+ result.color.bottomLeft,
+ [64, 145, 169],
+ "Bottom left pixel"
+ );
+ assertPixel(
+ result.color.bottomRight,
+ [64, 145, 169],
+ "Bottom right pixel"
+ );
+ } else {
+ assertPixel(result.color.topLeft, [52, 127, 152], "Top left pixel");
+ assertPixel(result.color.topRight, [52, 127, 152], "Top right pixel");
+ assertPixel(
+ result.color.bottomLeft,
+ [52, 127, 152],
+ "Bottom left pixel"
+ );
+ assertPixel(
+ result.color.bottomRight,
+ [52, 127, 152],
+ "Bottom right pixel"
+ );
+ }
}
);
});
diff --git a/browser/components/screenshots/tests/browser/browser_test_moving_tab_to_new_window.js b/browser/components/screenshots/tests/browser/browser_test_moving_tab_to_new_window.js
new file mode 100644
index 0000000000..c3bb546f3a
--- /dev/null
+++ b/browser/components/screenshots/tests/browser/browser_test_moving_tab_to_new_window.js
@@ -0,0 +1,123 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function test_movingTabToNewWindow() {
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE);
+ let originalHelper = new ScreenshotsHelper(tab.linkedBrowser);
+ originalHelper.triggerUIFromToolbar();
+ await originalHelper.waitForOverlay();
+ await originalHelper.dragOverlay(10, 10, 300, 300);
+
+ let newWindow = gBrowser.replaceTabWithWindow(tab);
+ let swapDocShellPromise = BrowserTestUtils.waitForEvent(
+ tab.linkedBrowser,
+ "SwapDocShells"
+ );
+ await swapDocShellPromise;
+
+ let newtab = newWindow.gBrowser.selectedTab;
+ let newHelper = new ScreenshotsHelper(newtab.linkedBrowser);
+
+ let isInitialized = await newHelper.isOverlayInitialized();
+
+ ok(isInitialized, "Overlay is initialized after switching windows");
+ ok(
+ !ScreenshotsUtils.browserToScreenshotsState.has(tab.linkedBrowser),
+ "The old browser is no longer in the ScreenshotsUtils weakmap"
+ );
+ ok(
+ ScreenshotsUtils.browserToScreenshotsState.has(newtab.linkedBrowser),
+ "The new browser is in the ScreenshotsUtils weakmap"
+ );
+
+ await newHelper.clickCancelButton();
+ await newHelper.assertStateChange("crosshairs");
+ await newHelper.waitForOverlay();
+
+ swapDocShellPromise = BrowserTestUtils.waitForEvent(
+ newtab.linkedBrowser,
+ "SwapDocShells"
+ );
+ gBrowser.adoptTab(newWindow.gBrowser.selectedTab, 1, true);
+ await swapDocShellPromise;
+
+ tab = gBrowser.selectedTab;
+ let helper = new ScreenshotsHelper(tab.linkedBrowser);
+
+ isInitialized = await helper.isOverlayInitialized();
+
+ ok(!isInitialized, "Overlay is not initialized");
+ ok(
+ !ScreenshotsUtils.browserToScreenshotsState.has(tab.linkedBrowser),
+ "The old browser is no longer in the ScreenshotsUtils weakmap"
+ );
+ ok(
+ !ScreenshotsUtils.browserToScreenshotsState.has(newtab.linkedBrowser),
+ "The new browser is no longer in the ScreenshotsUtils weakmap"
+ );
+
+ await BrowserTestUtils.removeTab(tab);
+});
+
+add_task(async function test_movingParentProcessTabToNewWindow() {
+ let tab = await BrowserTestUtils.openNewForegroundTab(
+ gBrowser,
+ "about:robots"
+ );
+ let originalHelper = new ScreenshotsHelper(tab.linkedBrowser);
+ originalHelper.triggerUIFromToolbar();
+ await originalHelper.waitForOverlay();
+ await originalHelper.dragOverlay(10, 10, 300, 300);
+
+ let newWindow = gBrowser.replaceTabWithWindow(tab);
+ let swapDocShellPromise = BrowserTestUtils.waitForEvent(
+ tab.linkedBrowser,
+ "SwapDocShells"
+ );
+ await swapDocShellPromise;
+
+ let newtab = newWindow.gBrowser.selectedTab;
+ let newHelper = new ScreenshotsHelper(newtab.linkedBrowser);
+
+ let isInitialized = await newHelper.isOverlayInitialized();
+
+ ok(isInitialized, "Overlay is initialized after switching windows");
+ ok(
+ !ScreenshotsUtils.browserToScreenshotsState.has(tab.linkedBrowser),
+ "The old browser is no longer in the ScreenshotsUtils weakmap"
+ );
+ ok(
+ ScreenshotsUtils.browserToScreenshotsState.has(newtab.linkedBrowser),
+ "The new browser is in the ScreenshotsUtils weakmap"
+ );
+
+ await newHelper.clickCancelButton();
+ await newHelper.assertStateChange("crosshairs");
+ await newHelper.waitForOverlay();
+
+ swapDocShellPromise = BrowserTestUtils.waitForEvent(
+ newtab.linkedBrowser,
+ "SwapDocShells"
+ );
+ gBrowser.adoptTab(newWindow.gBrowser.selectedTab, 1, true);
+ await swapDocShellPromise;
+
+ tab = gBrowser.selectedTab;
+ let helper = new ScreenshotsHelper(tab.linkedBrowser);
+
+ isInitialized = await helper.isOverlayInitialized();
+
+ ok(!isInitialized, "Overlay is not initialized");
+ ok(
+ !ScreenshotsUtils.browserToScreenshotsState.has(tab.linkedBrowser),
+ "The old browser is no longer in the ScreenshotsUtils weakmap"
+ );
+ ok(
+ !ScreenshotsUtils.browserToScreenshotsState.has(newtab.linkedBrowser),
+ "The new browser is no longer in the ScreenshotsUtils weakmap"
+ );
+
+ await BrowserTestUtils.removeTab(tab);
+});
diff --git a/browser/components/screenshots/tests/browser/head.js b/browser/components/screenshots/tests/browser/head.js
index 171e3b8c41..a36e955830 100644
--- a/browser/components/screenshots/tests/browser/head.js
+++ b/browser/components/screenshots/tests/browser/head.js
@@ -38,15 +38,21 @@ const MouseEvents = {
{},
{
get: (target, name) =>
- async function (x, y, options = {}) {
+ async function (x, y, options = {}, browser) {
if (name === "click") {
- this.down(x, y, options);
- this.up(x, y, options);
+ this.down(x, y, options, browser);
+ this.up(x, y, options, browser);
} else {
- await safeSynthesizeMouseEventInContentPage(":root", x, y, {
- type: "mouse" + name,
- ...options,
- });
+ await safeSynthesizeMouseEventInContentPage(
+ ":root",
+ x,
+ y,
+ {
+ type: "mouse" + name,
+ ...options,
+ },
+ browser
+ );
}
},
}
@@ -276,10 +282,15 @@ class ScreenshotsHelper {
this.waitForStateChange("resizing"),
]);
Assert.ok(true, "The overlay is in the dragging or resizing state");
-
+ // We intentionally turn off this a11y check, because the following mouse
+ // event is emitted at the end of the dragging event. Its keyboard
+ // accessible alternative is provided and tested elsewhere, therefore
+ // this rule check shall be ignored by a11y_checks suite.
+ AccessibilityUtils.setEnv({ mustHaveAccessibleRule: false });
mouse.up(endX, endY);
await this.assertStateChange("selected");
+ AccessibilityUtils.resetEnv();
this.endX = endX;
this.endY = endY;
@@ -474,7 +485,7 @@ class ScreenshotsHelper {
);
info(`clicking cancel button at ${x}, ${y}`);
- mouse.click(x, y);
+ mouse.click(x, y, {}, this.browser);
}
async clickPreviewCancelButton() {
@@ -878,9 +889,15 @@ async function safeSynthesizeMouseEventInContentPage(
selector,
x,
y,
- options = {}
+ options = {},
+ browser
) {
- let context = gBrowser.selectedBrowser.browsingContext;
+ let context;
+ if (!browser) {
+ context = gBrowser.selectedBrowser.browsingContext;
+ } else {
+ context = browser.browsingContext;
+ }
BrowserTestUtils.synthesizeMouse(selector, x, y, options, context);
}