Bug 596336: Update the UI with the new add-on details when bootstrapped add-ons are upgraded. r=Unfocused, a=blocks-betaN

This commit is contained in:
Dave Townsend 2010-10-18 11:11:05 -07:00
Родитель d7b9ee3bef
Коммит e337f1b9e0
10 изменённых файлов: 510 добавлений и 70 удалений

Просмотреть файл

@ -310,12 +310,11 @@ var gEventManager = {
},
delegateInstallEvent: function(aEvent, aParams) {
var install = aParams[0];
if (install.existingAddon) {
// install is an update
let addon = install.existingAddon;
this.delegateAddonEvent(aEvent, [addon].concat(aParams));
}
var existingAddon = aEvent == "onExternalInstall" ? aParams[1] : aParams[0].existingAddon;
// If the install is an update then send the event to all listeners
// registered for the existing add-on
if (existingAddon)
this.delegateAddonEvent(aEvent, [existingAddon].concat(aParams));
for (let i = 0; i < this._installListeners.length; i++) {
let listener = this._installListeners[i];
@ -1800,6 +1799,10 @@ var gListView = {
if (this._types.indexOf(aAddon.type) == -1)
return;
// The existing list item will take care of upgrade installs
if (aExistingAddon)
return;
var item = createItem(aAddon, false);
this._listBox.insertBefore(item, this._listBox.firstChild);
},
@ -1885,8 +1888,7 @@ var gDetailView = {
this._addon = aAddon;
gEventManager.registerAddonListener(this, aAddon.id);
if (aAddon.install)
gEventManager.registerInstallListener(this);
gEventManager.registerInstallListener(this);
this.node.setAttribute("type", aAddon.type);
@ -2187,6 +2189,17 @@ var gDetailView = {
}
},
onExternalInstall: function(aAddon, aExistingAddon, aNeedsRestart) {
// Only care about upgrades for the currently displayed add-on
if (!aExistingAddon || aExistingAddon.id != this._addon.id)
return;
if (!aNeedsRestart)
this._updateView(aAddon, false);
else
this.updateState();
},
onInstallCancelled: function(aInstall) {
if (aInstall.addon.id == this._addon.id)
gViewController.popState();

Просмотреть файл

@ -844,50 +844,12 @@
<implementation>
<constructor><![CDATA[
this._installStatus.mControl = this;
this._installStatus.mAddon = this.mAddon;
this.setAttribute("contextmenu", "addonitem-popup");
this._showStatus("none");
this._updateDates();
this._updateState();
var iconURL = this.mAddon.iconURL;
if (iconURL)
this._icon.src = iconURL;
if (this.mAddon.version)
this._version.value = this.mAddon.version;
else
this._version.hidden = true;
this._creator.setCreator(this.mAddon.creator);
if (this.mAddon.description)
this._description.value = this.mAddon.description;
else
this._description.hidden = true;
if (this.mAddon.applyBackgroundUpdates == AddonManager.AUTOUPDATE_DISABLE ||
(this.mAddon.applyBackgroundUpdates == AddonManager.AUTOUPDATE_DEFAULT &&
!AddonManager.autoUpdateDefault)) {
var self = this;
AddonManager.getAllInstalls(function(aInstallsList) {
// This can return after the binding has been destroyed,
// so try to detect that and return early
if (!("onNewInstall" in self))
return;
for (let i = 0; i < aInstallsList.length; i++) {
let install = aInstallsList[i];
if (install.existingAddon &&
install.existingAddon.id == self.mAddon.id &&
install.state == AddonManager.STATE_AVAILABLE) {
self.onNewInstall(install);
self.onIncludeUpdateChanged();
}
}
});
}
this._initWithAddon(this.mAddon);
gEventManager.registerAddonListener(this, this.mAddon.id);
]]></constructor>
@ -1036,6 +998,63 @@
]]></setter>
</property>
<method name="_initWithAddon">
<parameter name="aAddon"/>
<body><![CDATA[
this.mAddon = aAddon;
this._installStatus.mAddon = this.mAddon;
this._updateDates();
this._updateState();
this.setAttribute("name", aAddon.name);
if (aAddon.size)
this.setAttribute("size", aAddon.size);
else
this.removeAttribute("size");
var iconURL = this.mAddon.iconURL;
if (iconURL)
this._icon.src = iconURL;
else
this._icon.src = null;
if (this.mAddon.version)
this._version.value = this.mAddon.version;
else
this._version.hidden = true;
this._creator.setCreator(this.mAddon.creator);
if (this.mAddon.description)
this._description.value = this.mAddon.description;
else
this._description.hidden = true;
if (this.mAddon.applyBackgroundUpdates == AddonManager.AUTOUPDATE_DISABLE ||
(this.mAddon.applyBackgroundUpdates == AddonManager.AUTOUPDATE_DEFAULT &&
!AddonManager.autoUpdateDefault)) {
var self = this;
AddonManager.getAllInstalls(function(aInstallsList) {
// This can return after the binding has been destroyed,
// so try to detect that and return early
if (!("onNewInstall" in self))
return;
for (let i = 0; i < aInstallsList.length; i++) {
let install = aInstallsList[i];
if (install.existingAddon &&
install.existingAddon.id == self.mAddon.id &&
install.state == AddonManager.STATE_AVAILABLE) {
self.onNewInstall(install);
self.onIncludeUpdateChanged();
}
}
});
}
]]></body>
</method>
<method name="_showStatus">
<parameter name="aType"/>
<body><![CDATA[
@ -1066,10 +1085,13 @@
);
}
if (this.mAddon.updateDate)
if (this.mAddon.updateDate) {
this._dateUpdated.value = formatDate(this.mAddon.updateDate);
else
this.setAttribute("dateUpdated", this.mAddon.updateDate.getTime() / 1000);
} else {
this._dateUpdated.value = this._dateUpdated.getAttribute("unknown");
this.removeAttribute("dateUpdated");
}
]]></body>
</method>
@ -1412,6 +1434,23 @@
]]></body>
</method>
<method name="onExternalInstall">
<parameter name="aAddon"/>
<parameter name="aExistingAddon"/>
<parameter name="aNeedsRestart"/>
<body><![CDATA[
if (aExistingAddon.id != this.mAddon.id)
return;
// If the install completed without needing a restart then switch to
// using the new Addon
if (!aNeedsRestart)
this._initWithAddon(aAddon);
else
this._updateState();
]]></body>
</method>
<method name="onNewInstall">
<parameter name="aInstall"/>
<body><![CDATA[
@ -1444,8 +1483,15 @@
</method>
<method name="onInstallEnded">
<parameter name="aInstall"/>
<parameter name="aAddon"/>
<body><![CDATA[
this._updateState();
// If the install completed without needing a restart then switch to
// using the new Addon
if (!(aAddon.pendingOperations & AddonManager.PENDING_INSTALL))
this._initWithAddon(aAddon);
else
this._updateState();
]]></body>
</method>
</implementation>
@ -1459,7 +1505,6 @@
<!-- Addon - uninstalled - An uninstalled addon that can be re-installed. -->
<!-- XXXunf this doesn't take into account restart-less uninstalls. bug 561263 -->
<binding id="addon-uninstalled"
extends="chrome://mozapps/content/extensions/extensions.xml#addon-base">
<content>
@ -1522,6 +1567,51 @@
this.removeAttribute("pending");
]]></body>
</method>
<method name="onExternalInstall">
<parameter name="aAddon"/>
<parameter name="aExistingAddon"/>
<parameter name="aNeedsRestart"/>
<body><![CDATA[
if (aExistingAddon.id != this.mAddon.id)
return;
// Make sure any newly installed add-on has the correct disabled state
if (this.hasAttribute("wasDisabled"))
aAddon.userDisabled = this.getAttribute("wasDisabled") == "true";
// If the install completed without needing a restart then switch to
// using the new Addon
if (!aNeedsRestart)
this.mAddon = aAddon;
this.removeAttribute("restartrequired");
this.removeAttribute("pending");
]]></body>
</method>
<method name="onInstallStarted">
<parameter name="aInstall"/>
<body><![CDATA[
// Make sure any newly installed add-on has the correct disabled state
if (this.hasAttribute("wasDisabled"))
aInstall.addon.userDisabled = this.getAttribute("wasDisabled") == "true";
]]></body>
</method>
<method name="onInstallEnded">
<parameter name="aInstall"/>
<parameter name="aAddon"/>
<body><![CDATA[
// If the install completed without needing a restart then switch to
// using the new Addon
if (!(aAddon.pendingOperations & AddonManager.PENDING_INSTALL))
this.mAddon = aAddon;
this.removeAttribute("restartrequired");
this.removeAttribute("pending");
]]></body>
</method>
</implementation>
</binding>

Просмотреть файл

@ -64,6 +64,7 @@ _TEST_FILES = \
browser_bug587970.js \
browser_bug591465.js \
browser_bug591465.xml \
browser_bug596336.js \
browser_details.js \
browser_discovery.js \
browser_dragdrop.js \

Просмотреть файл

@ -0,0 +1,23 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>addon1@tests.mozilla.org</em:id>
<em:version>1.0</em:version>
<em:bootstrap>true</em:bootstrap>
<em:targetApplication>
<Description>
<em:id>toolkit@mozilla.org</em:id>
<em:minVersion>0</em:minVersion>
<em:maxVersion>*</em:maxVersion>
</Description>
</em:targetApplication>
<!-- Front End MetaData -->
<em:name>Bootstrap upgrade test</em:name>
</Description>
</RDF>

Просмотреть файл

@ -0,0 +1,23 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>addon1@tests.mozilla.org</em:id>
<em:version>2.0</em:version>
<em:bootstrap>true</em:bootstrap>
<em:targetApplication>
<Description>
<em:id>toolkit@mozilla.org</em:id>
<em:minVersion>0</em:minVersion>
<em:maxVersion>*</em:maxVersion>
</Description>
</em:targetApplication>
<!-- Front End MetaData -->
<em:name>Bootstrap upgrade test</em:name>
</Description>
</RDF>

Просмотреть файл

@ -0,0 +1,184 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// Tests that upgrading bootstrapped add-ons behaves correctly while the
// manager is open
var gManagerWindow;
var gCategoryUtilities;
function test() {
waitForExplicitFinish();
open_manager("addons://list/extension", function(aWindow) {
gManagerWindow = aWindow;
gCategoryUtilities = new CategoryUtilities(gManagerWindow);
run_next_test();
});
}
function end_test() {
close_manager(gManagerWindow, function() {
finish();
});
}
function get_list_item_count() {
return get_test_items_in_list(gManagerWindow).length;
}
function get_node(parent, anonid) {
return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid);
}
function get_class_node(parent, cls) {
return parent.ownerDocument.getAnonymousElementByAttribute(parent, "class", cls);
}
function install_addon(aXpi, aCallback) {
AddonManager.getInstallForURL(TESTROOT + "addons/" + aXpi + ".xpi",
function(aInstall) {
aInstall.addListener({
onInstallEnded: function(aInstall) {
executeSoon(aCallback);
}
});
aInstall.install();
}, "application/x-xpinstall");
}
function check_addon(aAddon, version) {
is(get_list_item_count(), 1, "Should be one item in the list");
is(aAddon.version, version, "Add-on should have the right version");
let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
ok(!!item, "Should see the add-on in the list");
// Force XBL to apply
item.clientTop;
is(get_node(item, "version").value, version, "Version should be correct");
if (aAddon.userDisabled)
is_element_visible(get_class_node(item, "disabled-postfix"), "Disabled postfix should be hidden");
else
is_element_hidden(get_class_node(item, "disabled-postfix"), "Disabled postfix should be hidden");
}
// Install version 1 then upgrade to version 2 with the manager open
add_test(function() {
install_addon("browser_bug596336_1", function() {
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
check_addon(aAddon, "1.0");
ok(!aAddon.userDisabled, "Add-on should not be disabled");
install_addon("browser_bug596336_2", function() {
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
check_addon(aAddon, "2.0");
ok(!aAddon.userDisabled, "Add-on should not be disabled");
aAddon.uninstall();
is(get_list_item_count(), 0, "Should be no items in the list");
run_next_test();
});
});
});
});
});
// Install version 1 mark it as disabled then upgrade to version 2 with the
// manager open
add_test(function() {
install_addon("browser_bug596336_1", function() {
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
aAddon.userDisabled = true;
check_addon(aAddon, "1.0");
ok(aAddon.userDisabled, "Add-on should be disabled");
install_addon("browser_bug596336_2", function() {
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
check_addon(aAddon, "2.0");
ok(aAddon.userDisabled, "Add-on should be disabled");
aAddon.uninstall();
is(get_list_item_count(), 0, "Should be no items in the list");
run_next_test();
});
});
});
});
});
// Install version 1 click the remove button and then upgrade to version 2 with
// the manager open
add_test(function() {
install_addon("browser_bug596336_1", function() {
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
check_addon(aAddon, "1.0");
ok(!aAddon.userDisabled, "Add-on should not be disabled");
let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
EventUtils.synthesizeMouseAtCenter(get_node(item, "remove-btn"), { }, gManagerWindow);
// Force XBL to apply
item.clientTop;
ok(aAddon.userDisabled, "Add-on should be disabled");
ok(!aAddon.pendingUninstall, "Add-on should not be pending uninstall");
is_element_visible(get_class_node(item, "pending"), "Pending message should be visible");
install_addon("browser_bug596336_2", function() {
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
check_addon(aAddon, "2.0");
ok(!aAddon.userDisabled, "Add-on should not be disabled");
aAddon.uninstall();
is(get_list_item_count(), 0, "Should be no items in the list");
run_next_test();
});
});
});
});
});
// Install version 1, disable it, click the remove button and then upgrade to
// version 2 with the manager open
add_test(function() {
install_addon("browser_bug596336_1", function() {
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
aAddon.userDisabled = true;
check_addon(aAddon, "1.0");
ok(aAddon.userDisabled, "Add-on should be disabled");
let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
EventUtils.synthesizeMouseAtCenter(get_node(item, "remove-btn"), { }, gManagerWindow);
// Force XBL to apply
item.clientTop;
ok(aAddon.userDisabled, "Add-on should be disabled");
ok(!aAddon.pendingUninstall, "Add-on should not be pending uninstall");
is_element_visible(get_class_node(item, "pending"), "Pending message should be visible");
install_addon("browser_bug596336_2", function() {
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
check_addon(aAddon, "2.0");
ok(aAddon.userDisabled, "Add-on should be disabled");
aAddon.uninstall();
is(get_list_item_count(), 0, "Should be no items in the list");
run_next_test();
});
});
});
});
});

Просмотреть файл

@ -639,3 +639,59 @@ add_test(function() {
});
});
});
// Tests that upgrades with onExternalInstall apply immediately
add_test(function() {
open_details("addon1@tests.mozilla.org", "extension", function() {
gProvider.createAddons([{
id: "addon1@tests.mozilla.org",
name: "Test add-on replacement",
version: "2.5",
description: "Short description replacement",
fullDescription: "Longer description replacement",
type: "extension",
iconURL: "chrome://foo/skin/icon.png",
icon64URL: "chrome://foo/skin/icon264.png",
sourceURI: Services.io.newURI("http://example.com/foo", null, null),
averageRating: 2,
optionsURL: "chrome://foo/content/options.xul",
applyBackgroundUpdates: AddonManager.AUTOUPDATE_ENABLE,
operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
}]);
is(get("detail-name").textContent, "Test add-on replacement", "Name should be correct");
is_element_visible(get("detail-version"), "Version should not be hidden");
is(get("detail-version").value, "2.5", "Version should be correct");
is(get("detail-icon").src, "chrome://foo/skin/icon264.png", "Icon should be correct");
is_element_hidden(get("detail-creator"), "Creator should be hidden");
is_element_hidden(get("detail-screenshot"), "Screenshot should be hidden");
is(get("detail-desc").textContent, "Longer description replacement", "Description should be correct");
is_element_hidden(get("detail-contributions"), "Contributions section should be hidden");
is_element_hidden(get("detail-dateUpdated"), "Update date should be hidden");
is_element_visible(get("detail-rating-row"), "Rating row should not be hidden");
is_element_visible(get("detail-rating"), "Rating should not be hidden");
is(get("detail-rating").averageRating, 2, "Rating should be correct");
is_element_hidden(get("detail-reviews"), "Reviews should be hidden");
is_element_hidden(get("detail-homepage-row"), "Homepage should be hidden");
is_element_hidden(get("detail-size"), "Size should be hidden");
is_element_hidden(get("detail-downloads"), "Downloads should be hidden");
is_element_visible(get("detail-prefs-btn"), "Preferences button should be visible");
is_element_hidden(get("detail-enable-btn"), "Enable button should be hidden");
is_element_visible(get("detail-disable-btn"), "Disable button should be visible");
is_element_visible(get("detail-uninstall-btn"), "Remove button should be visible");
is_element_hidden(get("detail-warning"), "Warning message should be hidden");
is_element_hidden(get("detail-warning-link"), "Warning link should be hidden");
is_element_hidden(get("detail-error"), "Error message should be hidden");
is_element_hidden(get("detail-pending"), "Pending message should be hidden");
run_next_test();
});
});

Просмотреть файл

@ -116,24 +116,7 @@ function installSearchResult(aCallback) {
}
function get_list_item_count() {
var tests = "@tests.mozilla.org";
let view = gManagerWindow.document.getElementById("view-port").selectedPanel;
let listid = view.id == "search-view" ? "search-list" : "addon-list";
let item = gManagerWindow.document.getElementById(listid).firstChild;
let count = 0;
while (item) {
if (!item.mAddon || item.mAddon.id.substring(item.mAddon.id.length - tests.length) == tests)
count++;
item = item.nextSibling;
}
// Remove the show all results item
if (view.id == "search-view")
count--;
return count;
return get_test_items_in_list(gManagerWindow).length;
}
function check_undo_install() {

Просмотреть файл

@ -536,3 +536,43 @@ add_test(function() {
run_next_test();
});
});
// Check that upgrades with onExternalInstall take effect immediately
add_test(function() {
gProvider.createAddons([{
id: "addon1@tests.mozilla.org",
name: "Test add-on replacement",
version: "2.0",
description: "A test add-on with a new description",
updateDate: gDate,
operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
}]);
let items = get_test_items();
is(items.length, 7, "Should be seven add-ons installed");
let addon = items[0];
addon.parentNode.ensureElementIsVisible(addon);
is(get_node(addon, "name").value, "Test add-on replacement", "Name should be correct");
is_element_visible(get_node(addon, "version"), "Version should be visible");
is(get_node(addon, "version").value, "2.0", "Version should be correct");
is_element_visible(get_node(addon, "description"), "Description should be visible");
is(get_node(addon, "description").value, "A test add-on with a new description", "Description should be correct");
is_element_hidden(get_node(addon, "creator"), "Creator should be hidden");
is_element_hidden(get_class_node(addon, "disabled-postfix"), "Disabled postfix should be hidden");
is_element_hidden(get_class_node(addon, "update-postfix"), "Update postfix should be hidden");
is(Date.parse(get_node(addon, "date-updated").value), gDate.getTime(), "Update date should be correct");
is_element_hidden(get_node(addon, "preferences-btn"), "Preferences button should be hidden");
is_element_hidden(get_node(addon, "enable-btn"), "Enable button should be hidden");
is_element_visible(get_node(addon, "disable-btn"), "Disable button should be visible");
is_element_visible(get_node(addon, "remove-btn"), "Remove button should be visible");
is_element_hidden(get_node(addon, "warning"), "Warning message should be hidden");
is_element_hidden(get_node(addon, "warning-link"), "Warning link should be hidden");
is_element_hidden(get_node(addon, "error"), "Error message should be hidden");
is_element_hidden(get_node(addon, "error-link"), "Error link should be hidden");
is_element_hidden(get_node(addon, "pending"), "Pending message should be hidden");
run_next_test();
});

Просмотреть файл

@ -85,6 +85,28 @@ function get_addon_file_url(aFilename) {
}
}
function get_test_items_in_list(aManager) {
var tests = "@tests.mozilla.org";
let view = aManager.document.getElementById("view-port").selectedPanel;
let listid = view.id == "search-view" ? "search-list" : "addon-list";
let item = aManager.document.getElementById(listid).firstChild;
let items = [];
while (item) {
if (item.localName != "richlistitem") {
item = item.nextSibling;
continue;
}
if (!item.mAddon || item.mAddon.id.substring(item.mAddon.id.length - tests.length) == tests)
items.push(item);
item = item.nextSibling;
}
return items;
}
function check_all_in_list(aManager, aIds, aIgnoreExtras) {
var doc = aManager.document;
var view = doc.getElementById("view-port").selectedPanel;
@ -400,6 +422,11 @@ MockProvider.prototype = {
* The add-on to add
*/
addAddon: function MP_addAddon(aAddon) {
var oldAddons = this.addons.filter(function(aOldAddon) aOldAddon.id == aAddon.id);
var oldAddon = oldAddons.length > 0 ? oldAddons[0] : null;
this.addons = this.addons.filter(function(aOldAddon) aOldAddon.id != aAddon.id);
this.addons.push(aAddon);
aAddon._provider = this;
@ -409,7 +436,7 @@ MockProvider.prototype = {
let requiresRestart = (aAddon.operationsRequiringRestart &
AddonManager.OP_NEEDS_RESTART_INSTALL) != 0;
AddonManagerPrivate.callInstallListeners("onExternalInstall", null, aAddon,
null, requiresRestart)
oldAddon, requiresRestart)
},
/**