browser/devtools/framework/test/browser_toolbox_raise.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_raise.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,90 @@
     1.4 +/* vim: set ts=2 et sw=2 tw=80: */
     1.5 +/* Any copyright is dedicated to the Public Domain.
     1.6 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.7 +
     1.8 +Cu.import("resource://gre/modules/Services.jsm");
     1.9 +let temp = {}
    1.10 +Cu.import("resource:///modules/devtools/gDevTools.jsm", temp);
    1.11 +let DevTools = temp.DevTools;
    1.12 +
    1.13 +Cu.import("resource://gre/modules/devtools/Loader.jsm", temp);
    1.14 +let devtools = temp.devtools;
    1.15 +
    1.16 +let Toolbox = devtools.Toolbox;
    1.17 +
    1.18 +let toolbox, target, tab1, tab2;
    1.19 +
    1.20 +function test() {
    1.21 +  waitForExplicitFinish();
    1.22 +
    1.23 +  gBrowser.selectedTab = tab1 = gBrowser.addTab();
    1.24 +  tab2 = gBrowser.addTab();
    1.25 +  target = TargetFactory.forTab(gBrowser.selectedTab);
    1.26 +
    1.27 +  gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) {
    1.28 +    gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true);
    1.29 +    gDevTools.showToolbox(target)
    1.30 +             .then(testBottomHost, console.error)
    1.31 +             .then(null, console.error);
    1.32 +  }, true);
    1.33 +
    1.34 +  content.location = "data:text/html,test for opening toolbox in different hosts";
    1.35 +}
    1.36 +
    1.37 +function testBottomHost(aToolbox) {
    1.38 +  toolbox = aToolbox;
    1.39 +
    1.40 +  // switch to another tab and test toolbox.raise()
    1.41 +  gBrowser.selectedTab = tab2;
    1.42 +  executeSoon(function() {
    1.43 +    is(gBrowser.selectedTab, tab2, "Correct tab is selected before calling raise");
    1.44 +    toolbox.raise();
    1.45 +    executeSoon(function() {
    1.46 +      is(gBrowser.selectedTab, tab1, "Correct tab was selected after calling raise");
    1.47 +
    1.48 +      toolbox.switchHost(Toolbox.HostType.WINDOW).then(testWindowHost).then(null, console.error);
    1.49 +    });
    1.50 +  });
    1.51 +}
    1.52 +
    1.53 +function testWindowHost() {
    1.54 +  // Make sure toolbox is not focused.
    1.55 +  window.addEventListener("focus", onFocus, true);
    1.56 +
    1.57 +  // Need to wait for focus  as otherwise window.focus() is overridden by
    1.58 +  // toolbox window getting focused first on Linux and Mac.
    1.59 +  let onToolboxFocus = () => {
    1.60 +    toolbox._host._window.removeEventListener("focus", onToolboxFocus, true);
    1.61 +    info("focusing main window.");
    1.62 +    window.focus()
    1.63 +  };
    1.64 +  // Need to wait for toolbox window to get focus.
    1.65 +  toolbox._host._window.addEventListener("focus", onToolboxFocus, true);
    1.66 +}
    1.67 +
    1.68 +function onFocus() {
    1.69 +  info("Main window is focused before calling toolbox.raise()")
    1.70 +  window.removeEventListener("focus", onFocus, true);
    1.71 +
    1.72 +  // Check if toolbox window got focus.
    1.73 +  let onToolboxFocusAgain = () => {
    1.74 +    toolbox._host._window.removeEventListener("focus", onToolboxFocusAgain, false);
    1.75 +    ok(true, "Toolbox window is the focused window after calling toolbox.raise()");
    1.76 +    cleanup();
    1.77 +  };
    1.78 +  toolbox._host._window.addEventListener("focus", onToolboxFocusAgain, false);
    1.79 +
    1.80 +  // Now raise toolbox.
    1.81 +  toolbox.raise();
    1.82 +}
    1.83 +
    1.84 +function cleanup() {
    1.85 +  Services.prefs.setCharPref("devtools.toolbox.host", Toolbox.HostType.BOTTOM);
    1.86 +
    1.87 +  toolbox.destroy().then(function() {
    1.88 +    DevTools = Toolbox = toolbox = target = null;
    1.89 +    gBrowser.removeCurrentTab();
    1.90 +    gBrowser.removeCurrentTab();
    1.91 +    finish();
    1.92 +  });
    1.93 +}

mercurial