toolkit/mozapps/extensions/test/browser/browser_bug593535.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial