1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/framework/test/browser_toolbox_zoom.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +let modifiers = { 1.8 + accelKey: true 1.9 +}; 1.10 + 1.11 +let toolbox; 1.12 + 1.13 +function test() { 1.14 + waitForExplicitFinish(); 1.15 + 1.16 + addTab("about:blank", function() { 1.17 + openToolbox(); 1.18 + }); 1.19 +} 1.20 + 1.21 +function openToolbox() { 1.22 + let target = TargetFactory.forTab(gBrowser.selectedTab); 1.23 + 1.24 + gDevTools.showToolbox(target).then((aToolbox) => { 1.25 + toolbox = aToolbox; 1.26 + toolbox.selectTool("styleeditor").then(testZoom); 1.27 + }); 1.28 +} 1.29 + 1.30 +function testZoom() { 1.31 + info("testing zoom keys"); 1.32 + 1.33 + testZoomLevel("in", 2, 1.2); 1.34 + testZoomLevel("out", 3, 0.9); 1.35 + testZoomLevel("reset", 1, 1); 1.36 + 1.37 + tidyUp(); 1.38 +} 1.39 + 1.40 +function testZoomLevel(type, times, expected) { 1.41 + sendZoomKey("toolbox-zoom-"+ type + "-key", times); 1.42 + 1.43 + let zoom = getCurrentZoom(toolbox); 1.44 + is(zoom.toFixed(2), expected, "zoom level correct after zoom " + type); 1.45 + 1.46 + is(toolbox.zoomValue.toFixed(2), expected, 1.47 + "saved zoom level is correct after zoom " + type); 1.48 +} 1.49 + 1.50 +function sendZoomKey(id, times) { 1.51 + let key = toolbox.doc.getElementById(id).getAttribute("key"); 1.52 + for (let i = 0; i < times; i++) { 1.53 + EventUtils.synthesizeKey(key, modifiers, toolbox.doc.defaultView); 1.54 + } 1.55 +} 1.56 + 1.57 +function getCurrentZoom() { 1.58 + var contViewer = toolbox.frame.docShell.contentViewer; 1.59 + var docViewer = contViewer.QueryInterface(Ci.nsIMarkupDocumentViewer); 1.60 + return docViewer.fullZoom; 1.61 +} 1.62 + 1.63 +function tidyUp() { 1.64 + toolbox.destroy().then(function() { 1.65 + gBrowser.removeCurrentTab(); 1.66 + 1.67 + toolbox = modifiers = null; 1.68 + finish(); 1.69 + }); 1.70 +}