browser_jsterm_screenshot_command_warnings.js (3001B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Test that screenshot command leads to the proper warning and error messages in the 5 // console when necessary. 6 7 "use strict"; 8 9 // The test times out on slow platforms (e.g. linux ccov) 10 requestLongerTimeout(2); 11 12 // We create a very big page here in order to make the :screenshot command fail on 13 // purpose. 14 const TEST_URI = `data:text/html;charset=utf8,<!DOCTYPE html> 15 <style> 16 body { margin:0; } 17 .big { width:20000px; height:20000px; } 18 .small { width:5px; height:5px; } 19 </style> 20 <div class="big"></div> 21 <div class="small"></div>`; 22 23 add_task(async function () { 24 await addTab(TEST_URI); 25 26 const hud = await openConsole(); 27 ok(hud, "web console opened"); 28 29 await testTruncationWarning(hud); 30 await testDPRWarning(hud); 31 }); 32 33 async function testTruncationWarning(hud) { 34 info("Check that large screenshots get cut off if necessary"); 35 36 let onMessages = waitForMessagesByType({ 37 hud, 38 messages: [ 39 { 40 text: "Screenshot copied to clipboard.", 41 typeSelector: ".console-api", 42 }, 43 { 44 text: "The image was cut off to 10000×10000 as the resulting image was too large", 45 typeSelector: ".console-api", 46 }, 47 ], 48 }); 49 // Note, we put the screenshot in the clipboard so we can easily measure the resulting 50 // image. We also pass --dpr 1 so we don't need to worry about different machines having 51 // different screen resolutions. 52 execute(hud, ":screenshot --clipboard --selector .big --dpr 1"); 53 await onMessages; 54 55 let { width, height } = await getImageSizeFromClipboard(); 56 is(width, 10000, "The resulting image is 10000px wide"); 57 is(height, 10000, "The resulting image is 10000px high"); 58 59 onMessages = waitForMessageByType( 60 hud, 61 "Screenshot copied to clipboard.", 62 ".console-api" 63 ); 64 execute(hud, ":screenshot --clipboard --selector .small --dpr 1"); 65 await onMessages; 66 67 ({ width, height } = await getImageSizeFromClipboard()); 68 is(width, 5, "The resulting image is 5px wide"); 69 is(height, 5, "The resulting image is 5px high"); 70 } 71 72 async function testDPRWarning(hud) { 73 info("Check that DPR is reduced to 1 after failure"); 74 75 const onMessages = waitForMessagesByType({ 76 hud, 77 messages: [ 78 { 79 text: "Screenshot copied to clipboard.", 80 typeSelector: ".console-api", 81 }, 82 { 83 text: "The image was cut off to 10000×10000 as the resulting image was too large", 84 typeSelector: ".console-api", 85 }, 86 { 87 text: "The device pixel ratio was reduced to 1 as the resulting image was too large", 88 typeSelector: ".console-api", 89 }, 90 ], 91 }); 92 execute(hud, ":screenshot --clipboard --fullpage --dpr 1000"); 93 await onMessages; 94 95 const { width, height } = await getImageSizeFromClipboard(); 96 is(width, 10000, "The resulting image is 10000px wide"); 97 is(height, 10000, "The resulting image is 10000px high"); 98 }