|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Bug 593535 - Failure to download extension causes about:addons to list the |
|
6 // addon with no way to restart the download |
|
7 |
|
8 const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; |
|
9 const SEARCH_URL = TESTROOT + "browser_bug593535.xml"; |
|
10 const QUERY = "NOTFOUND"; |
|
11 |
|
12 var gProvider; |
|
13 |
|
14 function test() { |
|
15 return; |
|
16 waitForExplicitFinish(); |
|
17 |
|
18 // Turn on searching for this test |
|
19 Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15); |
|
20 |
|
21 open_manager("addons://list/extension", function(aWindow) { |
|
22 gManagerWindow = aWindow; |
|
23 run_next_test(); |
|
24 }); |
|
25 } |
|
26 |
|
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 } |
|
35 |
|
36 finish(); |
|
37 }); |
|
38 }); |
|
39 } |
|
40 |
|
41 function search(aQuery, aCallback) { |
|
42 // Point search to the correct xml test file |
|
43 Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, SEARCH_URL); |
|
44 |
|
45 var searchBox = gManagerWindow.document.getElementById("header-search"); |
|
46 searchBox.value = aQuery; |
|
47 |
|
48 EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow); |
|
49 EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow); |
|
50 |
|
51 wait_for_view_load(gManagerWindow, function() { |
|
52 var remoteFilter = gManagerWindow.document.getElementById("search-filter-remote"); |
|
53 EventUtils.synthesizeMouseAtCenter(remoteFilter, { }, gManagerWindow); |
|
54 |
|
55 aCallback(); |
|
56 }); |
|
57 } |
|
58 |
|
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 } |
|
67 |
|
68 return null; |
|
69 } |
|
70 |
|
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 } |
|
76 |
|
77 |
|
78 function getAnonymousElementByAttribute(aElement, aName, aValue) { |
|
79 return gManagerWindow.document.getAnonymousElementByAttribute(aElement, |
|
80 aName, |
|
81 aValue); |
|
82 } |
|
83 |
|
84 |
|
85 |
|
86 // Tests that a failed install for a remote add-on will ask to retry the install |
|
87 add_test(function() { |
|
88 var remoteItem; |
|
89 |
|
90 var listener = { |
|
91 onDownloadFailed: function(aInstall) { |
|
92 aInstall.removeListener(this); |
|
93 ok(true, "Install failed as expected"); |
|
94 |
|
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 }, |
|
103 |
|
104 onInstallEnded: function() { |
|
105 ok(false, "Install should have failed"); |
|
106 } |
|
107 } |
|
108 |
|
109 search(QUERY, function() { |
|
110 var list = gManagerWindow.document.getElementById("search-list"); |
|
111 remoteItem = get_addon_item("notfound1"); |
|
112 list.ensureElementIsVisible(remoteItem); |
|
113 |
|
114 remoteItem.mAddon.install.addListener(listener); |
|
115 |
|
116 var installBtn = get_install_button(remoteItem); |
|
117 EventUtils.synthesizeMouseAtCenter(installBtn, { }, gManagerWindow); |
|
118 }); |
|
119 }); |