diff options
Diffstat (limited to 'browser/components/screenshots/tests')
9 files changed, 414 insertions, 47 deletions
diff --git a/browser/components/screenshots/tests/browser/browser.toml b/browser/components/screenshots/tests/browser/browser.toml index b27d28c677..97e7474fa3 100644 --- a/browser/components/screenshots/tests/browser/browser.toml +++ b/browser/components/screenshots/tests/browser/browser.toml @@ -18,6 +18,8 @@ prefs = [ ["browser_iframe_test.js"] skip-if = ["os == 'linux'"] +["browser_keyboard_shortcuts.js"] + ["browser_overlay_keyboard_test.js"] ["browser_screenshots_drag_scroll_test.js"] @@ -63,3 +65,5 @@ skip-if = ["!crashreporter"] ["browser_test_moving_tab_to_new_window.js"] ["browser_test_resize.js"] + +["browser_test_selection_size_text.js"] diff --git a/browser/components/screenshots/tests/browser/browser_iframe_test.js b/browser/components/screenshots/tests/browser/browser_iframe_test.js index bb853fbe28..24f7a71dca 100644 --- a/browser/components/screenshots/tests/browser/browser_iframe_test.js +++ b/browser/components/screenshots/tests/browser/browser_iframe_test.js @@ -90,7 +90,7 @@ add_task(async function test_selectingElementsInIframes() { await helper.waitForHoverElementRect(el.width, el.height); mouse.click(x, y); - await helper.waitForStateChange("selected"); + await helper.waitForStateChange(["selected"]); let dimensions = await helper.getSelectionRegionDimensions(); @@ -116,7 +116,7 @@ add_task(async function test_selectingElementsInIframes() { ); mouse.click(500, 500); - await helper.waitForStateChange("crosshairs"); + await helper.waitForStateChange(["crosshairs"]); } } ); diff --git a/browser/components/screenshots/tests/browser/browser_keyboard_shortcuts.js b/browser/components/screenshots/tests/browser/browser_keyboard_shortcuts.js new file mode 100644 index 0000000000..bca96f333f --- /dev/null +++ b/browser/components/screenshots/tests/browser/browser_keyboard_shortcuts.js @@ -0,0 +1,128 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_download_shortcut() { + await SpecialPowers.pushPrefEnv({ + set: [["browser.download.useDownloadDir", true]], + }); + + let publicDownloads = await Downloads.getList(Downloads.PUBLIC); + // First ensure we catch the download finishing. + let downloadFinishedPromise = new Promise(resolve => { + publicDownloads.addView({ + onDownloadChanged(download) { + info("Download changed!"); + if (download.succeeded || download.error) { + info("Download succeeded or errored"); + publicDownloads.removeView(this); + resolve(download); + } + }, + }); + }); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: TEST_PAGE, + }, + async browser => { + let helper = new ScreenshotsHelper(browser); + + helper.triggerUIFromToolbar(); + await helper.waitForOverlay(); + await helper.dragOverlay(10, 10, 500, 500); + + let screenshotExit = TestUtils.topicObserved("screenshots-exit"); + + await SpecialPowers.spawn(browser, [], async () => { + EventUtils.synthesizeKey("s", { accelKey: true }, content); + }); + + info("wait for download to finish"); + let download = await downloadFinishedPromise; + + ok(download.succeeded, "Download should succeed"); + + await publicDownloads.removeFinished(); + await screenshotExit; + + helper.triggerUIFromToolbar(); + await helper.waitForOverlay(); + + let screenshotReady = TestUtils.topicObserved( + "screenshots-preview-ready" + ); + + let visibleButton = await helper.getPanelButton(".visible-page"); + visibleButton.click(); + + await screenshotReady; + + screenshotExit = TestUtils.topicObserved("screenshots-exit"); + + EventUtils.synthesizeKey("s", { accelKey: true }); + + info("wait for download to finish"); + download = await downloadFinishedPromise; + + ok(download.succeeded, "Download should succeed"); + + await publicDownloads.removeFinished(); + await screenshotExit; + } + ); +}); + +add_task(async function test_copy_shortcut() { + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: TEST_PAGE, + }, + async browser => { + let helper = new ScreenshotsHelper(browser); + let contentInfo = await helper.getContentDimensions(); + ok(contentInfo, "Got dimensions back from the content"); + + helper.triggerUIFromToolbar(); + await helper.waitForOverlay(); + await helper.dragOverlay(10, 10, 500, 500); + + let screenshotExit = TestUtils.topicObserved("screenshots-exit"); + let clipboardChanged = helper.waitForRawClipboardChange(490, 490); + + await SpecialPowers.spawn(browser, [], async () => { + EventUtils.synthesizeKey("c", { accelKey: true }, content); + }); + + await clipboardChanged; + await screenshotExit; + + helper.triggerUIFromToolbar(); + await helper.waitForOverlay(); + + let screenshotReady = TestUtils.topicObserved( + "screenshots-preview-ready" + ); + + let visibleButton = await helper.getPanelButton(".visible-page"); + visibleButton.click(); + + await screenshotReady; + + clipboardChanged = helper.waitForRawClipboardChange( + contentInfo.clientWidth, + contentInfo.clientHeight + ); + screenshotExit = TestUtils.topicObserved("screenshots-exit"); + + EventUtils.synthesizeKey("c", { accelKey: true }); + + await clipboardChanged; + await screenshotExit; + } + ); +}); 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 757d721268..86940a5203 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 @@ -353,8 +353,6 @@ add_task(async function test_scrollIfByEdge() { await helper.scrollContentWindow(windowX, windowY); - await TestUtils.waitForTick(); - helper.triggerUIFromToolbar(); await helper.waitForOverlay(); @@ -363,17 +361,18 @@ add_task(async function test_scrollIfByEdge() { is(scrollX, windowX, "Window x position is 1000"); is(scrollY, windowY, "Window y position is 1000"); - let startX = 1100; - let startY = 1100; + let startX = 1200; + let startY = 1200; let endX = 1010; let endY = 1010; - // The window won't scroll if the state is draggingReady so we move to - // get into the dragging state and then move again to scroll the window - mouse.down(startX, startY); - await helper.assertStateChange("draggingReady"); - mouse.move(1050, 1050); - await helper.assertStateChange("dragging"); + await helper.dragOverlay(startX, startY, endX + 20, endY + 20); + await helper.scrollContentWindow(windowX, windowY); + + await TestUtils.waitForTick(); + + mouse.down(endX + 20, endY + 20); + await helper.assertStateChange("resizing"); mouse.move(endX, endY); mouse.up(endX, endY); await helper.assertStateChange("selected"); @@ -387,26 +386,64 @@ add_task(async function test_scrollIfByEdge() { is(scrollX, windowX, "Window x position is 990"); is(scrollY, windowY, "Window y position is 990"); + let screenshotExit = TestUtils.topicObserved("screenshots-exit"); + helper.triggerUIFromToolbar(); + await screenshotExit; + } + ); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: TEST_PAGE, + }, + async browser => { + let helper = new ScreenshotsHelper(browser); + + let windowX = 1000; + let windowY = 1000; + + await helper.scrollContentWindow(windowX, windowY); + + helper.triggerUIFromToolbar(); + await helper.waitForOverlay(); + let contentInfo = await helper.getContentDimensions(); + let { scrollX, scrollY, clientWidth, clientHeight } = contentInfo; + + let startX = windowX + clientWidth - 200; + let startY = windowX + clientHeight - 200; + let endX = windowX + clientWidth - 10; + let endY = windowY + clientHeight - 10; - endX = windowX + contentInfo.clientWidth - 10; - endY = windowY + contentInfo.clientHeight - 10; + await helper.dragOverlay(startX, startY, endX - 20, endY - 20); + await helper.scrollContentWindow(windowX, windowY); + + await TestUtils.waitForTick(); info( `starting to drag overlay to ${endX}, ${endY} in test\nclientInfo: ${JSON.stringify( contentInfo )}\n` ); - await helper.dragOverlay(startX, startY, endX, endY, "selected"); + mouse.down(endX - 20, endY - 20); + await helper.assertStateChange("resizing"); + mouse.move(endX, endY); + mouse.up(endX, endY); + await helper.assertStateChange("selected"); - windowX = 1000; - windowY = 1000; + windowX = 1010; + windowY = 1010; await helper.waitForScrollTo(windowX, windowY); ({ scrollX, scrollY } = await helper.getContentDimensions()); - is(scrollX, windowX, "Window x position is 1000"); - is(scrollY, windowY, "Window y position is 1000"); + is(scrollX, windowX, "Window x position is 1010"); + is(scrollY, windowY, "Window y position is 1010"); + + let screenshotExit = TestUtils.topicObserved("screenshots-exit"); + helper.triggerUIFromToolbar(); + await screenshotExit; } ); }); @@ -428,13 +465,19 @@ add_task(async function test_scrollIfByEdgeWithKeyboard() { helper.triggerUIFromToolbar(); await helper.waitForOverlay(); - let { scrollX, scrollY, clientWidth, clientHeight } = - await helper.getContentDimensions(); + let { scrollX, scrollY } = await helper.getContentDimensions(); is(scrollX, windowX, "Window x position is 1000"); is(scrollY, windowY, "Window y position is 1000"); - await helper.dragOverlay(1020, 1020, 1120, 1120); + await helper.dragOverlay( + scrollX + 20, + scrollY + 20, + scrollX + 120, + scrollY + 120 + ); + + await helper.scrollContentWindow(windowX, windowY); await helper.moveOverlayViaKeyboard("highlight", [ { key: "ArrowLeft", options: { shiftKey: true } }, @@ -447,14 +490,36 @@ add_task(async function test_scrollIfByEdgeWithKeyboard() { windowY = 989; await helper.waitForScrollTo(windowX, windowY); - ({ scrollX, scrollY, clientWidth, clientHeight } = - await helper.getContentDimensions()); + ({ scrollX, scrollY } = await helper.getContentDimensions()); is(scrollX, windowX, "Window x position is 989"); is(scrollY, windowY, "Window y position is 989"); - mouse.click(1200, 1200); - await helper.assertStateChange("crosshairs"); + let screenshotExit = TestUtils.topicObserved("screenshots-exit"); + helper.triggerUIFromToolbar(); + await screenshotExit; + } + ); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: TEST_PAGE, + }, + async browser => { + let helper = new ScreenshotsHelper(browser); + + let windowX = 989; + let windowY = 989; + + await helper.scrollContentWindow(windowX, windowY); + + helper.triggerUIFromToolbar(); + await helper.waitForOverlay(); + + let { scrollX, scrollY, clientWidth, clientHeight } = + await helper.getContentDimensions(); + await helper.dragOverlay( scrollX + clientWidth - 100 - 20, scrollY + clientHeight - 100 - 20, @@ -477,6 +542,10 @@ add_task(async function test_scrollIfByEdgeWithKeyboard() { is(scrollX, windowX, "Window x position is 1000"); is(scrollY, windowY, "Window y position is 1000"); + + let screenshotExit = TestUtils.topicObserved("screenshots-exit"); + helper.triggerUIFromToolbar(); + await screenshotExit; } ); }); diff --git a/browser/components/screenshots/tests/browser/browser_screenshots_drag_test.js b/browser/components/screenshots/tests/browser/browser_screenshots_drag_test.js index 605e0ae75c..3cef2dbd72 100644 --- a/browser/components/screenshots/tests/browser/browser_screenshots_drag_test.js +++ b/browser/components/screenshots/tests/browser/browser_screenshots_drag_test.js @@ -442,7 +442,7 @@ add_task(async function resizeAllCorners() { /** * This function tests clicking the overlay with the different mouse buttons */ -add_task(async function test_otherMouseButtons() { +add_task(async function test_clickingOtherMouseButtons() { await BrowserTestUtils.withNewTab( { gBrowser, @@ -478,6 +478,7 @@ add_task(async function test_otherMouseButtons() { mouse.down(10, 10, { button: 2 }); mouse.move(100, 100, { button: 2 }); + mouse.up(100, 100, { button: 2 }); await TestUtils.waitForTick(); @@ -486,3 +487,66 @@ add_task(async function test_otherMouseButtons() { } ); }); + +/** + * This function tests dragging the overlay with the different mouse buttons + */ +add_task(async function test_draggingOtherMouseButtons() { + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: TEST_PAGE, + }, + async browser => { + let helper = new ScreenshotsHelper(browser); + helper.triggerUIFromToolbar(); + await helper.waitForOverlay(); + + // Click with button 1 in dragging state + mouse.down(100, 100); + await helper.assertStateChange("draggingReady"); + mouse.move(200, 200); + await helper.assertStateChange("dragging"); + mouse.click(200, 200, { button: 1 }); + await helper.assertStateChange("selected"); + + // Reset + mouse.click(10, 10); + await helper.assertStateChange("crosshairs"); + + // Mouse down with button 2 in draggingReady state + mouse.down(100, 100); + await helper.assertStateChange("draggingReady"); + mouse.down(200, 200, { button: 2 }); + await helper.assertStateChange("crosshairs"); + + await helper.dragOverlay(100, 100, 200, 200); + + // Click with button 1 in resizing state + mouse.down(200, 200); + await helper.assertStateChange("resizing"); + mouse.click(200, 200, { button: 1 }); + + // Reset + mouse.click(10, 10); + await helper.assertStateChange("crosshairs"); + + await helper.dragOverlay(100, 100, 200, 200); + + // Mouse down with button 2 in dragging state + mouse.down(200, 200); + await helper.assertStateChange("resizing"); + mouse.down(200, 200, { button: 2 }); + + // Reset + mouse.click(10, 10); + await helper.assertStateChange("crosshairs"); + + // Mouse move with button 2 in draggingReady state + mouse.down(100, 100); + await helper.assertStateChange("draggingReady"); + mouse.move(100, 100, { button: 2 }); + await helper.assertStateChange("crosshairs"); + } + ); +}); 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 ad262a7e67..021a37b5c9 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 @@ -31,7 +31,7 @@ add_task(async function test_toggling_screenshots_pref() { .callsFake(observerSpy); let notifierStub = sinon .stub(ScreenshotsUtils, "notify") - .callsFake(function (window, type) { + .callsFake(function () { notifierSpy(); ScreenshotsUtils.notify.wrappedMethod.apply(this, arguments); }); diff --git a/browser/components/screenshots/tests/browser/browser_test_element_picker.js b/browser/components/screenshots/tests/browser/browser_test_element_picker.js index 17ed2a0190..3e2069134e 100644 --- a/browser/components/screenshots/tests/browser/browser_test_element_picker.js +++ b/browser/components/screenshots/tests/browser/browser_test_element_picker.js @@ -43,14 +43,14 @@ add_task(async function test_element_picker() { ); mouse.click(10, 10); - await helper.waitForStateChange("crosshairs"); + await helper.waitForStateChange(["crosshairs"]); let hoverElementRegionValid = await helper.isHoverElementRegionValid(); ok(!hoverElementRegionValid, "Hover element rect is null"); mouse.click(10, 10); - await helper.waitForStateChange("crosshairs"); + await helper.waitForStateChange(["crosshairs"]); } ); }); diff --git a/browser/components/screenshots/tests/browser/browser_test_selection_size_text.js b/browser/components/screenshots/tests/browser/browser_test_selection_size_text.js new file mode 100644 index 0000000000..38d1acbea9 --- /dev/null +++ b/browser/components/screenshots/tests/browser/browser_test_selection_size_text.js @@ -0,0 +1,86 @@ +/* Any copyright is dedicated to the Public Domain. + https://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_selectionSizeTest() { + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: TEST_PAGE, + }, + async browser => { + const dpr = browser.ownerGlobal.devicePixelRatio; + let helper = new ScreenshotsHelper(browser); + + helper.triggerUIFromToolbar(); + + await helper.waitForOverlay(); + await helper.dragOverlay(100, 100, 500, 500); + + let actualText = await helper.getOverlaySelectionSizeText(); + + Assert.equal( + actualText, + `${400 * dpr} x ${400 * dpr}`, + "The selection size text is the same" + ); + } + ); +}); + +add_task(async function test_selectionSizeTestAt1Point5Zoom() { + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: TEST_PAGE, + }, + async browser => { + const zoom = 1.5; + const dpr = browser.ownerGlobal.devicePixelRatio; + let helper = new ScreenshotsHelper(browser); + helper.zoomBrowser(zoom); + + helper.triggerUIFromToolbar(); + + await helper.waitForOverlay(); + await helper.dragOverlay(100, 100, 500, 500); + + let actualText = await helper.getOverlaySelectionSizeText(); + + Assert.equal( + actualText, + `${400 * dpr * zoom} x ${400 * dpr * zoom}`, + "The selection size text is the same" + ); + } + ); +}); + +add_task(async function test_selectionSizeTestAtPoint5Zoom() { + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: TEST_PAGE, + }, + async browser => { + const zoom = 0.5; + const dpr = browser.ownerGlobal.devicePixelRatio; + let helper = new ScreenshotsHelper(browser); + helper.zoomBrowser(zoom); + + helper.triggerUIFromToolbar(); + + await helper.waitForOverlay(); + await helper.dragOverlay(100, 100, 500, 500); + + let actualText = await helper.getOverlaySelectionSizeText(); + + Assert.equal( + actualText, + `${400 * dpr * zoom} x ${400 * dpr * zoom}`, + "The selection size text is the same" + ); + } + ); +}); diff --git a/browser/components/screenshots/tests/browser/head.js b/browser/components/screenshots/tests/browser/head.js index a36e955830..762da5f866 100644 --- a/browser/components/screenshots/tests/browser/head.js +++ b/browser/components/screenshots/tests/browser/head.js @@ -159,23 +159,23 @@ class ScreenshotsHelper { }); } - waitForStateChange(newState) { - return SpecialPowers.spawn(this.browser, [newState], async state => { + waitForStateChange(newStateArr) { + return SpecialPowers.spawn(this.browser, [newStateArr], async stateArr => { let screenshotsChild = content.windowGlobalChild.getActor( "ScreenshotsComponent" ); await ContentTaskUtils.waitForCondition(() => { - info(`got ${screenshotsChild.overlay.state}. expected ${state}`); - return screenshotsChild.overlay.state === state; - }, `Wait for overlay state to be ${state}`); + info(`got ${screenshotsChild.overlay.state}. expected ${stateArr}`); + return stateArr.includes(screenshotsChild.overlay.state); + }, `Wait for overlay state to be ${stateArr}`); return screenshotsChild.overlay.state; }); } async assertStateChange(newState) { - let currentState = await this.waitForStateChange(newState); + let currentState = await this.waitForStateChange([newState]); is( currentState, @@ -269,18 +269,13 @@ class ScreenshotsHelper { mouse.down(startX, startY); - await Promise.any([ - this.waitForStateChange("draggingReady"), - this.waitForStateChange("resizing"), - ]); + await this.waitForStateChange(["draggingReady", "resizing"]); Assert.ok(true, "The overlay is in the draggingReady or resizing state"); mouse.move(endX, endY); - await Promise.any([ - this.waitForStateChange("dragging"), - this.waitForStateChange("resizing"), - ]); + await this.waitForStateChange(["dragging", "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 @@ -324,7 +319,6 @@ class ScreenshotsHelper { overlay.topRightMover.focus({ focusVisible: true }); break; } - screenshotsChild.overlay.highlightEl.focus(); for (let event of eventsArr) { EventUtils.synthesizeKey( @@ -354,7 +348,6 @@ class ScreenshotsHelper { } async scrollContentWindow(x, y) { - let promise = BrowserTestUtils.waitForContentEvent(this.browser, "scroll"); let contentDims = await this.getContentDimensions(); await ContentTask.spawn( this.browser, @@ -404,7 +397,6 @@ class ScreenshotsHelper { }, `Waiting for window to scroll to ${xPos}, ${yPos}`); } ); - await promise; } async waitForScrollTo(x, y) { @@ -521,6 +513,15 @@ class ScreenshotsHelper { }); } + getOverlaySelectionSizeText(elementId = "testPageElement") { + return ContentTask.spawn(this.browser, [elementId], async () => { + let screenshotsChild = content.windowGlobalChild.getActor( + "ScreenshotsComponent" + ); + return screenshotsChild.overlay.selectionSize.textContent; + }); + } + async clickTestPageElement(elementId = "testPageElement") { let rect = await this.getTestPageElementRect(elementId); let dims = await this.getContentDimensions(); @@ -909,6 +910,21 @@ add_setup(async () => { ); let screenshotBtn = document.getElementById("screenshot-button"); Assert.ok(screenshotBtn, "The screenshots button was added to the nav bar"); + + registerCleanupFunction(async () => { + info(`downloads panel should be visible: ${DownloadsPanel.isPanelShowing}`); + if (DownloadsPanel.isPanelShowing) { + let hiddenPromise = BrowserTestUtils.waitForEvent( + DownloadsPanel.panel, + "popuphidden" + ); + DownloadsPanel.hidePanel(); + await hiddenPromise; + info( + `downloads panel should not be visible: ${DownloadsPanel.isPanelShowing}` + ); + } + }); }); function getContentDevicePixelRatio(browser) { |