|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Tests that marketplace results show up in searches, are sorted right and |
|
6 // attempting to buy links through to the right webpage |
|
7 |
|
8 const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; |
|
9 const SEARCH_URL = TESTROOT + "browser_purchase.xml"; |
|
10 |
|
11 var gManagerWindow; |
|
12 |
|
13 function test() { |
|
14 // Turn on searching for this test |
|
15 Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15); |
|
16 Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, SEARCH_URL); |
|
17 |
|
18 waitForExplicitFinish(); |
|
19 |
|
20 open_manager("addons://list/extension", function(aWindow) { |
|
21 gManagerWindow = aWindow; |
|
22 |
|
23 waitForFocus(function() { |
|
24 var searchBox = gManagerWindow.document.getElementById("header-search"); |
|
25 searchBox.value = "foo"; |
|
26 |
|
27 EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow); |
|
28 EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow); |
|
29 |
|
30 wait_for_view_load(gManagerWindow, function() { |
|
31 var remoteFilter = gManagerWindow.document.getElementById("search-filter-remote"); |
|
32 EventUtils.synthesizeMouseAtCenter(remoteFilter, { }, gManagerWindow); |
|
33 |
|
34 run_next_test(); |
|
35 }); |
|
36 }, aWindow); |
|
37 }); |
|
38 } |
|
39 |
|
40 function end_test() { |
|
41 close_manager(gManagerWindow, function() { |
|
42 // Will have created an install so cancel it |
|
43 AddonManager.getAllInstalls(function(aInstalls) { |
|
44 is(aInstalls.length, 1, "Should have been one install created"); |
|
45 aInstalls[0].cancel(); |
|
46 |
|
47 finish(); |
|
48 }); |
|
49 }); |
|
50 } |
|
51 |
|
52 function get_node(parent, anonid) { |
|
53 return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid); |
|
54 } |
|
55 |
|
56 function get_install_btn(parent) { |
|
57 var installStatus = get_node(parent, "install-status"); |
|
58 return get_node(installStatus, "install-remote-btn"); |
|
59 } |
|
60 |
|
61 function get_purchase_btn(parent) { |
|
62 var installStatus = get_node(parent, "install-status"); |
|
63 return get_node(installStatus, "purchase-remote-btn"); |
|
64 } |
|
65 |
|
66 // Tests that the expected results appeared |
|
67 add_test(function() { |
|
68 var list = gManagerWindow.document.getElementById("search-list"); |
|
69 var items = Array.filter(list.childNodes, function(e) { |
|
70 return e.tagName == "richlistitem"; |
|
71 }); |
|
72 |
|
73 is(items.length, 5, "Should be 5 results"); |
|
74 |
|
75 is(get_node(items[0], "name").value, "Ludicrously Expensive Add-on", "Add-on 0 should be in expected position"); |
|
76 is_element_hidden(get_install_btn(items[0]), "Add-on 0 install button should be hidden"); |
|
77 is_element_visible(get_purchase_btn(items[0]), "Add-on 0 purchase button should be visible"); |
|
78 is(get_purchase_btn(items[0]).label, "Purchase for $101\u2026", "Add-on 0 should have the right price"); |
|
79 |
|
80 is(get_node(items[1], "name").value, "Cheap Add-on", "Add-on 1 should be in expected position"); |
|
81 is_element_hidden(get_install_btn(items[1]), "Add-on 1 install button should be hidden"); |
|
82 is_element_visible(get_purchase_btn(items[1]), "Add-on 1 purchase button should be visible"); |
|
83 is(get_purchase_btn(items[1]).label, "Purchase for $0.99\u2026", "Add-on 2 should have the right price"); |
|
84 |
|
85 is(get_node(items[2], "name").value, "Reasonable Add-on", "Add-on 2 should be in expected position"); |
|
86 is_element_hidden(get_install_btn(items[2]), "Add-on 2 install button should be hidden"); |
|
87 is_element_visible(get_purchase_btn(items[2]), "Add-on 2 purchase button should be visible"); |
|
88 is(get_purchase_btn(items[2]).label, "Purchase for $1\u2026", "Add-on 3 should have the right price"); |
|
89 |
|
90 is(get_node(items[3], "name").value, "Free Add-on", "Add-on 3 should be in expected position"); |
|
91 is_element_visible(get_install_btn(items[3]), "Add-on 3 install button should be visible"); |
|
92 is_element_hidden(get_purchase_btn(items[3]), "Add-on 3 purchase button should be hidden"); |
|
93 |
|
94 is(get_node(items[4], "name").value, "More Expensive Add-on", "Add-on 4 should be in expected position"); |
|
95 is_element_hidden(get_install_btn(items[4]), "Add-on 4 install button should be hidden"); |
|
96 is_element_visible(get_purchase_btn(items[4]), "Add-on 4 purchase button should be visible"); |
|
97 is(get_purchase_btn(items[4]).label, "Purchase for $1.01\u2026", "Add-on 4 should have the right price"); |
|
98 |
|
99 run_next_test(); |
|
100 }); |
|
101 |
|
102 // Tests that sorting by price works |
|
103 add_test(function() { |
|
104 var list = gManagerWindow.document.getElementById("search-list"); |
|
105 |
|
106 var sorters = gManagerWindow.document.getElementById("search-sorters"); |
|
107 var priceSorter = get_node(sorters, "price-btn"); |
|
108 info("Changing sort order"); |
|
109 EventUtils.synthesizeMouseAtCenter(priceSorter, { }, gManagerWindow); |
|
110 |
|
111 var items = Array.filter(list.childNodes, function(e) { |
|
112 return e.tagName == "richlistitem"; |
|
113 }); |
|
114 |
|
115 is(get_node(items[0], "name").value, "Free Add-on", "Add-on 0 should be in expected position"); |
|
116 is(get_node(items[1], "name").value, "Cheap Add-on", "Add-on 1 should be in expected position"); |
|
117 is(get_node(items[2], "name").value, "Reasonable Add-on", "Add-on 2 should be in expected position"); |
|
118 is(get_node(items[3], "name").value, "More Expensive Add-on", "Add-on 3 should be in expected position"); |
|
119 is(get_node(items[4], "name").value, "Ludicrously Expensive Add-on", "Add-on 4 should be in expected position"); |
|
120 |
|
121 info("Changing sort order"); |
|
122 EventUtils.synthesizeMouseAtCenter(priceSorter, { }, gManagerWindow); |
|
123 |
|
124 var items = Array.filter(list.childNodes, function(e) { |
|
125 return e.tagName == "richlistitem"; |
|
126 }); |
|
127 |
|
128 is(get_node(items[0], "name").value, "Ludicrously Expensive Add-on", "Add-on 0 should be in expected position"); |
|
129 is(get_node(items[1], "name").value, "More Expensive Add-on", "Add-on 1 should be in expected position"); |
|
130 is(get_node(items[2], "name").value, "Reasonable Add-on", "Add-on 2 should be in expected position"); |
|
131 is(get_node(items[3], "name").value, "Cheap Add-on", "Add-on 3 should be in expected position"); |
|
132 is(get_node(items[4], "name").value, "Free Add-on", "Add-on 4 should be in expected position"); |
|
133 |
|
134 run_next_test(); |
|
135 }); |
|
136 |
|
137 // Tests that clicking the buy button works from the list |
|
138 add_test(function() { |
|
139 gBrowser.addEventListener("load", function(event) { |
|
140 if (!(event.target instanceof Document) || |
|
141 event.target.location.href == "about:blank") |
|
142 return; |
|
143 gBrowser.removeEventListener("load", arguments.callee, true); |
|
144 |
|
145 is(gBrowser.currentURI.spec, TESTROOT + "releaseNotes.xhtml?addon5", "Should have loaded the right page"); |
|
146 |
|
147 gBrowser.removeCurrentTab(); |
|
148 |
|
149 if (gUseInContentUI) { |
|
150 is(gBrowser.currentURI.spec, "about:addons", "Should be back to the add-ons manager"); |
|
151 run_next_test(); |
|
152 } |
|
153 else { |
|
154 waitForFocus(run_next_test, gManagerWindow); |
|
155 } |
|
156 }, true); |
|
157 |
|
158 var list = gManagerWindow.document.getElementById("search-list"); |
|
159 EventUtils.synthesizeMouseAtCenter(get_purchase_btn(list.firstChild), { }, gManagerWindow); |
|
160 }); |
|
161 |
|
162 // Tests that clicking the buy button from the details view works |
|
163 add_test(function() { |
|
164 gBrowser.addEventListener("load", function(event) { |
|
165 if (!(event.target instanceof Document) || |
|
166 event.target.location.href == "about:blank") |
|
167 return; |
|
168 gBrowser.removeEventListener("load", arguments.callee, true); |
|
169 |
|
170 is(gBrowser.currentURI.spec, TESTROOT + "releaseNotes.xhtml?addon4", "Should have loaded the right page"); |
|
171 |
|
172 gBrowser.removeCurrentTab(); |
|
173 |
|
174 if (gUseInContentUI) { |
|
175 is(gBrowser.currentURI.spec, "about:addons", "Should be back to the add-ons manager"); |
|
176 run_next_test(); |
|
177 } |
|
178 else { |
|
179 waitForFocus(run_next_test, gManagerWindow); |
|
180 } |
|
181 }, true); |
|
182 |
|
183 var list = gManagerWindow.document.getElementById("search-list"); |
|
184 var item = list.firstChild.nextSibling; |
|
185 list.ensureElementIsVisible(item); |
|
186 EventUtils.synthesizeMouseAtCenter(item, { clickCount: 1 }, gManagerWindow); |
|
187 EventUtils.synthesizeMouseAtCenter(item, { clickCount: 2 }, gManagerWindow); |
|
188 |
|
189 wait_for_view_load(gManagerWindow, function() { |
|
190 var btn = gManagerWindow.document.getElementById("detail-purchase-btn"); |
|
191 is_element_visible(btn, "Purchase button should be visible"); |
|
192 |
|
193 EventUtils.synthesizeMouseAtCenter(btn, { }, gManagerWindow); |
|
194 }); |
|
195 }); |