1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/framework/test/browser_toolbox_hosts.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,132 @@ 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 +let temp = {} 1.9 +Cu.import("resource:///modules/devtools/gDevTools.jsm", temp); 1.10 +let DevTools = temp.DevTools; 1.11 + 1.12 +Cu.import("resource://gre/modules/devtools/Loader.jsm", temp); 1.13 +let devtools = temp.devtools; 1.14 + 1.15 +let Toolbox = devtools.Toolbox; 1.16 + 1.17 +let toolbox, target; 1.18 + 1.19 +function test() 1.20 +{ 1.21 + waitForExplicitFinish(); 1.22 + 1.23 + gBrowser.selectedTab = gBrowser.addTab(); 1.24 + target = TargetFactory.forTab(gBrowser.selectedTab); 1.25 + 1.26 + gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { 1.27 + gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); 1.28 + gDevTools.showToolbox(target) 1.29 + .then(testBottomHost, console.error) 1.30 + .then(null, console.error); 1.31 + }, true); 1.32 + 1.33 + content.location = "data:text/html,test for opening toolbox in different hosts"; 1.34 +} 1.35 + 1.36 +function testBottomHost(aToolbox) 1.37 +{ 1.38 + toolbox = aToolbox; 1.39 + 1.40 + checkHostType(Toolbox.HostType.BOTTOM); 1.41 + 1.42 + // test UI presence 1.43 + let nbox = gBrowser.getNotificationBox(); 1.44 + let iframe = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-bottom-iframe"); 1.45 + ok(iframe, "toolbox bottom iframe exists"); 1.46 + 1.47 + checkToolboxLoaded(iframe); 1.48 + 1.49 + toolbox.switchHost(Toolbox.HostType.SIDE).then(testSidebarHost); 1.50 +} 1.51 + 1.52 +function testSidebarHost() 1.53 +{ 1.54 + checkHostType(Toolbox.HostType.SIDE); 1.55 + 1.56 + // test UI presence 1.57 + let nbox = gBrowser.getNotificationBox(); 1.58 + let bottom = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-bottom-iframe"); 1.59 + ok(!bottom, "toolbox bottom iframe doesn't exist"); 1.60 + 1.61 + let iframe = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-side-iframe"); 1.62 + ok(iframe, "toolbox side iframe exists"); 1.63 + 1.64 + checkToolboxLoaded(iframe); 1.65 + 1.66 + toolbox.switchHost(Toolbox.HostType.WINDOW).then(testWindowHost); 1.67 +} 1.68 + 1.69 +function testWindowHost() 1.70 +{ 1.71 + checkHostType(Toolbox.HostType.WINDOW); 1.72 + 1.73 + let nbox = gBrowser.getNotificationBox(); 1.74 + let sidebar = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-side-iframe"); 1.75 + ok(!sidebar, "toolbox sidebar iframe doesn't exist"); 1.76 + 1.77 + let win = Services.wm.getMostRecentWindow("devtools:toolbox"); 1.78 + ok(win, "toolbox separate window exists"); 1.79 + 1.80 + let iframe = win.document.getElementById("toolbox-iframe"); 1.81 + checkToolboxLoaded(iframe); 1.82 + 1.83 + testToolSelect(); 1.84 +} 1.85 + 1.86 +function testToolSelect() 1.87 +{ 1.88 + // make sure we can load a tool after switching hosts 1.89 + toolbox.selectTool("inspector").then(testDestroy); 1.90 +} 1.91 + 1.92 +function testDestroy() 1.93 +{ 1.94 + toolbox.destroy().then(function() { 1.95 + target = TargetFactory.forTab(gBrowser.selectedTab); 1.96 + gDevTools.showToolbox(target).then(testRememberHost); 1.97 + }); 1.98 +} 1.99 + 1.100 +function testRememberHost(aToolbox) 1.101 +{ 1.102 + toolbox = aToolbox; 1.103 + // last host was the window - make sure it's the same when re-opening 1.104 + is(toolbox.hostType, Toolbox.HostType.WINDOW, "host remembered"); 1.105 + 1.106 + let win = Services.wm.getMostRecentWindow("devtools:toolbox"); 1.107 + ok(win, "toolbox separate window exists"); 1.108 + 1.109 + cleanup(); 1.110 +} 1.111 + 1.112 +function checkHostType(hostType) 1.113 +{ 1.114 + is(toolbox.hostType, hostType, "host type is " + hostType); 1.115 + 1.116 + let pref = Services.prefs.getCharPref("devtools.toolbox.host"); 1.117 + is(pref, hostType, "host pref is " + hostType); 1.118 +} 1.119 + 1.120 +function checkToolboxLoaded(iframe) 1.121 +{ 1.122 + let tabs = iframe.contentDocument.getElementById("toolbox-tabs"); 1.123 + ok(tabs, "toolbox UI has been loaded into iframe"); 1.124 +} 1.125 + 1.126 +function cleanup() 1.127 +{ 1.128 + Services.prefs.setCharPref("devtools.toolbox.host", Toolbox.HostType.BOTTOM); 1.129 + 1.130 + toolbox.destroy().then(function() { 1.131 + DevTools = Toolbox = toolbox = target = null; 1.132 + gBrowser.removeCurrentTab(); 1.133 + finish(); 1.134 + }); 1.135 + }