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