browser_setDesktopBackgroundPreview.js (2864B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 /** 5 * Check whether the preview image for setDesktopBackground is rendered 6 * correctly, without stretching 7 */ 8 9 add_setup(async function () { 10 await SpecialPowers.pushPrefEnv({ 11 set: [["test.wait300msAfterTabSwitch", true]], 12 }); 13 }); 14 15 add_task(async function () { 16 await BrowserTestUtils.withNewTab( 17 { 18 gBrowser, 19 url: "about:logo", 20 }, 21 async () => { 22 const dialogLoad = BrowserTestUtils.domWindowOpened(null, async win => { 23 await BrowserTestUtils.waitForEvent(win, "load"); 24 Assert.equal( 25 win.document.documentElement.getAttribute("windowtype"), 26 "Shell:SetDesktopBackground", 27 "Opened correct window" 28 ); 29 return true; 30 }); 31 32 const image = content.document.images[0]; 33 EventUtils.synthesizeMouseAtCenter(image, { type: "contextmenu" }); 34 35 const menu = document.getElementById("contentAreaContextMenu"); 36 await BrowserTestUtils.waitForPopupEvent(menu, "shown"); 37 const menuClosed = BrowserTestUtils.waitForPopupEvent(menu, "hidden"); 38 39 const menuItem = document.getElementById("context-setDesktopBackground"); 40 try { 41 menu.activateItem(menuItem); 42 } catch (ex) { 43 ok( 44 menuItem.hidden, 45 "should only fail to activate when menu item is hidden" 46 ); 47 ok( 48 !ShellService.canSetDesktopBackground, 49 "Should only hide when not able to set the desktop background" 50 ); 51 is( 52 AppConstants.platform, 53 "linux", 54 "Should always be able to set desktop background on non-linux platforms" 55 ); 56 todo(false, "Skipping test on this configuration"); 57 58 menu.hidePopup(); 59 await menuClosed; 60 return; 61 } 62 63 await menuClosed; 64 65 const win = await dialogLoad; 66 67 /* setDesktopBackground.js does a setTimeout to wait for correct 68 dimensions. If we don't wait here we could read the preview dimensions 69 before they're changed to match the screen */ 70 await TestUtils.waitForTick(); 71 72 const canvas = win.document.getElementById("screen"); 73 const screenRatio = screen.width / screen.height; 74 const previewRatio = canvas.clientWidth / canvas.clientHeight; 75 76 info(`Screen dimensions are ${screen.width}x${screen.height}`); 77 info(`Screen's raw ratio is ${screenRatio}`); 78 info( 79 `Preview dimensions are ${canvas.clientWidth}x${canvas.clientHeight}` 80 ); 81 info(`Preview's raw ratio is ${previewRatio}`); 82 83 Assert.ok( 84 previewRatio < screenRatio + 0.01 && previewRatio > screenRatio - 0.01, 85 "Preview's aspect ratio is within ±.01 of screen's" 86 ); 87 88 win.close(); 89 90 await menuClosed; 91 } 92 ); 93 });