summaryrefslogtreecommitdiffstats
path: root/browser/components/uitour/test/browser_UITour_availableTargets.js
blob: a6e96e31fa22720faf7827a3486f65471f0b62b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"use strict";

var gTestTab;
var gContentAPI;
var gContentWindow;

var hasWebIDE = Services.prefs.getBoolPref("devtools.webide.widget.enabled");
var hasPocket = Services.prefs.getBoolPref("extensions.pocket.enabled");

requestLongerTimeout(2);
add_task(setup_UITourTest);

add_UITour_task(function* test_availableTargets() {
  let data = yield getConfigurationPromise("availableTargets");
  ok_targets(data, [
    "accountStatus",
    "addons",
    "appMenu",
    "backForward",
    "bookmarks",
    "customize",
    "help",
    "home",
    "devtools",
      ...(hasPocket ? ["pocket"] : []),
    "privateWindow",
    "quit",
    "readerMode-urlBar",
    "search",
    "searchIcon",
    "trackingProtection",
    "urlbar",
      ...(hasWebIDE ? ["webide"] : [])
  ]);

  ok(UITour.availableTargetsCache.has(window),
     "Targets should now be cached");
});

add_UITour_task(function* test_availableTargets_changeWidgets() {
  CustomizableUI.removeWidgetFromArea("bookmarks-menu-button");
  ok(!UITour.availableTargetsCache.has(window),
     "Targets should be evicted from cache after widget change");
  let data = yield getConfigurationPromise("availableTargets");
  ok_targets(data, [
    "accountStatus",
    "addons",
    "appMenu",
    "backForward",
    "customize",
    "help",
    "devtools",
    "home",
      ...(hasPocket ? ["pocket"] : []),
    "privateWindow",
    "quit",
    "readerMode-urlBar",
    "search",
    "searchIcon",
    "trackingProtection",
    "urlbar",
      ...(hasWebIDE ? ["webide"] : [])
  ]);

  ok(UITour.availableTargetsCache.has(window),
     "Targets should now be cached again");
  CustomizableUI.reset();
  ok(!UITour.availableTargetsCache.has(window),
     "Targets should not be cached after reset");
});

add_UITour_task(function* test_availableTargets_exceptionFromGetTarget() {
  // The query function for the "search" target will throw if it's not found.
  // Make sure the callback still fires with the other available targets.
  CustomizableUI.removeWidgetFromArea("search-container");
  let data = yield getConfigurationPromise("availableTargets");
  // Default minus "search" and "searchIcon"
  ok_targets(data, [
    "accountStatus",
    "addons",
    "appMenu",
    "backForward",
    "bookmarks",
    "customize",
    "help",
    "home",
    "devtools",
      ...(hasPocket ? ["pocket"] : []),
    "privateWindow",
    "quit",
    "readerMode-urlBar",
    "trackingProtection",
    "urlbar",
      ...(hasWebIDE ? ["webide"] : [])
  ]);

  CustomizableUI.reset();
});

function ok_targets(actualData, expectedTargets) {
  // Depending on how soon after page load this is called, the selected tab icon
  // may or may not be showing the loading throbber.  Check for its presence and
  // insert it into expectedTargets if it's visible.
  let selectedTabIcon =
    document.getAnonymousElementByAttribute(gBrowser.selectedTab,
                                            "anonid",
                                            "tab-icon-image");
  if (selectedTabIcon && UITour.isElementVisible(selectedTabIcon))
    expectedTargets.push("selectedTabIcon");

  ok(Array.isArray(actualData.targets), "data.targets should be an array");
  is(actualData.targets.sort().toString(), expectedTargets.sort().toString(),
     "Targets should be as expected");
}