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: // Bug 593535 - Failure to download extension causes about:addons to list the michael@0: // addon with no way to restart the download michael@0: michael@0: const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; michael@0: const SEARCH_URL = TESTROOT + "browser_bug593535.xml"; michael@0: const QUERY = "NOTFOUND"; michael@0: michael@0: var gProvider; michael@0: michael@0: function test() { michael@0: return; michael@0: waitForExplicitFinish(); michael@0: michael@0: // Turn on searching for this test michael@0: Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15); michael@0: michael@0: open_manager("addons://list/extension", function(aWindow) { michael@0: gManagerWindow = aWindow; michael@0: run_next_test(); michael@0: }); michael@0: } michael@0: michael@0: function end_test() { michael@0: close_manager(gManagerWindow, function() { michael@0: AddonManager.getAllInstalls(function(aInstallsList) { michael@0: for (var install of aInstallsList) { michael@0: var sourceURI = install.sourceURI.spec; michael@0: if (sourceURI.match(/^http:\/\/example\.com\/(.+)\.xpi$/) != null) michael@0: install.cancel(); michael@0: } michael@0: michael@0: finish(); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function search(aQuery, aCallback) { michael@0: // Point search to the correct xml test file michael@0: Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, SEARCH_URL); michael@0: michael@0: var searchBox = gManagerWindow.document.getElementById("header-search"); michael@0: searchBox.value = aQuery; 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: aCallback(); michael@0: }); michael@0: } michael@0: michael@0: function get_addon_item(aName) { michael@0: var id = aName + "@tests.mozilla.org"; michael@0: var list = gManagerWindow.document.getElementById("search-list"); michael@0: var rows = list.getElementsByTagName("richlistitem"); michael@0: for (let row of rows) { michael@0: if (row.mAddon && row.mAddon.id == id) michael@0: return row; michael@0: } michael@0: michael@0: return null; michael@0: } michael@0: michael@0: function get_install_button(aItem) { michael@0: isnot(aItem, null, "Item should not be null when checking state of install button"); michael@0: var installStatus = getAnonymousElementByAttribute(aItem, "anonid", "install-status"); michael@0: return getAnonymousElementByAttribute(installStatus, "anonid", "install-remote-btn"); michael@0: } michael@0: michael@0: michael@0: function getAnonymousElementByAttribute(aElement, aName, aValue) { michael@0: return gManagerWindow.document.getAnonymousElementByAttribute(aElement, michael@0: aName, michael@0: aValue); michael@0: } michael@0: michael@0: michael@0: michael@0: // Tests that a failed install for a remote add-on will ask to retry the install michael@0: add_test(function() { michael@0: var remoteItem; michael@0: michael@0: var listener = { michael@0: onDownloadFailed: function(aInstall) { michael@0: aInstall.removeListener(this); michael@0: ok(true, "Install failed as expected"); michael@0: michael@0: executeSoon(function() { michael@0: is(remoteItem.getAttribute("notification"), "warning", "Item should have notification attribute set to 'warning'"); michael@0: is_element_visible(remoteItem._warning, "Warning text should be visible"); michael@0: is(remoteItem._warning.textContent, "There was an error downloading NOTFOUND.", "Warning should show correct message"); michael@0: is_element_visible(remoteItem._warningLink, "Retry button should be visible"); michael@0: run_next_test(); michael@0: }); michael@0: }, michael@0: michael@0: onInstallEnded: function() { michael@0: ok(false, "Install should have failed"); michael@0: } michael@0: } michael@0: michael@0: search(QUERY, function() { michael@0: var list = gManagerWindow.document.getElementById("search-list"); michael@0: remoteItem = get_addon_item("notfound1"); michael@0: list.ensureElementIsVisible(remoteItem); michael@0: michael@0: remoteItem.mAddon.install.addListener(listener); michael@0: michael@0: var installBtn = get_install_button(remoteItem); michael@0: EventUtils.synthesizeMouseAtCenter(installBtn, { }, gManagerWindow); michael@0: }); michael@0: });