browser_save_image.js (1272B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const MockFilePicker = SpecialPowers.MockFilePicker; 7 8 add_setup(async function () { 9 await SpecialPowers.pushPrefEnv({ 10 set: [["test.wait300msAfterTabSwitch", true]], 11 }); 12 13 MockFilePicker.init(window.browsingContext); 14 15 registerCleanupFunction(async () => { 16 MockFilePicker.cleanup(); 17 }); 18 }); 19 20 add_task(async function test_save_image_canvas() { 21 await BrowserTestUtils.withNewTab( 22 "data:text/html;charset=utf-8,<canvas></canvas>", 23 async browser => { 24 let menu = document.getElementById("contentAreaContextMenu"); 25 let popupShown = BrowserTestUtils.waitForEvent(menu, "popupshown"); 26 let filePicker = waitForFilePicker(); 27 28 BrowserTestUtils.synthesizeMouseAtCenter( 29 "canvas", 30 { type: "contextmenu", button: 2 }, 31 browser 32 ); 33 await popupShown; 34 35 menu.activateItem(menu.querySelector("#context-saveimage")); 36 37 await filePicker; 38 } 39 ); 40 }); 41 42 function waitForFilePicker() { 43 return new Promise(resolve => { 44 MockFilePicker.showCallback = () => { 45 MockFilePicker.showCallback = null; 46 ok(true, "Saw the file picker"); 47 48 resolve(); 49 }; 50 }); 51 }