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.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
5 // Bug 593535 - Failure to download extension causes about:addons to list the
6 // addon with no way to restart the download
8 const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url";
9 const SEARCH_URL = TESTROOT + "browser_bug593535.xml";
10 const QUERY = "NOTFOUND";
12 var gProvider;
14 function test() {
15 return;
16 waitForExplicitFinish();
18 // Turn on searching for this test
19 Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15);
21 open_manager("addons://list/extension", function(aWindow) {
22 gManagerWindow = aWindow;
23 run_next_test();
24 });
25 }
27 function end_test() {
28 close_manager(gManagerWindow, function() {
29 AddonManager.getAllInstalls(function(aInstallsList) {
30 for (var install of aInstallsList) {
31 var sourceURI = install.sourceURI.spec;
32 if (sourceURI.match(/^http:\/\/example\.com\/(.+)\.xpi$/) != null)
33 install.cancel();
34 }
36 finish();
37 });
38 });
39 }
41 function search(aQuery, aCallback) {
42 // Point search to the correct xml test file
43 Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, SEARCH_URL);
45 var searchBox = gManagerWindow.document.getElementById("header-search");
46 searchBox.value = aQuery;
48 EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
49 EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
51 wait_for_view_load(gManagerWindow, function() {
52 var remoteFilter = gManagerWindow.document.getElementById("search-filter-remote");
53 EventUtils.synthesizeMouseAtCenter(remoteFilter, { }, gManagerWindow);
55 aCallback();
56 });
57 }
59 function get_addon_item(aName) {
60 var id = aName + "@tests.mozilla.org";
61 var list = gManagerWindow.document.getElementById("search-list");
62 var rows = list.getElementsByTagName("richlistitem");
63 for (let row of rows) {
64 if (row.mAddon && row.mAddon.id == id)
65 return row;
66 }
68 return null;
69 }
71 function get_install_button(aItem) {
72 isnot(aItem, null, "Item should not be null when checking state of install button");
73 var installStatus = getAnonymousElementByAttribute(aItem, "anonid", "install-status");
74 return getAnonymousElementByAttribute(installStatus, "anonid", "install-remote-btn");
75 }
78 function getAnonymousElementByAttribute(aElement, aName, aValue) {
79 return gManagerWindow.document.getAnonymousElementByAttribute(aElement,
80 aName,
81 aValue);
82 }
86 // Tests that a failed install for a remote add-on will ask to retry the install
87 add_test(function() {
88 var remoteItem;
90 var listener = {
91 onDownloadFailed: function(aInstall) {
92 aInstall.removeListener(this);
93 ok(true, "Install failed as expected");
95 executeSoon(function() {
96 is(remoteItem.getAttribute("notification"), "warning", "Item should have notification attribute set to 'warning'");
97 is_element_visible(remoteItem._warning, "Warning text should be visible");
98 is(remoteItem._warning.textContent, "There was an error downloading NOTFOUND.", "Warning should show correct message");
99 is_element_visible(remoteItem._warningLink, "Retry button should be visible");
100 run_next_test();
101 });
102 },
104 onInstallEnded: function() {
105 ok(false, "Install should have failed");
106 }
107 }
109 search(QUERY, function() {
110 var list = gManagerWindow.document.getElementById("search-list");
111 remoteItem = get_addon_item("notfound1");
112 list.ensureElementIsVisible(remoteItem);
114 remoteItem.mAddon.install.addListener(listener);
116 var installBtn = get_install_button(remoteItem);
117 EventUtils.synthesizeMouseAtCenter(installBtn, { }, gManagerWindow);
118 });
119 });