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