michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Tests that marketplace results show up in searches, are sorted right and michael@0: // attempting to buy links through to the right webpage michael@0: michael@0: const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; michael@0: const SEARCH_URL = TESTROOT + "browser_purchase.xml"; michael@0: michael@0: var gManagerWindow; michael@0: michael@0: function test() { michael@0: // Turn on searching for this test michael@0: Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15); michael@0: Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, SEARCH_URL); michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: open_manager("addons://list/extension", function(aWindow) { michael@0: gManagerWindow = aWindow; michael@0: michael@0: waitForFocus(function() { michael@0: var searchBox = gManagerWindow.document.getElementById("header-search"); michael@0: searchBox.value = "foo"; michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow); michael@0: EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow); michael@0: michael@0: wait_for_view_load(gManagerWindow, function() { michael@0: var remoteFilter = gManagerWindow.document.getElementById("search-filter-remote"); michael@0: EventUtils.synthesizeMouseAtCenter(remoteFilter, { }, gManagerWindow); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }, aWindow); michael@0: }); michael@0: } michael@0: michael@0: function end_test() { michael@0: close_manager(gManagerWindow, function() { michael@0: // Will have created an install so cancel it michael@0: AddonManager.getAllInstalls(function(aInstalls) { michael@0: is(aInstalls.length, 1, "Should have been one install created"); michael@0: aInstalls[0].cancel(); michael@0: michael@0: finish(); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function get_node(parent, anonid) { michael@0: return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid); michael@0: } michael@0: michael@0: function get_install_btn(parent) { michael@0: var installStatus = get_node(parent, "install-status"); michael@0: return get_node(installStatus, "install-remote-btn"); michael@0: } michael@0: michael@0: function get_purchase_btn(parent) { michael@0: var installStatus = get_node(parent, "install-status"); michael@0: return get_node(installStatus, "purchase-remote-btn"); michael@0: } michael@0: michael@0: // Tests that the expected results appeared michael@0: add_test(function() { michael@0: var list = gManagerWindow.document.getElementById("search-list"); michael@0: var items = Array.filter(list.childNodes, function(e) { michael@0: return e.tagName == "richlistitem"; michael@0: }); michael@0: michael@0: is(items.length, 5, "Should be 5 results"); michael@0: michael@0: is(get_node(items[0], "name").value, "Ludicrously Expensive Add-on", "Add-on 0 should be in expected position"); michael@0: is_element_hidden(get_install_btn(items[0]), "Add-on 0 install button should be hidden"); michael@0: is_element_visible(get_purchase_btn(items[0]), "Add-on 0 purchase button should be visible"); michael@0: is(get_purchase_btn(items[0]).label, "Purchase for $101\u2026", "Add-on 0 should have the right price"); michael@0: michael@0: is(get_node(items[1], "name").value, "Cheap Add-on", "Add-on 1 should be in expected position"); michael@0: is_element_hidden(get_install_btn(items[1]), "Add-on 1 install button should be hidden"); michael@0: is_element_visible(get_purchase_btn(items[1]), "Add-on 1 purchase button should be visible"); michael@0: is(get_purchase_btn(items[1]).label, "Purchase for $0.99\u2026", "Add-on 2 should have the right price"); michael@0: michael@0: is(get_node(items[2], "name").value, "Reasonable Add-on", "Add-on 2 should be in expected position"); michael@0: is_element_hidden(get_install_btn(items[2]), "Add-on 2 install button should be hidden"); michael@0: is_element_visible(get_purchase_btn(items[2]), "Add-on 2 purchase button should be visible"); michael@0: is(get_purchase_btn(items[2]).label, "Purchase for $1\u2026", "Add-on 3 should have the right price"); michael@0: michael@0: is(get_node(items[3], "name").value, "Free Add-on", "Add-on 3 should be in expected position"); michael@0: is_element_visible(get_install_btn(items[3]), "Add-on 3 install button should be visible"); michael@0: is_element_hidden(get_purchase_btn(items[3]), "Add-on 3 purchase button should be hidden"); michael@0: michael@0: is(get_node(items[4], "name").value, "More Expensive Add-on", "Add-on 4 should be in expected position"); michael@0: is_element_hidden(get_install_btn(items[4]), "Add-on 4 install button should be hidden"); michael@0: is_element_visible(get_purchase_btn(items[4]), "Add-on 4 purchase button should be visible"); michael@0: is(get_purchase_btn(items[4]).label, "Purchase for $1.01\u2026", "Add-on 4 should have the right price"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // Tests that sorting by price works michael@0: add_test(function() { michael@0: var list = gManagerWindow.document.getElementById("search-list"); michael@0: michael@0: var sorters = gManagerWindow.document.getElementById("search-sorters"); michael@0: var priceSorter = get_node(sorters, "price-btn"); michael@0: info("Changing sort order"); michael@0: EventUtils.synthesizeMouseAtCenter(priceSorter, { }, gManagerWindow); michael@0: michael@0: var items = Array.filter(list.childNodes, function(e) { michael@0: return e.tagName == "richlistitem"; michael@0: }); michael@0: michael@0: is(get_node(items[0], "name").value, "Free Add-on", "Add-on 0 should be in expected position"); michael@0: is(get_node(items[1], "name").value, "Cheap Add-on", "Add-on 1 should be in expected position"); michael@0: is(get_node(items[2], "name").value, "Reasonable Add-on", "Add-on 2 should be in expected position"); michael@0: is(get_node(items[3], "name").value, "More Expensive Add-on", "Add-on 3 should be in expected position"); michael@0: is(get_node(items[4], "name").value, "Ludicrously Expensive Add-on", "Add-on 4 should be in expected position"); michael@0: michael@0: info("Changing sort order"); michael@0: EventUtils.synthesizeMouseAtCenter(priceSorter, { }, gManagerWindow); michael@0: michael@0: var items = Array.filter(list.childNodes, function(e) { michael@0: return e.tagName == "richlistitem"; michael@0: }); michael@0: michael@0: is(get_node(items[0], "name").value, "Ludicrously Expensive Add-on", "Add-on 0 should be in expected position"); michael@0: is(get_node(items[1], "name").value, "More Expensive Add-on", "Add-on 1 should be in expected position"); michael@0: is(get_node(items[2], "name").value, "Reasonable Add-on", "Add-on 2 should be in expected position"); michael@0: is(get_node(items[3], "name").value, "Cheap Add-on", "Add-on 3 should be in expected position"); michael@0: is(get_node(items[4], "name").value, "Free Add-on", "Add-on 4 should be in expected position"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // Tests that clicking the buy button works from the list michael@0: add_test(function() { michael@0: gBrowser.addEventListener("load", function(event) { michael@0: if (!(event.target instanceof Document) || michael@0: event.target.location.href == "about:blank") michael@0: return; michael@0: gBrowser.removeEventListener("load", arguments.callee, true); michael@0: michael@0: is(gBrowser.currentURI.spec, TESTROOT + "releaseNotes.xhtml?addon5", "Should have loaded the right page"); michael@0: michael@0: gBrowser.removeCurrentTab(); michael@0: michael@0: if (gUseInContentUI) { michael@0: is(gBrowser.currentURI.spec, "about:addons", "Should be back to the add-ons manager"); michael@0: run_next_test(); michael@0: } michael@0: else { michael@0: waitForFocus(run_next_test, gManagerWindow); michael@0: } michael@0: }, true); michael@0: michael@0: var list = gManagerWindow.document.getElementById("search-list"); michael@0: EventUtils.synthesizeMouseAtCenter(get_purchase_btn(list.firstChild), { }, gManagerWindow); michael@0: }); michael@0: michael@0: // Tests that clicking the buy button from the details view works michael@0: add_test(function() { michael@0: gBrowser.addEventListener("load", function(event) { michael@0: if (!(event.target instanceof Document) || michael@0: event.target.location.href == "about:blank") michael@0: return; michael@0: gBrowser.removeEventListener("load", arguments.callee, true); michael@0: michael@0: is(gBrowser.currentURI.spec, TESTROOT + "releaseNotes.xhtml?addon4", "Should have loaded the right page"); michael@0: michael@0: gBrowser.removeCurrentTab(); michael@0: michael@0: if (gUseInContentUI) { michael@0: is(gBrowser.currentURI.spec, "about:addons", "Should be back to the add-ons manager"); michael@0: run_next_test(); michael@0: } michael@0: else { michael@0: waitForFocus(run_next_test, gManagerWindow); michael@0: } michael@0: }, true); michael@0: michael@0: var list = gManagerWindow.document.getElementById("search-list"); michael@0: var item = list.firstChild.nextSibling; michael@0: list.ensureElementIsVisible(item); michael@0: EventUtils.synthesizeMouseAtCenter(item, { clickCount: 1 }, gManagerWindow); michael@0: EventUtils.synthesizeMouseAtCenter(item, { clickCount: 2 }, gManagerWindow); michael@0: michael@0: wait_for_view_load(gManagerWindow, function() { michael@0: var btn = gManagerWindow.document.getElementById("detail-purchase-btn"); michael@0: is_element_visible(btn, "Purchase button should be visible"); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(btn, { }, gManagerWindow); michael@0: }); michael@0: });