browser/devtools/framework/test/browser_toolbox_zoom.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 let modifiers = {
michael@0 5 accelKey: true
michael@0 6 };
michael@0 7
michael@0 8 let toolbox;
michael@0 9
michael@0 10 function test() {
michael@0 11 waitForExplicitFinish();
michael@0 12
michael@0 13 addTab("about:blank", function() {
michael@0 14 openToolbox();
michael@0 15 });
michael@0 16 }
michael@0 17
michael@0 18 function openToolbox() {
michael@0 19 let target = TargetFactory.forTab(gBrowser.selectedTab);
michael@0 20
michael@0 21 gDevTools.showToolbox(target).then((aToolbox) => {
michael@0 22 toolbox = aToolbox;
michael@0 23 toolbox.selectTool("styleeditor").then(testZoom);
michael@0 24 });
michael@0 25 }
michael@0 26
michael@0 27 function testZoom() {
michael@0 28 info("testing zoom keys");
michael@0 29
michael@0 30 testZoomLevel("in", 2, 1.2);
michael@0 31 testZoomLevel("out", 3, 0.9);
michael@0 32 testZoomLevel("reset", 1, 1);
michael@0 33
michael@0 34 tidyUp();
michael@0 35 }
michael@0 36
michael@0 37 function testZoomLevel(type, times, expected) {
michael@0 38 sendZoomKey("toolbox-zoom-"+ type + "-key", times);
michael@0 39
michael@0 40 let zoom = getCurrentZoom(toolbox);
michael@0 41 is(zoom.toFixed(2), expected, "zoom level correct after zoom " + type);
michael@0 42
michael@0 43 is(toolbox.zoomValue.toFixed(2), expected,
michael@0 44 "saved zoom level is correct after zoom " + type);
michael@0 45 }
michael@0 46
michael@0 47 function sendZoomKey(id, times) {
michael@0 48 let key = toolbox.doc.getElementById(id).getAttribute("key");
michael@0 49 for (let i = 0; i < times; i++) {
michael@0 50 EventUtils.synthesizeKey(key, modifiers, toolbox.doc.defaultView);
michael@0 51 }
michael@0 52 }
michael@0 53
michael@0 54 function getCurrentZoom() {
michael@0 55 var contViewer = toolbox.frame.docShell.contentViewer;
michael@0 56 var docViewer = contViewer.QueryInterface(Ci.nsIMarkupDocumentViewer);
michael@0 57 return docViewer.fullZoom;
michael@0 58 }
michael@0 59
michael@0 60 function tidyUp() {
michael@0 61 toolbox.destroy().then(function() {
michael@0 62 gBrowser.removeCurrentTab();
michael@0 63
michael@0 64 toolbox = modifiers = null;
michael@0 65 finish();
michael@0 66 });
michael@0 67 }

mercurial