browser_jsterm_screenshot_command_fixed_header.js (2248B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Test that fullpage screenshot command works properly with fixed elements 5 6 "use strict"; 7 8 const TEST_URI = 9 "http://example.com/browser/devtools/client/webconsole/test/browser/test_jsterm_screenshot_command.html"; 10 11 // on some machines, such as macOS, dpr is set to 2. This is expected behavior, however 12 // to keep tests consistant across OSs we are setting the dpr to 1 13 const dpr = "--dpr 1"; 14 15 add_task(async function () { 16 const hud = await openNewTabAndConsole(TEST_URI); 17 18 info("Scroll in the content page"); 19 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async () => { 20 // Overflow the page 21 content.document.body.classList.add("overflow"); 22 content.wrappedJSObject.scrollTo(200, 350); 23 }); 24 25 info("Execute :screenshot --fullpage"); 26 const file = new FileUtils.File( 27 PathUtils.join(PathUtils.tempDir, "TestScreenshotFile.png") 28 ); 29 const command = `:screenshot ${file.path} ${dpr} --fullpage`; 30 // `-fullpage` is appended at the end of the provided filename 31 const actualFilePath = file.path.replace(".png", "-fullpage.png"); 32 await executeAndWaitForMessageByType( 33 hud, 34 command, 35 `Saved to ${file.path.replace(".png", "-fullpage.png")}`, 36 ".console-api" 37 ); 38 39 info("Create an image using the downloaded file as source"); 40 const image = new Image(); 41 image.src = PathUtils.toFileURI(actualFilePath); 42 await once(image, "load"); 43 44 info("Check that the fixed element is rendered at the expected position"); 45 checkImageColorAt({ 46 image, 47 x: 0, 48 y: 0, 49 expectedColor: `rgb(255, 0, 0)`, 50 label: 51 "The top-left corner has the expected red color, matching the header element", 52 }); 53 54 const scrollPosition = await SpecialPowers.spawn( 55 gBrowser.selectedBrowser, 56 [], 57 async () => { 58 return [content.wrappedJSObject.scrollX, content.wrappedJSObject.scrollY]; 59 } 60 ); 61 is( 62 scrollPosition.join("|"), 63 "200|350", 64 "The page still has the same scroll positions as before taking the screenshot" 65 ); 66 67 info("Remove the downloaded screenshot file and cleanup downloads"); 68 await IOUtils.remove(actualFilePath); 69 await resetDownloads(); 70 });