browser/devtools/framework/test/browser_toolbox_raise.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 /* vim: set ts=2 et sw=2 tw=80: */
     2 /* Any copyright is dedicated to the Public Domain.
     3    http://creativecommons.org/publicdomain/zero/1.0/ */
     5 Cu.import("resource://gre/modules/Services.jsm");
     6 let temp = {}
     7 Cu.import("resource:///modules/devtools/gDevTools.jsm", temp);
     8 let DevTools = temp.DevTools;
    10 Cu.import("resource://gre/modules/devtools/Loader.jsm", temp);
    11 let devtools = temp.devtools;
    13 let Toolbox = devtools.Toolbox;
    15 let toolbox, target, tab1, tab2;
    17 function test() {
    18   waitForExplicitFinish();
    20   gBrowser.selectedTab = tab1 = gBrowser.addTab();
    21   tab2 = gBrowser.addTab();
    22   target = TargetFactory.forTab(gBrowser.selectedTab);
    24   gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) {
    25     gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true);
    26     gDevTools.showToolbox(target)
    27              .then(testBottomHost, console.error)
    28              .then(null, console.error);
    29   }, true);
    31   content.location = "data:text/html,test for opening toolbox in different hosts";
    32 }
    34 function testBottomHost(aToolbox) {
    35   toolbox = aToolbox;
    37   // switch to another tab and test toolbox.raise()
    38   gBrowser.selectedTab = tab2;
    39   executeSoon(function() {
    40     is(gBrowser.selectedTab, tab2, "Correct tab is selected before calling raise");
    41     toolbox.raise();
    42     executeSoon(function() {
    43       is(gBrowser.selectedTab, tab1, "Correct tab was selected after calling raise");
    45       toolbox.switchHost(Toolbox.HostType.WINDOW).then(testWindowHost).then(null, console.error);
    46     });
    47   });
    48 }
    50 function testWindowHost() {
    51   // Make sure toolbox is not focused.
    52   window.addEventListener("focus", onFocus, true);
    54   // Need to wait for focus  as otherwise window.focus() is overridden by
    55   // toolbox window getting focused first on Linux and Mac.
    56   let onToolboxFocus = () => {
    57     toolbox._host._window.removeEventListener("focus", onToolboxFocus, true);
    58     info("focusing main window.");
    59     window.focus()
    60   };
    61   // Need to wait for toolbox window to get focus.
    62   toolbox._host._window.addEventListener("focus", onToolboxFocus, true);
    63 }
    65 function onFocus() {
    66   info("Main window is focused before calling toolbox.raise()")
    67   window.removeEventListener("focus", onFocus, true);
    69   // Check if toolbox window got focus.
    70   let onToolboxFocusAgain = () => {
    71     toolbox._host._window.removeEventListener("focus", onToolboxFocusAgain, false);
    72     ok(true, "Toolbox window is the focused window after calling toolbox.raise()");
    73     cleanup();
    74   };
    75   toolbox._host._window.addEventListener("focus", onToolboxFocusAgain, false);
    77   // Now raise toolbox.
    78   toolbox.raise();
    79 }
    81 function cleanup() {
    82   Services.prefs.setCharPref("devtools.toolbox.host", Toolbox.HostType.BOTTOM);
    84   toolbox.destroy().then(function() {
    85     DevTools = Toolbox = toolbox = target = null;
    86     gBrowser.removeCurrentTab();
    87     gBrowser.removeCurrentTab();
    88     finish();
    89   });
    90 }

mercurial