browser_toolbox_zoom.js (1531B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const { Toolbox } = require("resource://devtools/client/framework/toolbox.js"); 7 const L10N = new LocalizationHelper( 8 "devtools/client/locales/toolbox.properties" 9 ); 10 11 add_task(async function () { 12 // This test assume that zoom value will be default value. i.e. x1.0. 13 await pushPref("devtools.toolbox.zoomValue", "1.0"); 14 await addTab("about:blank"); 15 const toolbox = await gDevTools.showToolboxForTab(gBrowser.selectedTab, { 16 toolId: "styleeditor", 17 hostType: Toolbox.HostType.BOTTOM, 18 }); 19 20 info("testing zoom keys"); 21 22 testZoomLevel("In", 2, 1.2, toolbox); 23 testZoomLevel("Out", 3, 0.9, toolbox); 24 testZoomLevel("Reset", 1, 1, toolbox); 25 26 await toolbox.destroy(); 27 gBrowser.removeCurrentTab(); 28 }); 29 30 function testZoomLevel(type, times, expected, toolbox) { 31 sendZoomKey("toolbox.zoom" + type + ".key", times); 32 33 const zoom = getCurrentZoom(toolbox); 34 is( 35 zoom.toFixed(1), 36 expected.toFixed(1), 37 "zoom level correct after zoom " + type 38 ); 39 40 const savedZoom = parseFloat( 41 Services.prefs.getCharPref("devtools.toolbox.zoomValue") 42 ); 43 is( 44 savedZoom.toFixed(1), 45 expected.toFixed(1), 46 "saved zoom level is correct after zoom " + type 47 ); 48 } 49 50 function sendZoomKey(shortcut, times) { 51 for (let i = 0; i < times; i++) { 52 synthesizeKeyShortcut(L10N.getStr(shortcut)); 53 } 54 } 55 56 function getCurrentZoom(toolbox) { 57 return toolbox.win.browsingContext.fullZoom; 58 }