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.

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

mercurial