diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /devtools/client/framework/test/browser_toolbox_screenshot_tool.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/framework/test/browser_toolbox_screenshot_tool.js')
-rw-r--r-- | devtools/client/framework/test/browser_toolbox_screenshot_tool.js | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/devtools/client/framework/test/browser_toolbox_screenshot_tool.js b/devtools/client/framework/test/browser_toolbox_screenshot_tool.js new file mode 100644 index 0000000000..63c8b9fd58 --- /dev/null +++ b/devtools/client/framework/test/browser_toolbox_screenshot_tool.js @@ -0,0 +1,126 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +const exampleOrgDocument = `https://example.org/document-builder.sjs`; +const exampleComDocument = `https://example.com/document-builder.sjs`; + +const TEST_URL = `${exampleOrgDocument}?html= + <style> + body { + margin: 0; + height: 10001px; + } + iframe { + height: 50px; + border:none; + display: block; + } + </style> + <iframe + src="${exampleOrgDocument}?html=<body style='margin:0;height:30px;background:rgb(255,0,0)'></body>" + id="same-origin"></iframe> + <iframe + src="${exampleComDocument}?html=<body style='margin:0;height:30px;background:rgb(0,255,0)'></body>" + id="remote"></iframe>`; + +add_task(async function () { + await pushPref("devtools.command-button-screenshot.enabled", true); + + await addTab(TEST_URL); + + info("Open the toolbox"); + const toolbox = await gDevTools.showToolboxForTab(gBrowser.selectedTab); + + const onScreenshotDownloaded = waitUntilScreenshot(); + toolbox.doc.querySelector("#command-button-screenshot").click(); + const filePath = await onScreenshotDownloaded; + + ok(!!filePath, "The screenshot was taken"); + + info("Create an image using the downloaded file as source"); + const image = new Image(); + const onImageLoad = once(image, "load"); + image.src = PathUtils.toFileURI(filePath); + await onImageLoad; + + const dpr = await SpecialPowers.spawn( + gBrowser.selectedBrowser, + [], + () => content.wrappedJSObject.devicePixelRatio + ); + + info("Check that the same-origin iframe is rendered in the screenshot"); + await checkImageColorAt({ + image, + y: 10 * dpr, + expectedColor: `rgb(255, 0, 0)`, + label: "The same-origin iframe is rendered properly in the screenshot", + }); + + info("Check that the remote iframe is rendered in the screenshot"); + await checkImageColorAt({ + image, + y: 60 * dpr, + expectedColor: `rgb(0, 255, 0)`, + label: "The remote iframe is rendered properly in the screenshot", + }); + + info( + "Check that a warning message was displayed to indicate the screenshot was truncated" + ); + const notificationBox = await waitFor(() => + toolbox.doc.querySelector(".notificationbox") + ); + + const message = notificationBox.querySelector(".notification").textContent; + ok( + message.startsWith("The image was cut off"), + `The warning message is rendered as expected (${message})` + ); + + // Remove the downloaded screenshot file + await IOUtils.remove(filePath); + + info( + "Check that taking a screenshot in a private window doesn't appear in the non-private window" + ); + const privateWindow = await BrowserTestUtils.openNewBrowserWindow({ + private: true, + }); + ok(PrivateBrowsingUtils.isWindowPrivate(privateWindow), "window is private"); + const privateBrowser = privateWindow.gBrowser; + privateBrowser.selectedTab = BrowserTestUtils.addTab( + privateBrowser, + TEST_URL + ); + + info("private tab opened"); + ok( + PrivateBrowsingUtils.isBrowserPrivate(privateBrowser.selectedBrowser), + "tab window is private" + ); + + const privateToolbox = await gDevTools.showToolboxForTab( + privateBrowser.selectedTab + ); + + const onPrivateScreenshotDownloaded = waitUntilScreenshot({ + isWindowPrivate: true, + }); + privateToolbox.doc.querySelector("#command-button-screenshot").click(); + const privateScreenshotFilePath = await onPrivateScreenshotDownloaded; + ok( + !!privateScreenshotFilePath, + "The screenshot was taken in the private window" + ); + + // Remove the downloaded screenshot file + await IOUtils.remove(privateScreenshotFilePath); + + // cleanup the downloads + await resetDownloads(); + + const closePromise = BrowserTestUtils.windowClosed(privateWindow); + privateWindow.BrowserTryToCloseWindow(); + await closePromise; +}); |