1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_purchase.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,195 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +// Tests that marketplace results show up in searches, are sorted right and 1.9 +// attempting to buy links through to the right webpage 1.10 + 1.11 +const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; 1.12 +const SEARCH_URL = TESTROOT + "browser_purchase.xml"; 1.13 + 1.14 +var gManagerWindow; 1.15 + 1.16 +function test() { 1.17 + // Turn on searching for this test 1.18 + Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15); 1.19 + Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, SEARCH_URL); 1.20 + 1.21 + waitForExplicitFinish(); 1.22 + 1.23 + open_manager("addons://list/extension", function(aWindow) { 1.24 + gManagerWindow = aWindow; 1.25 + 1.26 + waitForFocus(function() { 1.27 + var searchBox = gManagerWindow.document.getElementById("header-search"); 1.28 + searchBox.value = "foo"; 1.29 + 1.30 + EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow); 1.31 + EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow); 1.32 + 1.33 + wait_for_view_load(gManagerWindow, function() { 1.34 + var remoteFilter = gManagerWindow.document.getElementById("search-filter-remote"); 1.35 + EventUtils.synthesizeMouseAtCenter(remoteFilter, { }, gManagerWindow); 1.36 + 1.37 + run_next_test(); 1.38 + }); 1.39 + }, aWindow); 1.40 + }); 1.41 +} 1.42 + 1.43 +function end_test() { 1.44 + close_manager(gManagerWindow, function() { 1.45 + // Will have created an install so cancel it 1.46 + AddonManager.getAllInstalls(function(aInstalls) { 1.47 + is(aInstalls.length, 1, "Should have been one install created"); 1.48 + aInstalls[0].cancel(); 1.49 + 1.50 + finish(); 1.51 + }); 1.52 + }); 1.53 +} 1.54 + 1.55 +function get_node(parent, anonid) { 1.56 + return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid); 1.57 +} 1.58 + 1.59 +function get_install_btn(parent) { 1.60 + var installStatus = get_node(parent, "install-status"); 1.61 + return get_node(installStatus, "install-remote-btn"); 1.62 +} 1.63 + 1.64 +function get_purchase_btn(parent) { 1.65 + var installStatus = get_node(parent, "install-status"); 1.66 + return get_node(installStatus, "purchase-remote-btn"); 1.67 +} 1.68 + 1.69 +// Tests that the expected results appeared 1.70 +add_test(function() { 1.71 + var list = gManagerWindow.document.getElementById("search-list"); 1.72 + var items = Array.filter(list.childNodes, function(e) { 1.73 + return e.tagName == "richlistitem"; 1.74 + }); 1.75 + 1.76 + is(items.length, 5, "Should be 5 results"); 1.77 + 1.78 + is(get_node(items[0], "name").value, "Ludicrously Expensive Add-on", "Add-on 0 should be in expected position"); 1.79 + is_element_hidden(get_install_btn(items[0]), "Add-on 0 install button should be hidden"); 1.80 + is_element_visible(get_purchase_btn(items[0]), "Add-on 0 purchase button should be visible"); 1.81 + is(get_purchase_btn(items[0]).label, "Purchase for $101\u2026", "Add-on 0 should have the right price"); 1.82 + 1.83 + is(get_node(items[1], "name").value, "Cheap Add-on", "Add-on 1 should be in expected position"); 1.84 + is_element_hidden(get_install_btn(items[1]), "Add-on 1 install button should be hidden"); 1.85 + is_element_visible(get_purchase_btn(items[1]), "Add-on 1 purchase button should be visible"); 1.86 + is(get_purchase_btn(items[1]).label, "Purchase for $0.99\u2026", "Add-on 2 should have the right price"); 1.87 + 1.88 + is(get_node(items[2], "name").value, "Reasonable Add-on", "Add-on 2 should be in expected position"); 1.89 + is_element_hidden(get_install_btn(items[2]), "Add-on 2 install button should be hidden"); 1.90 + is_element_visible(get_purchase_btn(items[2]), "Add-on 2 purchase button should be visible"); 1.91 + is(get_purchase_btn(items[2]).label, "Purchase for $1\u2026", "Add-on 3 should have the right price"); 1.92 + 1.93 + is(get_node(items[3], "name").value, "Free Add-on", "Add-on 3 should be in expected position"); 1.94 + is_element_visible(get_install_btn(items[3]), "Add-on 3 install button should be visible"); 1.95 + is_element_hidden(get_purchase_btn(items[3]), "Add-on 3 purchase button should be hidden"); 1.96 + 1.97 + is(get_node(items[4], "name").value, "More Expensive Add-on", "Add-on 4 should be in expected position"); 1.98 + is_element_hidden(get_install_btn(items[4]), "Add-on 4 install button should be hidden"); 1.99 + is_element_visible(get_purchase_btn(items[4]), "Add-on 4 purchase button should be visible"); 1.100 + is(get_purchase_btn(items[4]).label, "Purchase for $1.01\u2026", "Add-on 4 should have the right price"); 1.101 + 1.102 + run_next_test(); 1.103 +}); 1.104 + 1.105 +// Tests that sorting by price works 1.106 +add_test(function() { 1.107 + var list = gManagerWindow.document.getElementById("search-list"); 1.108 + 1.109 + var sorters = gManagerWindow.document.getElementById("search-sorters"); 1.110 + var priceSorter = get_node(sorters, "price-btn"); 1.111 + info("Changing sort order"); 1.112 + EventUtils.synthesizeMouseAtCenter(priceSorter, { }, gManagerWindow); 1.113 + 1.114 + var items = Array.filter(list.childNodes, function(e) { 1.115 + return e.tagName == "richlistitem"; 1.116 + }); 1.117 + 1.118 + is(get_node(items[0], "name").value, "Free Add-on", "Add-on 0 should be in expected position"); 1.119 + is(get_node(items[1], "name").value, "Cheap Add-on", "Add-on 1 should be in expected position"); 1.120 + is(get_node(items[2], "name").value, "Reasonable Add-on", "Add-on 2 should be in expected position"); 1.121 + is(get_node(items[3], "name").value, "More Expensive Add-on", "Add-on 3 should be in expected position"); 1.122 + is(get_node(items[4], "name").value, "Ludicrously Expensive Add-on", "Add-on 4 should be in expected position"); 1.123 + 1.124 + info("Changing sort order"); 1.125 + EventUtils.synthesizeMouseAtCenter(priceSorter, { }, gManagerWindow); 1.126 + 1.127 + var items = Array.filter(list.childNodes, function(e) { 1.128 + return e.tagName == "richlistitem"; 1.129 + }); 1.130 + 1.131 + is(get_node(items[0], "name").value, "Ludicrously Expensive Add-on", "Add-on 0 should be in expected position"); 1.132 + is(get_node(items[1], "name").value, "More Expensive Add-on", "Add-on 1 should be in expected position"); 1.133 + is(get_node(items[2], "name").value, "Reasonable Add-on", "Add-on 2 should be in expected position"); 1.134 + is(get_node(items[3], "name").value, "Cheap Add-on", "Add-on 3 should be in expected position"); 1.135 + is(get_node(items[4], "name").value, "Free Add-on", "Add-on 4 should be in expected position"); 1.136 + 1.137 + run_next_test(); 1.138 +}); 1.139 + 1.140 +// Tests that clicking the buy button works from the list 1.141 +add_test(function() { 1.142 + gBrowser.addEventListener("load", function(event) { 1.143 + if (!(event.target instanceof Document) || 1.144 + event.target.location.href == "about:blank") 1.145 + return; 1.146 + gBrowser.removeEventListener("load", arguments.callee, true); 1.147 + 1.148 + is(gBrowser.currentURI.spec, TESTROOT + "releaseNotes.xhtml?addon5", "Should have loaded the right page"); 1.149 + 1.150 + gBrowser.removeCurrentTab(); 1.151 + 1.152 + if (gUseInContentUI) { 1.153 + is(gBrowser.currentURI.spec, "about:addons", "Should be back to the add-ons manager"); 1.154 + run_next_test(); 1.155 + } 1.156 + else { 1.157 + waitForFocus(run_next_test, gManagerWindow); 1.158 + } 1.159 + }, true); 1.160 + 1.161 + var list = gManagerWindow.document.getElementById("search-list"); 1.162 + EventUtils.synthesizeMouseAtCenter(get_purchase_btn(list.firstChild), { }, gManagerWindow); 1.163 +}); 1.164 + 1.165 +// Tests that clicking the buy button from the details view works 1.166 +add_test(function() { 1.167 + gBrowser.addEventListener("load", function(event) { 1.168 + if (!(event.target instanceof Document) || 1.169 + event.target.location.href == "about:blank") 1.170 + return; 1.171 + gBrowser.removeEventListener("load", arguments.callee, true); 1.172 + 1.173 + is(gBrowser.currentURI.spec, TESTROOT + "releaseNotes.xhtml?addon4", "Should have loaded the right page"); 1.174 + 1.175 + gBrowser.removeCurrentTab(); 1.176 + 1.177 + if (gUseInContentUI) { 1.178 + is(gBrowser.currentURI.spec, "about:addons", "Should be back to the add-ons manager"); 1.179 + run_next_test(); 1.180 + } 1.181 + else { 1.182 + waitForFocus(run_next_test, gManagerWindow); 1.183 + } 1.184 + }, true); 1.185 + 1.186 + var list = gManagerWindow.document.getElementById("search-list"); 1.187 + var item = list.firstChild.nextSibling; 1.188 + list.ensureElementIsVisible(item); 1.189 + EventUtils.synthesizeMouseAtCenter(item, { clickCount: 1 }, gManagerWindow); 1.190 + EventUtils.synthesizeMouseAtCenter(item, { clickCount: 2 }, gManagerWindow); 1.191 + 1.192 + wait_for_view_load(gManagerWindow, function() { 1.193 + var btn = gManagerWindow.document.getElementById("detail-purchase-btn"); 1.194 + is_element_visible(btn, "Purchase button should be visible"); 1.195 + 1.196 + EventUtils.synthesizeMouseAtCenter(btn, { }, gManagerWindow); 1.197 + }); 1.198 +});