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 | let temp = {} |
michael@0 | 6 | Cu.import("resource:///modules/devtools/gDevTools.jsm", temp); |
michael@0 | 7 | let DevTools = temp.DevTools; |
michael@0 | 8 | |
michael@0 | 9 | Cu.import("resource://gre/modules/devtools/Loader.jsm", temp); |
michael@0 | 10 | let devtools = temp.devtools; |
michael@0 | 11 | |
michael@0 | 12 | let Toolbox = devtools.Toolbox; |
michael@0 | 13 | |
michael@0 | 14 | let toolbox, target; |
michael@0 | 15 | |
michael@0 | 16 | function test() |
michael@0 | 17 | { |
michael@0 | 18 | waitForExplicitFinish(); |
michael@0 | 19 | |
michael@0 | 20 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 21 | target = TargetFactory.forTab(gBrowser.selectedTab); |
michael@0 | 22 | |
michael@0 | 23 | gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { |
michael@0 | 24 | gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); |
michael@0 | 25 | gDevTools.showToolbox(target) |
michael@0 | 26 | .then(testBottomHost, console.error) |
michael@0 | 27 | .then(null, console.error); |
michael@0 | 28 | }, true); |
michael@0 | 29 | |
michael@0 | 30 | content.location = "data:text/html,test for opening toolbox in different hosts"; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function testBottomHost(aToolbox) |
michael@0 | 34 | { |
michael@0 | 35 | toolbox = aToolbox; |
michael@0 | 36 | |
michael@0 | 37 | checkHostType(Toolbox.HostType.BOTTOM); |
michael@0 | 38 | |
michael@0 | 39 | // test UI presence |
michael@0 | 40 | let nbox = gBrowser.getNotificationBox(); |
michael@0 | 41 | let iframe = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-bottom-iframe"); |
michael@0 | 42 | ok(iframe, "toolbox bottom iframe exists"); |
michael@0 | 43 | |
michael@0 | 44 | checkToolboxLoaded(iframe); |
michael@0 | 45 | |
michael@0 | 46 | toolbox.switchHost(Toolbox.HostType.SIDE).then(testSidebarHost); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | function testSidebarHost() |
michael@0 | 50 | { |
michael@0 | 51 | checkHostType(Toolbox.HostType.SIDE); |
michael@0 | 52 | |
michael@0 | 53 | // test UI presence |
michael@0 | 54 | let nbox = gBrowser.getNotificationBox(); |
michael@0 | 55 | let bottom = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-bottom-iframe"); |
michael@0 | 56 | ok(!bottom, "toolbox bottom iframe doesn't exist"); |
michael@0 | 57 | |
michael@0 | 58 | let iframe = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-side-iframe"); |
michael@0 | 59 | ok(iframe, "toolbox side iframe exists"); |
michael@0 | 60 | |
michael@0 | 61 | checkToolboxLoaded(iframe); |
michael@0 | 62 | |
michael@0 | 63 | toolbox.switchHost(Toolbox.HostType.WINDOW).then(testWindowHost); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | function testWindowHost() |
michael@0 | 67 | { |
michael@0 | 68 | checkHostType(Toolbox.HostType.WINDOW); |
michael@0 | 69 | |
michael@0 | 70 | let nbox = gBrowser.getNotificationBox(); |
michael@0 | 71 | let sidebar = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-side-iframe"); |
michael@0 | 72 | ok(!sidebar, "toolbox sidebar iframe doesn't exist"); |
michael@0 | 73 | |
michael@0 | 74 | let win = Services.wm.getMostRecentWindow("devtools:toolbox"); |
michael@0 | 75 | ok(win, "toolbox separate window exists"); |
michael@0 | 76 | |
michael@0 | 77 | let iframe = win.document.getElementById("toolbox-iframe"); |
michael@0 | 78 | checkToolboxLoaded(iframe); |
michael@0 | 79 | |
michael@0 | 80 | testToolSelect(); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | function testToolSelect() |
michael@0 | 84 | { |
michael@0 | 85 | // make sure we can load a tool after switching hosts |
michael@0 | 86 | toolbox.selectTool("inspector").then(testDestroy); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | function testDestroy() |
michael@0 | 90 | { |
michael@0 | 91 | toolbox.destroy().then(function() { |
michael@0 | 92 | target = TargetFactory.forTab(gBrowser.selectedTab); |
michael@0 | 93 | gDevTools.showToolbox(target).then(testRememberHost); |
michael@0 | 94 | }); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | function testRememberHost(aToolbox) |
michael@0 | 98 | { |
michael@0 | 99 | toolbox = aToolbox; |
michael@0 | 100 | // last host was the window - make sure it's the same when re-opening |
michael@0 | 101 | is(toolbox.hostType, Toolbox.HostType.WINDOW, "host remembered"); |
michael@0 | 102 | |
michael@0 | 103 | let win = Services.wm.getMostRecentWindow("devtools:toolbox"); |
michael@0 | 104 | ok(win, "toolbox separate window exists"); |
michael@0 | 105 | |
michael@0 | 106 | cleanup(); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | function checkHostType(hostType) |
michael@0 | 110 | { |
michael@0 | 111 | is(toolbox.hostType, hostType, "host type is " + hostType); |
michael@0 | 112 | |
michael@0 | 113 | let pref = Services.prefs.getCharPref("devtools.toolbox.host"); |
michael@0 | 114 | is(pref, hostType, "host pref is " + hostType); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | function checkToolboxLoaded(iframe) |
michael@0 | 118 | { |
michael@0 | 119 | let tabs = iframe.contentDocument.getElementById("toolbox-tabs"); |
michael@0 | 120 | ok(tabs, "toolbox UI has been loaded into iframe"); |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | function cleanup() |
michael@0 | 124 | { |
michael@0 | 125 | Services.prefs.setCharPref("devtools.toolbox.host", Toolbox.HostType.BOTTOM); |
michael@0 | 126 | |
michael@0 | 127 | toolbox.destroy().then(function() { |
michael@0 | 128 | DevTools = Toolbox = toolbox = target = null; |
michael@0 | 129 | gBrowser.removeCurrentTab(); |
michael@0 | 130 | finish(); |
michael@0 | 131 | }); |
michael@0 | 132 | } |