|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 "use strict"; |
|
5 |
|
6 let gTestTab; |
|
7 let gContentAPI; |
|
8 let gContentWindow; |
|
9 |
|
10 Components.utils.import("resource:///modules/UITour.jsm"); |
|
11 |
|
12 function test() { |
|
13 requestLongerTimeout(2); |
|
14 UITourTest(); |
|
15 } |
|
16 |
|
17 let tests = [ |
|
18 function test_availableTargets(done) { |
|
19 gContentAPI.getConfiguration("availableTargets", (data) => { |
|
20 ok_targets(data, [ |
|
21 "accountStatus", |
|
22 "addons", |
|
23 "appMenu", |
|
24 "backForward", |
|
25 "bookmarks", |
|
26 "customize", |
|
27 "help", |
|
28 "home", |
|
29 "pinnedTab", |
|
30 "quit", |
|
31 "search", |
|
32 "searchProvider", |
|
33 "urlbar", |
|
34 ]); |
|
35 ok(UITour.availableTargetsCache.has(window), |
|
36 "Targets should now be cached"); |
|
37 done(); |
|
38 }); |
|
39 }, |
|
40 |
|
41 function test_availableTargets_changeWidgets(done) { |
|
42 CustomizableUI.removeWidgetFromArea("bookmarks-menu-button"); |
|
43 ok(!UITour.availableTargetsCache.has(window), |
|
44 "Targets should be evicted from cache after widget change"); |
|
45 gContentAPI.getConfiguration("availableTargets", (data) => { |
|
46 ok_targets(data, [ |
|
47 "accountStatus", |
|
48 "addons", |
|
49 "appMenu", |
|
50 "backForward", |
|
51 "customize", |
|
52 "help", |
|
53 "home", |
|
54 "pinnedTab", |
|
55 "quit", |
|
56 "search", |
|
57 "searchProvider", |
|
58 "urlbar", |
|
59 ]); |
|
60 ok(UITour.availableTargetsCache.has(window), |
|
61 "Targets should now be cached again"); |
|
62 CustomizableUI.reset(); |
|
63 ok(!UITour.availableTargetsCache.has(window), |
|
64 "Targets should not be cached after reset"); |
|
65 done(); |
|
66 }); |
|
67 }, |
|
68 |
|
69 function test_availableTargets_exceptionFromGetTarget(done) { |
|
70 // The query function for the "search" target will throw if it's not found. |
|
71 // Make sure the callback still fires with the other available targets. |
|
72 CustomizableUI.removeWidgetFromArea("search-container"); |
|
73 gContentAPI.getConfiguration("availableTargets", (data) => { |
|
74 // Default minus "search" and "searchProvider" |
|
75 ok_targets(data, [ |
|
76 "accountStatus", |
|
77 "addons", |
|
78 "appMenu", |
|
79 "backForward", |
|
80 "bookmarks", |
|
81 "customize", |
|
82 "help", |
|
83 "home", |
|
84 "pinnedTab", |
|
85 "quit", |
|
86 "urlbar", |
|
87 ]); |
|
88 CustomizableUI.reset(); |
|
89 done(); |
|
90 }); |
|
91 }, |
|
92 ]; |
|
93 |
|
94 function ok_targets(actualData, expectedTargets) { |
|
95 // Depending on how soon after page load this is called, the selected tab icon |
|
96 // may or may not be showing the loading throbber. Check for its presence and |
|
97 // insert it into expectedTargets if it's visible. |
|
98 let selectedTabIcon = |
|
99 document.getAnonymousElementByAttribute(gBrowser.selectedTab, |
|
100 "anonid", |
|
101 "tab-icon-image"); |
|
102 if (selectedTabIcon && UITour.isElementVisible(selectedTabIcon)) |
|
103 expectedTargets.push("selectedTabIcon"); |
|
104 |
|
105 ok(Array.isArray(actualData.targets), "data.targets should be an array"); |
|
106 is(actualData.targets.sort().toString(), expectedTargets.sort().toString(), |
|
107 "Targets should be as expected"); |
|
108 } |