browser/devtools/framework/test/browser_toolbox_window_shortcuts.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/framework/test/browser_toolbox_window_shortcuts.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,92 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +let Toolbox = devtools.Toolbox;
     1.8 +
     1.9 +let toolbox, toolIDs, idIndex, modifiedPrefs = [];
    1.10 +
    1.11 +function test() {
    1.12 +  waitForExplicitFinish();
    1.13 +
    1.14 +  if (window.navigator.userAgent.indexOf("Mac OS X 10.8") != -1 ||
    1.15 +      window.navigator.userAgent.indexOf("Windows NT 5.1") != -1) {
    1.16 +    info("Skipping Mac OSX 10.8 and Windows xp, see bug 838069");
    1.17 +    finish();
    1.18 +    return;
    1.19 +  }
    1.20 +  addTab("about:blank", function() {
    1.21 +    toolIDs = [];
    1.22 +    for (let [id, definition] of gDevTools._tools) {
    1.23 +      if (definition.key) {
    1.24 +        toolIDs.push(id);
    1.25 +
    1.26 +        // Enable disabled tools
    1.27 +        let pref = definition.visibilityswitch, prefValue;
    1.28 +        try {
    1.29 +          prefValue = Services.prefs.getBoolPref(pref);
    1.30 +        } catch (e) {
    1.31 +          continue;
    1.32 +        }
    1.33 +        if (!prefValue) {
    1.34 +          modifiedPrefs.push(pref);
    1.35 +          Services.prefs.setBoolPref(pref, true);
    1.36 +        }
    1.37 +      }
    1.38 +    }
    1.39 +    let target = TargetFactory.forTab(gBrowser.selectedTab);
    1.40 +    idIndex = 0;
    1.41 +    gDevTools.showToolbox(target, toolIDs[0], Toolbox.HostType.WINDOW)
    1.42 +             .then(testShortcuts);
    1.43 +  });
    1.44 +}
    1.45 +
    1.46 +function testShortcuts(aToolbox, aIndex) {
    1.47 +  if (aIndex == toolIDs.length) {
    1.48 +    tidyUp();
    1.49 +    return;
    1.50 +  }
    1.51 +
    1.52 +  toolbox = aToolbox;
    1.53 +  info("Toolbox fired a `ready` event");
    1.54 +
    1.55 +  toolbox.once("select", selectCB);
    1.56 +
    1.57 +  if (aIndex != null) {
    1.58 +    // This if block is to allow the call of selectCB without shortcut press for
    1.59 +    // the first time. That happens because on opening of toolbox, one tool gets
    1.60 +    // selected atleast.
    1.61 +
    1.62 +    let key = gDevTools._tools.get(toolIDs[aIndex]).key;
    1.63 +    let toolModifiers = gDevTools._tools.get(toolIDs[aIndex]).modifiers;
    1.64 +    let modifiers = {
    1.65 +      accelKey: toolModifiers.contains("accel"),
    1.66 +      altKey: toolModifiers.contains("alt"),
    1.67 +      shiftKey: toolModifiers.contains("shift"),
    1.68 +    };
    1.69 +    idIndex = aIndex;
    1.70 +    info("Testing shortcut for tool " + aIndex + ":" + toolIDs[aIndex] +
    1.71 +         " using key " + key);
    1.72 +    EventUtils.synthesizeKey(key, modifiers, toolbox.doc.defaultView.parent);
    1.73 +  }
    1.74 +}
    1.75 +
    1.76 +function selectCB(event, id) {
    1.77 +  info("toolbox-select event from " + id);
    1.78 +
    1.79 +  is(toolIDs.indexOf(id), idIndex,
    1.80 +     "Correct tool is selected on pressing the shortcut for " + id);
    1.81 +
    1.82 +  testShortcuts(toolbox, idIndex + 1);
    1.83 +}
    1.84 +
    1.85 +function tidyUp() {
    1.86 +  toolbox.destroy().then(function() {
    1.87 +    gBrowser.removeCurrentTab();
    1.88 +
    1.89 +    for (let pref of modifiedPrefs) {
    1.90 +      Services.prefs.clearUserPref(pref);
    1.91 +    }
    1.92 +    toolbox = toolIDs = idIndex = modifiedPrefs = Toolbox = null;
    1.93 +    finish();
    1.94 +  });
    1.95 +}

mercurial