|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 Cu.import("resource://gre/modules/Task.jsm"); |
|
5 |
|
6 let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); |
|
7 const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {}); |
|
8 let TargetFactory = devtools.TargetFactory; |
|
9 |
|
10 Services.prefs.setBoolPref("devtools.inspector.sidebarOpen", true); |
|
11 Services.prefs.setIntPref("devtools.toolbox.footer.height", 350); |
|
12 gDevTools.testing = true; |
|
13 SimpleTest.registerCleanupFunction(() => { |
|
14 Services.prefs.clearUserPref("devtools.inspector.sidebarOpen"); |
|
15 Services.prefs.clearUserPref("devtools.toolbox.footer.height"); |
|
16 gDevTools.testing = false; |
|
17 }); |
|
18 |
|
19 // All tests are async in general |
|
20 waitForExplicitFinish(); |
|
21 |
|
22 function loadTab(url) { |
|
23 let deferred = promise.defer(); |
|
24 |
|
25 gBrowser.selectedTab = gBrowser.addTab(); |
|
26 gBrowser.selectedBrowser.addEventListener("load", function onload() { |
|
27 gBrowser.selectedBrowser.removeEventListener("load", onload, true); |
|
28 waitForFocus(function() { |
|
29 deferred.resolve(content); |
|
30 }, content); |
|
31 }, true); |
|
32 |
|
33 content.location = url; |
|
34 |
|
35 return deferred.promise; |
|
36 } |
|
37 |
|
38 function selectNode(aNode) { |
|
39 info("selecting node"); |
|
40 let onSelect = inspector.once("layoutview-updated"); |
|
41 inspector.selection.setNode(aNode, "test"); |
|
42 return onSelect.then(() => { |
|
43 let view = inspector.sidebar.getWindowForTab("layoutview"); |
|
44 ok(!!view.layoutview, "LayoutView document is alive."); |
|
45 |
|
46 return view; |
|
47 }); |
|
48 } |
|
49 |
|
50 function waitForUpdate() { |
|
51 return inspector.once("layoutview-updated"); |
|
52 } |
|
53 |
|
54 function asyncTest(testfunc) { |
|
55 return Task.async(function*() { |
|
56 let initialTab = gBrowser.selectedTab; |
|
57 |
|
58 yield testfunc(); |
|
59 |
|
60 // Remove all tabs except for the initial tab. This is basically |
|
61 // gBrowser.removeAllTabsBut without the animation |
|
62 let tabs = gBrowser.visibleTabs; |
|
63 gBrowser.selectedTab = initialTab; |
|
64 for (let i = tabs.length - 1; i >= 0; i--) { |
|
65 if (tabs[i] != initialTab) |
|
66 gBrowser.removeTab(tabs[i]); |
|
67 } |
|
68 |
|
69 // Reset the sidebar back to the default |
|
70 Services.prefs.setCharPref("devtools.inspector.activeSidebar", "ruleview"); |
|
71 |
|
72 finish(); |
|
73 }); |
|
74 } |
|
75 |
|
76 var TESTS = []; |
|
77 |
|
78 function addTest(message, func) { |
|
79 TESTS.push([message, Task.async(func)]) |
|
80 } |
|
81 |
|
82 var runTests = Task.async(function*() { |
|
83 for (let [message, test] of TESTS) { |
|
84 info(message); |
|
85 yield test(); |
|
86 } |
|
87 }); |