Bug 1844171 - Update screenshots tests. r=sfoster

Differential Revision: https://phabricator.services.mozilla.com/D183912
This commit is contained in:
Niklas Baumgardner
2023-07-27 16:15:03 +00:00
parent 8464bcdbb9
commit 5eafa5cac5
4 changed files with 89 additions and 104 deletions

View File

@@ -21,19 +21,19 @@ add_task(async function test_overlayCoversEntirePage() {
helper.triggerUIFromToolbar();
await helper.waitForOverlay();
await helper.dragOverlay(10, 10, 500, 500);
let dimensions = await helper.getSelectionLayerDimensions();
info(JSON.stringify(dimensions));
let { scrollWidth, scrollHeight } =
await helper.getScreenshotsOverlayDimensions();
is(
dimensions.scrollWidth,
scrollWidth,
contentInfo.scrollWidth,
"The overlay spans the entire width of the page"
);
is(
dimensions.scrollHeight,
scrollHeight,
contentInfo.scrollHeight,
"The overlay spans the entire height of the page"
);
@@ -78,12 +78,12 @@ add_task(async function test_draggingBoxOffTopLeft() {
mouse.move(10, 10);
// We moved the box to the edge of the screen so we need to wait until the box size is updated
await helper.waitForSelectionBoxSizeChange(490);
await helper.waitForSelectionRegionSizeChange(490);
let dimensions = await helper.getSelectionBoxDimensions();
let dimensions = await helper.getSelectionRegionDimensions();
is(dimensions.x1, 0, "The box x1 position is now 0");
is(dimensions.y1, 0, "The box y1 position is now 0");
is(dimensions.left, 0, "The box x1 position is now 0");
is(dimensions.top, 0, "The box y1 position is now 0");
is(dimensions.width, 255, "The box width is now 255");
is(dimensions.height, 255, "The box height is now 255");
@@ -98,12 +98,12 @@ add_task(async function test_draggingBoxOffTopLeft() {
);
// We moved the box off the edge of the screen so we need to wait until the box size is updated
await helper.waitForSelectionBoxSizeChange(255);
await helper.waitForSelectionRegionSizeChange(255);
dimensions = await helper.getSelectionBoxDimensions();
dimensions = await helper.getSelectionRegionDimensions();
is(dimensions.x1, 10, "The box x1 position is now 10 again");
is(dimensions.y1, 10, "The box y1 position is now 10 again");
is(dimensions.left, 10, "The box x1 position is now 10 again");
is(dimensions.top, 10, "The box y1 position is now 10 again");
is(dimensions.width, 490, "The box width is now 490 again");
is(dimensions.height, 490, "The box height is now 490 again");
}
@@ -159,12 +159,12 @@ add_task(async function test_draggingBoxOffBottomRight() {
mouse.move(endX, endY);
// We moved the box to the edge of the screen so we need to wait until the box size is updated
await helper.waitForSelectionBoxSizeChange(480);
await helper.waitForSelectionRegionSizeChange(480);
let dimensions = await helper.getSelectionBoxDimensions();
let dimensions = await helper.getSelectionRegionDimensions();
is(dimensions.x1, startX + 240, "The box x1 position is now 3748");
is(dimensions.y1, startY + 240, "The box y1 position is now 3756");
is(dimensions.left, startX + 240, "The box x1 position is now 3748");
is(dimensions.top, startY + 240, "The box y1 position is now 3756");
is(dimensions.width, 260, "The box width is now 260");
is(dimensions.height, 260, "The box height is now 260");
@@ -179,12 +179,12 @@ add_task(async function test_draggingBoxOffBottomRight() {
);
// We moved the box off the edge of the screen so we need to wait until the box size is updated
await helper.waitForSelectionBoxSizeChange(252);
await helper.waitForSelectionRegionSizeChange(252);
dimensions = await helper.getSelectionBoxDimensions();
dimensions = await helper.getSelectionRegionDimensions();
is(dimensions.x1, startX, "The box x1 position is now 3508 again");
is(dimensions.y1, startY, "The box y1 position is now 3516 again");
is(dimensions.left, startX, "The box x1 position is now 3508 again");
is(dimensions.top, startY, "The box y1 position is now 3516 again");
is(dimensions.width, 480, "The box width is now 480 again");
is(dimensions.height, 480, "The box height is now 480 again");
}
@@ -223,10 +223,10 @@ add_task(async function test_scrollingScreenshotsOpen() {
await helper.scrollContentWindow(scrollX, scrollY);
let dimensions = await helper.getSelectionBoxDimensions();
let dimensions = await helper.getSelectionRegionDimensions();
is(dimensions.x1, startX, "The box x1 position is 10");
is(dimensions.y1, startY, "The box y1 position is 10");
is(dimensions.left, startX, "The box x1 position is 10");
is(dimensions.top, startY, "The box y1 position is 10");
is(dimensions.width, endX - startX, "The box width is now 90");
is(dimensions.height, endY - startY, "The box height is now 90");
@@ -243,10 +243,10 @@ add_task(async function test_scrollingScreenshotsOpen() {
await helper.scrollContentWindow(0, 0);
dimensions = await helper.getSelectionBoxDimensions();
dimensions = await helper.getSelectionRegionDimensions();
is(dimensions.x1, scrollX + startX, "The box x1 position is 1010");
is(dimensions.y1, scrollY + startY, "The box y1 position is 1010");
is(dimensions.left, scrollX + startX, "The box x1 position is 1010");
is(dimensions.top, scrollY + startY, "The box y1 position is 1010");
is(dimensions.width, endX - startX, "The box width is now 90");
is(dimensions.height, endY - startY, "The box height is now 90");
@@ -282,37 +282,40 @@ add_task(async function test_scrollingScreenshotsOpen() {
await helper.waitForStateChange("selected");
dimensions = await helper.getSelectionLayerDimensions();
info(JSON.stringify(dimensions));
is(dimensions.boxLeft, startX, "The box left is 10");
is(dimensions.boxTop, startY, "The box top is 10");
let { left, top, right, bottom, width, height } =
await helper.getSelectionRegionDimensions();
let { scrollWidth, scrollHeight } =
await helper.getScreenshotsOverlayDimensions();
is(left, startX, "The box left is 10");
is(top, startY, "The box top is 10");
is(
dimensions.boxRight,
right,
contentInfo.clientWidth * 2 - 30,
"The box right is 2 x clientWidth - 30"
);
is(
dimensions.boxBottom,
bottom,
contentInfo.clientHeight * 2 - 30,
"The box right is 2 x clientHeight - 30"
);
is(
dimensions.boxWidth,
width,
contentInfo.clientWidth * 2 - 40,
"The box right is 2 x clientWidth - 40"
);
is(
dimensions.boxHeight,
height,
contentInfo.clientHeight * 2 - 40,
"The box right is 2 x clientHeight - 40"
);
is(
dimensions.scrollWidth,
scrollWidth,
contentInfo.scrollWidth,
"The overlay spans the entire width of the page"
);
is(
dimensions.scrollHeight,
scrollHeight,
contentInfo.scrollHeight,
"The overlay spans the entire height of the page"
);

View File

@@ -24,15 +24,16 @@ add_task(async function test_overlay() {
await helper.dragOverlay(10, 10, 500, 500);
let dimensions = await helper.getSelectionLayerDimensions();
let { scrollWidth, scrollHeight } =
await helper.getScreenshotsOverlayDimensions();
Assert.equal(
dimensions.scrollWidth,
scrollWidth,
contentInfo.clientWidth,
"The overlay spans the width of the window"
);
Assert.equal(
dimensions.scrollHeight,
scrollHeight,
contentInfo.clientHeight,
"The overlay spans the height of the window"
);
@@ -76,7 +77,7 @@ add_task(async function test_window_resize() {
await helper.waitForOverlay();
await helper.dragOverlay(10, 10, 100, 100);
let dimensions = await helper.getSelectionLayerDimensions();
let dimensions = await helper.getScreenshotsOverlayDimensions();
let oldWidth = dimensions.scrollWidth;
let oldHeight = dimensions.scrollHeight;
@@ -90,7 +91,7 @@ add_task(async function test_window_resize() {
await helper.waitForSelectionLayerDimensionChange(oldWidth, oldHeight);
contentInfo = await helper.getContentDimensions();
dimensions = await helper.getSelectionLayerDimensions();
dimensions = await helper.getScreenshotsOverlayDimensions();
Assert.equal(
dimensions.scrollWidth,
contentInfo.clientWidth,
@@ -115,7 +116,7 @@ add_task(async function test_window_resize() {
await helper.waitForSelectionLayerDimensionChange(oldWidth, oldHeight);
contentInfo = await helper.getContentDimensions();
dimensions = await helper.getSelectionLayerDimensions();
dimensions = await helper.getScreenshotsOverlayDimensions();
Assert.equal(
dimensions.scrollWidth,
contentInfo.clientWidth,

View File

@@ -128,7 +128,7 @@ class ScreenshotsHelper {
let screenshotsChild = content.windowGlobalChild.getActor(
"ScreenshotsComponent"
);
return screenshotsChild?._overlay?._initialized;
return screenshotsChild?.overlay?.initialized;
});
}
@@ -137,7 +137,7 @@ class ScreenshotsHelper {
let screenshotsChild = content.windowGlobalChild.getActor(
"ScreenshotsComponent"
);
return screenshotsChild._overlay.stateHandler.getState();
return screenshotsChild.overlay.state;
});
}
@@ -153,7 +153,7 @@ class ScreenshotsHelper {
let screenshotsChild = content.windowGlobalChild.getActor(
"ScreenshotsComponent"
);
return screenshotsChild._overlay.stateHandler.getHoverElementBoxRect();
return screenshotsChild.overlay.hoverElementRegion.dimensions;
});
}
@@ -164,7 +164,7 @@ class ScreenshotsHelper {
});
}
async waitForSelectionBoxSizeChange(currentWidth) {
async waitForSelectionRegionSizeChange(currentWidth) {
await ContentTask.spawn(
this.browser,
[currentWidth],
@@ -173,13 +173,11 @@ class ScreenshotsHelper {
"ScreenshotsComponent"
);
let dimensions =
screenshotsChild._overlay.screenshotsContainer.getSelectionLayerDimensions();
let dimensions = screenshotsChild.overlay.selectionRegion.dimensions;
// return dimensions.boxWidth;
await ContentTaskUtils.waitForCondition(() => {
dimensions =
screenshotsChild._overlay.screenshotsContainer.getSelectionLayerDimensions();
return dimensions.boxWidth !== currWidth;
dimensions = screenshotsChild.overlay.selectionRegion.dimensions;
return dimensions.width !== currWidth;
}, "Wait for selection box width change");
}
);
@@ -273,28 +271,30 @@ class ScreenshotsHelper {
}
clickDownloadButton() {
// Click the download button with last x and y position from dragOverlay.
// The middle of the copy button is last X - 70 and last Y + 36.
// Ex. 500, 500 would be 530, 536
mouse.click(this.endX - 70, this.endY + 36);
ContentTask.spawn(this.browser, null, async () => {
let screenshotsChild = content.windowGlobalChild.getActor(
"ScreenshotsComponent"
);
screenshotsChild.overlay.downloadButton.click();
});
}
clickCopyButton(overrideX = null, overrideY = null) {
// Click the copy button with last x and y position from dragOverlay.
// The middle of the copy button is last X - 183 and last Y + 36.
// Ex. 500, 500 would be 317, 536
if (overrideX && overrideY) {
mouse.click(overrideX - 183, overrideY + 36);
} else {
mouse.click(this.endX - 183, this.endY + 36);
}
clickCopyButton() {
ContentTask.spawn(this.browser, null, async () => {
let screenshotsChild = content.windowGlobalChild.getActor(
"ScreenshotsComponent"
);
screenshotsChild.overlay.copyButton.click();
});
}
clickCancelButton() {
// Click the cancel button with last x and y position from dragOverlay.
// The middle of the copy button is last X - 259 and last Y + 36.
// Ex. 500, 500 would be 241, 536
mouse.click(this.endX - 259, this.endY + 36);
ContentTask.spawn(this.browser, null, async () => {
let screenshotsChild = content.windowGlobalChild.getActor(
"ScreenshotsComponent"
);
screenshotsChild.overlay.cancelButton.click();
});
}
async clickTestPageElement() {
@@ -411,14 +411,18 @@ class ScreenshotsHelper {
});
}
getSelectionLayerDimensions() {
getScreenshotsOverlayDimensions() {
return ContentTask.spawn(this.browser, null, async () => {
let screenshotsChild = content.windowGlobalChild.getActor(
"ScreenshotsComponent"
);
Assert.ok(screenshotsChild._overlay._initialized, "The overlay exists");
Assert.ok(screenshotsChild.overlay.initialized, "The overlay exists");
return screenshotsChild._overlay.screenshotsContainer.getSelectionLayerDimensions();
return {
scrollWidth: screenshotsChild.overlay.screenshotsContainer.scrollWidth,
scrollHeight:
screenshotsChild.overlay.screenshotsContainer.scrollHeight,
};
});
}
@@ -432,54 +436,31 @@ class ScreenshotsHelper {
);
await ContentTaskUtils.waitForCondition(() => {
let dimensions =
screenshotsChild._overlay.screenshotsContainer.getSelectionLayerDimensions();
let screenshotsContainer =
screenshotsChild.overlay.screenshotsContainer;
info(
`old height: ${prevHeight}. new height: ${dimensions.scrollHeight}.\nold width: ${prevWidth}. new width: ${dimensions.scrollWidth}`
`old height: ${prevHeight}. new height: ${screenshotsContainer.scrollHeight}.\nold width: ${prevWidth}. new width: ${screenshotsContainer.scrollWidth}`
);
return (
dimensions.scrollHeight !== prevHeight &&
dimensions.scrollWidth !== prevWidth
screenshotsContainer.scrollHeight !== prevHeight &&
screenshotsContainer.scrollWidth !== prevWidth
);
}, "Wait for selection box width change");
}
);
}
getSelectionBoxDimensions() {
getSelectionRegionDimensions() {
return ContentTask.spawn(this.browser, null, async () => {
let screenshotsChild = content.windowGlobalChild.getActor(
"ScreenshotsComponent"
);
Assert.ok(screenshotsChild._overlay._initialized, "The overlay exists");
Assert.ok(screenshotsChild.overlay.initialized, "The overlay exists");
return screenshotsChild._overlay.screenshotsContainer.getSelectionLayerBoxDimensions();
return screenshotsChild.overlay.selectionRegion.dimensions;
});
}
/**
* Clicks an element on the screen
* @param eleSel The selector for the element to click
*/
async clickUIElement(eleSel) {
await SpecialPowers.spawn(
this.browser,
[eleSel],
async function (eleSelector) {
info(
`in clickScreenshotsUIElement content function, eleSelector: ${eleSelector}`
);
const EventUtils = ContentTaskUtils.getEventUtils(content);
let ele = content.document.querySelector(eleSelector);
info(`Found the thing to click: ${eleSelector}: ${!!ele}`);
EventUtils.synthesizeMouseAtCenter(ele, {});
// wait a frame for the screenshots UI to finish any init
await new content.Promise(res => content.requestAnimationFrame(res));
}
);
}
/**
* Copied from screenshots extension
* A helper that returns the size of the image that was just put into the clipboard by the

View File

@@ -259,7 +259,7 @@ async function isScreenshotInitialized() {
let screenshotsChild = content.windowGlobalChild.getActor(
"ScreenshotsComponent"
);
return screenshotsChild?._overlay?._initialized;
return screenshotsChild?.overlay?.initialized;
});
}