Bug 567127 - Add install button to the add-ons manager. r=dtownsend, ui-r=Boriss, a=blocking-beta5

This commit is contained in:
Blair McBride 2010-06-02 13:41:41 +12:00
Родитель 0ddfa53697
Коммит 5c044cb33c
8 изменённых файлов: 257 добавлений и 1 удалений

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

@ -7,7 +7,8 @@
<!ENTITY listEmpty.findUpdates.label "Check For Updates">
<!ENTITY listEmpty.search.label "Could not find any matching add-ons">
<!ENTITY listEmpty.button.label "Learn more about add-ons">
<!ENTITY installFromFile.label "Install from file…">
<!ENTITY installFromFile.accesskey "I">
<!-- categories / views -->
<!-- LOCALIZATION NOTE: These should match the header-* entries in extensions.properties -->

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

@ -50,6 +50,9 @@ restartToDisable=%1$S will be disabled after you restart %2$S
restartToUninstall=%1$S will be removed after you restart %2$S
restartToUpgrade=%1$S will be updated after you restart %2$S
installFromFile.dialogTitle=Select add-on to install
installFromFile.filterName=Add-ons
uninstallAddonTooltip=Uninstall this add-on
uninstallAddonRestartRequiredTooltip=Uninstall this add-on (restart required)
enableAddonTooltip=Enable this add-on

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

@ -638,6 +638,48 @@ var gViewController = {
doCommand: function(aAddon) {
aAddon.cancelUninstall();
}
},
cmd_installFromFile: {
isEnabled: function() true,
doCommand: function() {
const nsIFilePicker = Ci.nsIFilePicker;
var fp = Cc["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker);
fp.init(window,
gStrings.ext.GetStringFromName("installFromFile.dialogTitle"),
nsIFilePicker.modeOpenMultiple);
try {
fp.appendFilter(gStrings.ext.GetStringFromName("installFromFile.filterName"),
"*.xpi;*.jar");
fp.appendFilters(nsIFilePicker.filterAll);
} catch (e) { }
if (fp.show() != nsIFilePicker.returnOK)
return;
var files = fp.files;
var installs = [];
function buildNextInstall() {
if (!files.hasMoreElements()) {
if (installs.length > 0) {
// Display the normal install confirmation for the installs
AddonManager.installAddonsFromWebpage("application/x-xpinstall",
this, null, installs);
}
return;
}
var file = files.getNext();
AddonManager.getInstallForFile(file, function(aInstall) {
installs.push(aInstall);
buildNextInstall();
});
}
buildNextInstall();
}
}
},

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

@ -83,6 +83,7 @@
<command id="cmd_goToRecentUpdates"/>
<command id="cmd_goToAvailableUpdates"/>
<command id="cmd_toggleBackgroundUpdateCheck"/>
<command id="cmd_installFromFile"/>
</commandset>
<!-- view commands - these act on the selected addon -->
@ -177,6 +178,11 @@
label="&updates.viewUpdates.label;"
accesskey="&updates.viewUpdates.accesskey;"
command="cmd_goToRecentUpdates"/>
<menuseparator id="utils-installFromFile-separator"/>
<menuitem id="utils-installFromFile"
label="&installFromFile.label;"
accesskey="&installFromFile.accesskey;"
command="cmd_installFromFile"/>
<menuseparator/>
<menuitem id="utils-backgroudUpdateCheck"
label="&updates.backgroudUpdateCheck.label;"

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

@ -55,6 +55,7 @@ _TEST_FILES = \
browser_bug562890.js \
browser_bug562899.js \
browser_bug562992.js \
browser_bug567127.js \
browser_bug567137.js \
browser_bug572561.js \
browser_bug577990.js \

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

@ -0,0 +1,22 @@
<?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>bug567127_1@tests.mozilla.org</em:id>
<em:version>1.0</em:version>
<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>browser_bug567127 #1</em:name>
</Description>
</RDF>

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

@ -0,0 +1,22 @@
<?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>bug567127_2@tests.mozilla.org</em:id>
<em:version>1.0</em:version>
<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>browser_bug567127 #2</em:name>
</Description>
</RDF>

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

@ -0,0 +1,159 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// Tests bug 567127 - Add install button to the add-ons manager
var gFilePickerFiles = [];
var gMockFilePickerFactory;
var gMockFilePickerFactoryCID;
var gManagerWindow;
function MockFilePicker() { }
MockFilePicker.prototype = {
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIFilePicker]),
init: function(aParent, aTitle, aMode) { },
appendFilters: function(aFilterMask) { },
appendFilter: function(aTitle, aFilter) { },
defaultString: "",
defaultExtension: "",
filterIndex: 0,
displayDirectory: null,
file: null,
fileURL: null,
get files() {
var i = 0;
return {
getNext: function() gFilePickerFiles[i++],
hasMoreElements: function() gFilePickerFiles.length > i
};
},
show: function() {
return gFilePickerFiles.length == 0 ?
Components.interfaces.nsIFilePicker.returnCancel :
Components.interfaces.nsIFilePicker.returnOK;
}
};
// This listens for the next opened window and checks it is of the right url.
// opencallback is called when the new window is fully loaded
// closecallback is called when the window is closed
function WindowOpenListener(url, opencallback, closecallback) {
this.url = url;
this.opencallback = opencallback;
this.closecallback = closecallback;
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
wm.addListener(this);
}
WindowOpenListener.prototype = {
url: null,
opencallback: null,
closecallback: null,
window: null,
domwindow: null,
handleEvent: function(event) {
is(this.domwindow.document.location.href, this.url, "Should have opened the correct window");
this.domwindow.removeEventListener("load", this, false);
// Allow any other load handlers to execute
var self = this;
executeSoon(function() { self.opencallback(self.domwindow); } );
},
onWindowTitleChange: function(window, title) {
},
onOpenWindow: function(window) {
if (this.window)
return;
this.window = window;
this.domwindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowInternal);
this.domwindow.addEventListener("load", this, false);
},
onCloseWindow: function(window) {
if (this.window != window)
return;
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
wm.removeListener(this);
this.opencallback = null;
this.window = null;
this.domwindow = null;
// Let the window close complete
executeSoon(this.closecallback);
this.closecallback = null;
}
};
function test_confirmation(aWindow, aExpectedURLs) {
var list = aWindow.document.getElementById("itemList");
is(list.childNodes.length, aExpectedURLs.length, "Should be the right number of installs");
aExpectedURLs.forEach(function(aURL) {
var node = list.firstChild;
while (node) {
if (node.url == aURL) {
ok(true, "Should have seen " + aURL + " in the list");
return;
}
node = node.nextSibling;
}
ok(false, "Should have seen " + aURL + " in the list");
});
aWindow.document.documentElement.cancelDialog();
}
function test() {
waitForExplicitFinish();
gMockFilePickerFactoryCID = Components.ID("{4f595df2-9108-42c6-9910-0dc392a310c9}");
gMockFilePickerFactory = XPCOMUtils._getFactory(MockFilePicker);
var compReg = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
compReg.registerFactory(gMockFilePickerFactoryCID,
"Mock FilePicker",
"@mozilla.org/filepicker;1",
gMockFilePickerFactory);
open_manager(null, function(aWindow) {
gManagerWindow = aWindow;
run_next_test();
});
}
function end_test() {
var compReg = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
compReg.unregisterFactory(gMockFilePickerFactoryCID,
gMockFilePickerFactory);
close_manager(gManagerWindow, function() {
finish();
});
}
add_test(function() {
var filePaths = [
get_addon_file_url("browser_bug567127_1.xpi"),
get_addon_file_url("browser_bug567127_2.xpi")
];
gFilePickerFiles = filePaths.map(function(aPath) aPath.file);
new WindowOpenListener(INSTALL_URI, function(aWindow) {
test_confirmation(aWindow, filePaths.map(function(aPath) aPath.spec));
}, run_next_test);
gManagerWindow.gViewController.doCommand("cmd_installFromFile");
});