|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Tests that installed addons in the search view load inline prefs properly |
|
6 |
|
7 const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; |
|
8 const NO_MATCH_URL = TESTROOT + "browser_searching_empty.xml"; |
|
9 |
|
10 var gManagerWindow; |
|
11 var gCategoryUtilities; |
|
12 var gProvider; |
|
13 |
|
14 function test() { |
|
15 // Turn on searching for this test |
|
16 Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15); |
|
17 |
|
18 waitForExplicitFinish(); |
|
19 |
|
20 gProvider = new MockProvider(); |
|
21 |
|
22 gProvider.createAddons([{ |
|
23 id: "inlinesettings2@tests.mozilla.org", |
|
24 name: "Inline Settings (Regular)", |
|
25 version: "1", |
|
26 optionsURL: CHROMEROOT + "options.xul", |
|
27 optionsType: AddonManager.OPTIONS_TYPE_INLINE |
|
28 }]); |
|
29 |
|
30 open_manager("addons://list/extension", function(aWindow) { |
|
31 gManagerWindow = aWindow; |
|
32 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
33 run_next_test(); |
|
34 }); |
|
35 } |
|
36 |
|
37 function end_test() { |
|
38 close_manager(gManagerWindow, finish); |
|
39 } |
|
40 |
|
41 /* |
|
42 * Checks whether or not the Add-ons Manager is currently searching |
|
43 * |
|
44 * @param aExpectedSearching |
|
45 * The expected isSearching state |
|
46 */ |
|
47 function check_is_searching(aExpectedSearching) { |
|
48 var loading = gManagerWindow.document.getElementById("search-loading"); |
|
49 is(!is_hidden(loading), aExpectedSearching, |
|
50 "Search throbber should be showing iff currently searching"); |
|
51 } |
|
52 |
|
53 /* |
|
54 * Completes a search |
|
55 * |
|
56 * @param aQuery |
|
57 * The query to search for |
|
58 * @param aFinishImmediately |
|
59 * Boolean representing whether or not the search is expected to |
|
60 * finish immediately |
|
61 * @param aCallback |
|
62 * The callback to call when the search is done |
|
63 * @param aCategoryType |
|
64 * The expected selected category after the search is done. |
|
65 * Optional and defaults to "search" |
|
66 */ |
|
67 function search(aQuery, aFinishImmediately, aCallback, aCategoryType) { |
|
68 // Point search to the correct xml test file |
|
69 Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, NO_MATCH_URL); |
|
70 |
|
71 aCategoryType = aCategoryType ? aCategoryType : "search"; |
|
72 |
|
73 var searchBox = gManagerWindow.document.getElementById("header-search"); |
|
74 searchBox.value = aQuery; |
|
75 |
|
76 EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow); |
|
77 EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow); |
|
78 |
|
79 var finishImmediately = true; |
|
80 wait_for_view_load(gManagerWindow, function() { |
|
81 is(gCategoryUtilities.selectedCategory, aCategoryType, "Expected category view should be selected"); |
|
82 is(gCategoryUtilities.isTypeVisible("search"), aCategoryType == "search", |
|
83 "Search category should only be visible if it is the current view"); |
|
84 is(finishImmediately, aFinishImmediately, "Search should finish immediately only if expected"); |
|
85 |
|
86 aCallback(); |
|
87 }); |
|
88 |
|
89 finishImmediately = false |
|
90 if (!aFinishImmediately) |
|
91 check_is_searching(true); |
|
92 } |
|
93 |
|
94 /* |
|
95 * Get item for a specific add-on by name |
|
96 * |
|
97 * @param aName |
|
98 * The name of the add-on to search for |
|
99 * @return Row of add-on if found, null otherwise |
|
100 */ |
|
101 function get_addon_item(aName) { |
|
102 var id = aName + "@tests.mozilla.org"; |
|
103 var list = gManagerWindow.document.getElementById("search-list"); |
|
104 var rows = list.getElementsByTagName("richlistitem"); |
|
105 for (let row of rows) { |
|
106 if (row.mAddon && row.mAddon.id == id) |
|
107 return row; |
|
108 } |
|
109 |
|
110 return null; |
|
111 } |
|
112 |
|
113 add_test(function() { |
|
114 search("settings", false, function() { |
|
115 var localFilter = gManagerWindow.document.getElementById("search-filter-local"); |
|
116 EventUtils.synthesizeMouseAtCenter(localFilter, { }, gManagerWindow); |
|
117 |
|
118 var item = get_addon_item("inlinesettings2"); |
|
119 // Force the XBL binding to apply. |
|
120 item.clientTop; |
|
121 var button = gManagerWindow.document.getAnonymousElementByAttribute(item, "anonid", "preferences-btn"); |
|
122 is_element_visible(button, "Preferences button should be visible"); |
|
123 |
|
124 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); |
|
125 wait_for_view_load(gManagerWindow, function() { |
|
126 is(gManagerWindow.gViewController.currentViewObj, gManagerWindow.gDetailView, "View should have changed to detail"); |
|
127 |
|
128 var searchCategory = gManagerWindow.document.getElementById("category-search"); |
|
129 EventUtils.synthesizeMouseAtCenter(searchCategory, { }, gManagerWindow); |
|
130 wait_for_view_load(gManagerWindow, function() { |
|
131 is(gManagerWindow.gViewController.currentViewObj, gManagerWindow.gSearchView, "View should have changed back to search"); |
|
132 |
|
133 // Reset filter to remote to avoid breaking later tests. |
|
134 var remoteFilter = gManagerWindow.document.getElementById("search-filter-remote"); |
|
135 EventUtils.synthesizeMouseAtCenter(remoteFilter, { }, gManagerWindow); |
|
136 run_next_test(); |
|
137 }); |
|
138 }); |
|
139 }); |
|
140 }); |