browser/devtools/responsivedesign/test/head.js

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

mercurial