1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_bug593535.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,119 @@ 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 +// Bug 593535 - Failure to download extension causes about:addons to list the 1.9 +// addon with no way to restart the download 1.10 + 1.11 +const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; 1.12 +const SEARCH_URL = TESTROOT + "browser_bug593535.xml"; 1.13 +const QUERY = "NOTFOUND"; 1.14 + 1.15 +var gProvider; 1.16 + 1.17 +function test() { 1.18 + return; 1.19 + waitForExplicitFinish(); 1.20 + 1.21 + // Turn on searching for this test 1.22 + Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15); 1.23 + 1.24 + open_manager("addons://list/extension", function(aWindow) { 1.25 + gManagerWindow = aWindow; 1.26 + run_next_test(); 1.27 + }); 1.28 +} 1.29 + 1.30 +function end_test() { 1.31 + close_manager(gManagerWindow, function() { 1.32 + AddonManager.getAllInstalls(function(aInstallsList) { 1.33 + for (var install of aInstallsList) { 1.34 + var sourceURI = install.sourceURI.spec; 1.35 + if (sourceURI.match(/^http:\/\/example\.com\/(.+)\.xpi$/) != null) 1.36 + install.cancel(); 1.37 + } 1.38 + 1.39 + finish(); 1.40 + }); 1.41 + }); 1.42 +} 1.43 + 1.44 +function search(aQuery, aCallback) { 1.45 + // Point search to the correct xml test file 1.46 + Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, SEARCH_URL); 1.47 + 1.48 + var searchBox = gManagerWindow.document.getElementById("header-search"); 1.49 + searchBox.value = aQuery; 1.50 + 1.51 + EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow); 1.52 + EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow); 1.53 + 1.54 + wait_for_view_load(gManagerWindow, function() { 1.55 + var remoteFilter = gManagerWindow.document.getElementById("search-filter-remote"); 1.56 + EventUtils.synthesizeMouseAtCenter(remoteFilter, { }, gManagerWindow); 1.57 + 1.58 + aCallback(); 1.59 + }); 1.60 +} 1.61 + 1.62 +function get_addon_item(aName) { 1.63 + var id = aName + "@tests.mozilla.org"; 1.64 + var list = gManagerWindow.document.getElementById("search-list"); 1.65 + var rows = list.getElementsByTagName("richlistitem"); 1.66 + for (let row of rows) { 1.67 + if (row.mAddon && row.mAddon.id == id) 1.68 + return row; 1.69 + } 1.70 + 1.71 + return null; 1.72 +} 1.73 + 1.74 +function get_install_button(aItem) { 1.75 + isnot(aItem, null, "Item should not be null when checking state of install button"); 1.76 + var installStatus = getAnonymousElementByAttribute(aItem, "anonid", "install-status"); 1.77 + return getAnonymousElementByAttribute(installStatus, "anonid", "install-remote-btn"); 1.78 +} 1.79 + 1.80 + 1.81 +function getAnonymousElementByAttribute(aElement, aName, aValue) { 1.82 + return gManagerWindow.document.getAnonymousElementByAttribute(aElement, 1.83 + aName, 1.84 + aValue); 1.85 +} 1.86 + 1.87 + 1.88 + 1.89 +// Tests that a failed install for a remote add-on will ask to retry the install 1.90 +add_test(function() { 1.91 + var remoteItem; 1.92 + 1.93 + var listener = { 1.94 + onDownloadFailed: function(aInstall) { 1.95 + aInstall.removeListener(this); 1.96 + ok(true, "Install failed as expected"); 1.97 + 1.98 + executeSoon(function() { 1.99 + is(remoteItem.getAttribute("notification"), "warning", "Item should have notification attribute set to 'warning'"); 1.100 + is_element_visible(remoteItem._warning, "Warning text should be visible"); 1.101 + is(remoteItem._warning.textContent, "There was an error downloading NOTFOUND.", "Warning should show correct message"); 1.102 + is_element_visible(remoteItem._warningLink, "Retry button should be visible"); 1.103 + run_next_test(); 1.104 + }); 1.105 + }, 1.106 + 1.107 + onInstallEnded: function() { 1.108 + ok(false, "Install should have failed"); 1.109 + } 1.110 + } 1.111 + 1.112 + search(QUERY, function() { 1.113 + var list = gManagerWindow.document.getElementById("search-list"); 1.114 + remoteItem = get_addon_item("notfound1"); 1.115 + list.ensureElementIsVisible(remoteItem); 1.116 + 1.117 + remoteItem.mAddon.install.addListener(listener); 1.118 + 1.119 + var installBtn = get_install_button(remoteItem); 1.120 + EventUtils.synthesizeMouseAtCenter(installBtn, { }, gManagerWindow); 1.121 + }); 1.122 +});