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 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | "use strict"; |
michael@0 | 5 | |
michael@0 | 6 | let {devtools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {}); |
michael@0 | 7 | let TargetFactory = devtools.TargetFactory; |
michael@0 | 8 | |
michael@0 | 9 | // Import the GCLI test helper |
michael@0 | 10 | let testDir = gTestPath.substr(0, gTestPath.lastIndexOf("/")); |
michael@0 | 11 | Services.scriptloader.loadSubScript(testDir + "../../../commandline/test/helpers.js", this); |
michael@0 | 12 | |
michael@0 | 13 | gDevTools.testing = true; |
michael@0 | 14 | SimpleTest.registerCleanupFunction(() => { |
michael@0 | 15 | gDevTools.testing = false; |
michael@0 | 16 | }); |
michael@0 | 17 | |
michael@0 | 18 | /** |
michael@0 | 19 | * Open the toolbox, with the inspector tool visible. |
michael@0 | 20 | * @return a promise that resolves when the inspector is ready |
michael@0 | 21 | */ |
michael@0 | 22 | let openInspector = Task.async(function*() { |
michael@0 | 23 | info("Opening the inspector"); |
michael@0 | 24 | let target = TargetFactory.forTab(gBrowser.selectedTab); |
michael@0 | 25 | |
michael@0 | 26 | let inspector, toolbox; |
michael@0 | 27 | |
michael@0 | 28 | // Checking if the toolbox and the inspector are already loaded |
michael@0 | 29 | // The inspector-updated event should only be waited for if the inspector |
michael@0 | 30 | // isn't loaded yet |
michael@0 | 31 | toolbox = gDevTools.getToolbox(target); |
michael@0 | 32 | if (toolbox) { |
michael@0 | 33 | inspector = toolbox.getPanel("inspector"); |
michael@0 | 34 | if (inspector) { |
michael@0 | 35 | info("Toolbox and inspector already open"); |
michael@0 | 36 | return { |
michael@0 | 37 | toolbox: toolbox, |
michael@0 | 38 | inspector: inspector |
michael@0 | 39 | }; |
michael@0 | 40 | } |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | info("Opening the toolbox"); |
michael@0 | 44 | toolbox = yield gDevTools.showToolbox(target, "inspector"); |
michael@0 | 45 | yield waitForToolboxFrameFocus(toolbox); |
michael@0 | 46 | inspector = toolbox.getPanel("inspector"); |
michael@0 | 47 | |
michael@0 | 48 | info("Waiting for the inspector to update"); |
michael@0 | 49 | yield inspector.once("inspector-updated"); |
michael@0 | 50 | |
michael@0 | 51 | return { |
michael@0 | 52 | toolbox: toolbox, |
michael@0 | 53 | inspector: inspector |
michael@0 | 54 | }; |
michael@0 | 55 | }); |
michael@0 | 56 | |
michael@0 | 57 | /** |
michael@0 | 58 | * Wait for the toolbox frame to receive focus after it loads |
michael@0 | 59 | * @param {Toolbox} toolbox |
michael@0 | 60 | * @return a promise that resolves when focus has been received |
michael@0 | 61 | */ |
michael@0 | 62 | function waitForToolboxFrameFocus(toolbox) { |
michael@0 | 63 | info("Making sure that the toolbox's frame is focused"); |
michael@0 | 64 | let def = promise.defer(); |
michael@0 | 65 | let win = toolbox.frame.contentWindow; |
michael@0 | 66 | waitForFocus(def.resolve, win); |
michael@0 | 67 | return def.promise; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | /** |
michael@0 | 71 | * Open the toolbox, with the inspector tool visible, and the sidebar that |
michael@0 | 72 | * corresponds to the given id selected |
michael@0 | 73 | * @return a promise that resolves when the inspector is ready and the sidebar |
michael@0 | 74 | * view is visible and ready |
michael@0 | 75 | */ |
michael@0 | 76 | let openInspectorSideBar = Task.async(function*(id) { |
michael@0 | 77 | let {toolbox, inspector} = yield openInspector(); |
michael@0 | 78 | |
michael@0 | 79 | if (!hasSideBarTab(inspector, id)) { |
michael@0 | 80 | info("Waiting for the " + id + " sidebar to be ready"); |
michael@0 | 81 | yield inspector.sidebar.once(id + "-ready"); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | info("Selecting the " + id + " sidebar"); |
michael@0 | 85 | inspector.sidebar.select(id); |
michael@0 | 86 | |
michael@0 | 87 | return { |
michael@0 | 88 | toolbox: toolbox, |
michael@0 | 89 | inspector: inspector, |
michael@0 | 90 | view: inspector.sidebar.getWindowForTab(id)[id].view |
michael@0 | 91 | }; |
michael@0 | 92 | }); |
michael@0 | 93 | |
michael@0 | 94 | /** |
michael@0 | 95 | * Checks whether the inspector's sidebar corresponding to the given id already |
michael@0 | 96 | * exists |
michael@0 | 97 | * @param {InspectorPanel} |
michael@0 | 98 | * @param {String} |
michael@0 | 99 | * @return {Boolean} |
michael@0 | 100 | */ |
michael@0 | 101 | function hasSideBarTab(inspector, id) { |
michael@0 | 102 | return !!inspector.sidebar.getWindowForTab(id); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | /** |
michael@0 | 106 | * Open the toolbox, with the inspector tool visible, and the computed-view |
michael@0 | 107 | * sidebar tab selected. |
michael@0 | 108 | * @return a promise that resolves when the inspector is ready and the computed |
michael@0 | 109 | * view is visible and ready |
michael@0 | 110 | */ |
michael@0 | 111 | function openComputedView() { |
michael@0 | 112 | return openInspectorSideBar("computedview"); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | /** |
michael@0 | 116 | * Open the toolbox, with the inspector tool visible, and the rule-view |
michael@0 | 117 | * sidebar tab selected. |
michael@0 | 118 | * @return a promise that resolves when the inspector is ready and the rule |
michael@0 | 119 | * view is visible and ready |
michael@0 | 120 | */ |
michael@0 | 121 | function openRuleView() { |
michael@0 | 122 | return openInspectorSideBar("ruleview"); |
michael@0 | 123 | } |