browser/devtools/framework/test/browser_toolbox_tabsswitch_shortcuts.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/ */
     4 let Toolbox = devtools.Toolbox;
     6 let toolbox, toolIDs, idIndex, secondTime = false,
     7     reverse = false, nextKey = null, prevKey = null;
     9 function test() {
    10   waitForExplicitFinish();
    12   addTab("about:blank", function() {
    13     let target = TargetFactory.forTab(gBrowser.selectedTab);
    14     idIndex = 0;
    16     target.makeRemote().then(() => {
    17       toolIDs = gDevTools.getToolDefinitionArray()
    18                   .filter(def => def.isTargetSupported(target))
    19                   .map(def => def.id);
    20       gDevTools.showToolbox(target, toolIDs[0], Toolbox.HostType.BOTTOM)
    21                .then(testShortcuts);
    22     });
    23   });
    24 }
    26 function testShortcuts(aToolbox, aIndex) {
    27   if (aIndex == toolIDs.length) {
    28     aIndex = 0;
    29     if (secondTime) {
    30       secondTime = false;
    31       reverse = true;
    32       aIndex = toolIDs.length - 2;
    33     }
    34     else {
    35       secondTime = true;
    36     }
    37   }
    38   else if (aIndex == -1) {
    39     aIndex = toolIDs.length - 1;
    40     if (secondTime) {
    41       tidyUp();
    42       return;
    43     }
    44     secondTime = true;
    45   }
    47   toolbox = aToolbox;
    48   if (!nextKey) {
    49     nextKey = toolbox.doc.getElementById("toolbox-next-tool-key")
    50                      .getAttribute("key");
    51     prevKey = toolbox.doc.getElementById("toolbox-previous-tool-key")
    52                      .getAttribute("key");
    53   }
    54   info("Toolbox fired a `ready` event");
    56   toolbox.once("select", onSelect);
    58   if (aIndex != null) {
    59     // This if block is to allow the call of onSelect without shortcut press for
    60     // the first time. That happens because on opening of toolbox, one tool gets
    61     // selected atleast.
    63     let key = (reverse ? prevKey: nextKey);
    64     let modifiers = {
    65       accelKey: true
    66     };
    67     idIndex = aIndex;
    68     info("Testing shortcut to switch to tool " + aIndex + ":" + toolIDs[aIndex] +
    69          " using key " + key);
    70     EventUtils.synthesizeKey(key, modifiers, toolbox.doc.defaultView);
    71   }
    72 }
    74 function onSelect(event, id) {
    75   info("toolbox-select event from " + id);
    77   is(toolIDs.indexOf(id), idIndex,
    78      "Correct tool is selected on pressing the shortcut for " + id);
    79   // Execute soon to reset the stack trace.
    80   executeSoon(() => {
    81     testShortcuts(toolbox, idIndex + (reverse ? -1: 1));
    82   });
    83 }
    85 function tidyUp() {
    86   toolbox.destroy().then(function() {
    87     gBrowser.removeCurrentTab();
    89     toolbox = toolIDs = idIndex = Toolbox = secondTime = reverse = nextKey =
    90       prevKey = null;
    91     finish();
    92   });
    93 }

mercurial