Bug 565682: Support dropping xpi/jar files on the add-ons manager. r=Unfocused

This commit is contained in:
Dave Townsend 2010-06-16 19:46:11 -07:00
Родитель 3b5df1c67a
Коммит a34dc9b037
11 изменённых файлов: 347 добавлений и 6 удалений

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

@ -1256,3 +1256,63 @@ var gDetailView = {
this.updateState();
}
};
var gDragDrop = {
onDragOver: function(aEvent) {
var types = aEvent.dataTransfer.types;
if (types.contains("text/uri-list") ||
types.contains("text/x-moz-url") ||
types.contains("application/x-moz-file"))
aEvent.preventDefault();
},
onDrop: function(aEvent) {
var dataTransfer = aEvent.dataTransfer;
var urls = [];
// Convert every dropped item into a url
for (var i = 0; i < dataTransfer.mozItemCount; i++) {
var url = dataTransfer.mozGetDataAt("text/uri-list", i);
if (url) {
urls.push(url);
continue;
}
url = dataTransfer.mozGetDataAt("text/x-moz-url", i);
if (url) {
urls.push(url.split("\n")[0]);
continue;
}
var file = dataTransfer.mozGetDataAt("application/x-moz-file", i);
if (file) {
urls.push(Services.io.newFileURI(file).spec);
continue;
}
}
var pos = 0;
var installs = [];
function buildNextInstall() {
if (pos == urls.length) {
if (installs.length > 0) {
// Display the normal install confirmation for the installs
AddonManager.installAddonsFromWebpage("application/x-xpinstall", this,
null, installs);
}
return;
}
AddonManager.getInstallForURL(urls[pos++], function(aInstall) {
installs.push(aInstall);
buildNextInstall();
}, "application/x-xpinstall");
}
buildNextInstall();
aEvent.preventDefault();
}
};

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

@ -46,7 +46,10 @@
]>
<page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
id="addons-page" title="&addons.windowTitle;">
id="addons-page" title="&addons.windowTitle;"
ondragenter="gDragDrop.onDragOver(event)"
ondragover="gDragDrop.onDragOver(event)"
ondrop="gDragDrop.onDrop(event)">
<script type="application/javascript"
src="chrome://mozapps/content/extensions/extensions.js"/>

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

@ -40,16 +40,18 @@ topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = toolkit/mozapps/extensions/test/browser
ADDONSRC = $(srcdir)/addons
TESTXPI = $(CURDIR)/$(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)/addons
include $(DEPTH)/config/autoconf.mk
_TEST_FILES = \
head.js \
browser_bug562899.js \
browser_dragdrop.js \
browser_updatessl.js \
browser_updatessl.rdf \
browser_installssl.js \
browser_installssl.xpi \
redirect.sjs \
$(NULL)
@ -57,3 +59,14 @@ include $(topsrcdir)/config/rules.mk
libs:: $(_TEST_FILES)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
libs::
rm -rf $(TESTXPI)
$(NSINSTALL) -D $(TESTXPI)
if [ -d $(ADDONSRC) ]; then \
$(EXIT_ON_ERROR) \
for dir in $(ADDONSRC)/*; do \
base=`basename $$dir` ; \
(cd $$dir && zip $(TESTXPI)/$$base.xpi *) \
done \
fi

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

@ -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>dragdrop1@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>Drag Drop test 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>dragdrop2@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>Drag Drop test 2</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>sslinstall@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>SSL Install Tests</em:name>
</Description>
</RDF>

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

@ -0,0 +1,185 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// This tests simulated drag and drop of files into the add-ons manager.
// We test with the add-ons manager in its own tab if in Firefox otherwise
// in its own window.
// Tests are only simulations of the drag and drop events, we cannot really do
// this automatically.
Components.utils.import("resource://gre/modules/AddonManager.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
var gManagerWindow;
// 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() {
waitForExplicitFinish();
Services.prefs.setBoolPref(PREF_LOGGING_ENABLED, true);
open_manager(null, function(aWindow) {
gManagerWindow = aWindow;
run_next_test();
});
}
function end_test() {
Services.prefs.clearUserPref(PREF_LOGGING_ENABLED);
gManagerWindow.close();
finish();
}
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();
}
// Simulates dropping a URL onto the manager
add_test(function() {
var url = TESTROOT + "addons/browser_dragdrop1.xpi";
new WindowOpenListener(INSTALL_URI, function(aWindow) {
test_confirmation(aWindow, [url]);
}, run_next_test);
var effect = EventUtils.synthesizeDrop(gManagerWindow.document.getElementById("view-container"),
[[{type: "text/x-moz-url", data: url}]],
"copy", gManagerWindow);
is(effect, "copy", "Drag should be accepted");
});
// Simulates dropping a file onto the manager
add_test(function() {
var fileurl = get_addon_file_url("browser_dragdrop1.xpi");
new WindowOpenListener(INSTALL_URI, function(aWindow) {
test_confirmation(aWindow, [fileurl.spec]);
}, run_next_test);
var effect = EventUtils.synthesizeDrop(gManagerWindow.document.getElementById("view-container"),
[[{type: "application/x-moz-file", data: fileurl.file}]],
"copy", gManagerWindow);
is(effect, "copy", "Drag should be accepted");
});
// Simulates dropping two urls onto the manager
add_test(function() {
var url1 = TESTROOT + "addons/browser_dragdrop1.xpi";
var url2 = TESTROOT2 + "addons/browser_dragdrop2.xpi";
new WindowOpenListener(INSTALL_URI, function(aWindow) {
test_confirmation(aWindow, [url1, url2]);
}, run_next_test);
var effect = EventUtils.synthesizeDrop(gManagerWindow.document.getElementById("view-container"),
[[{type: "text/x-moz-url", data: url1}],
[{type: "text/x-moz-url", data: url2}]],
"copy", gManagerWindow);
is(effect, "copy", "Drag should be accepted");
});
// Simulates dropping two files onto the manager
add_test(function() {
var fileurl1 = get_addon_file_url("browser_dragdrop1.xpi");
var fileurl2 = get_addon_file_url("browser_dragdrop2.xpi");
new WindowOpenListener(INSTALL_URI, function(aWindow) {
test_confirmation(aWindow, [fileurl1.spec, fileurl2.spec]);
}, run_next_test);
var effect = EventUtils.synthesizeDrop(gManagerWindow.document.getElementById("view-container"),
[[{type: "application/x-moz-file", data: fileurl1.file}],
[{type: "application/x-moz-file", data: fileurl2.file}]],
"copy", gManagerWindow);
is(effect, "copy", "Drag should be accepted");
});
// Simulates dropping a file and a url onto the manager (weird, but should still work)
add_test(function() {
var url = TESTROOT + "addons/browser_dragdrop1.xpi";
var fileurl = get_addon_file_url("browser_dragdrop2.xpi");
new WindowOpenListener(INSTALL_URI, function(aWindow) {
test_confirmation(aWindow, [url, fileurl.spec]);
}, run_next_test);
var effect = EventUtils.synthesizeDrop(gManagerWindow.document.getElementById("view-container"),
[[{type: "text/x-moz-url", data: url}],
[{type: "application/x-moz-file", data: fileurl.file}]],
"copy", gManagerWindow);
is(effect, "copy", "Drag should be accepted");
});

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

@ -5,8 +5,8 @@
Components.utils.import("resource://gre/modules/AddonManager.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
const xpi = "browser/toolkit/mozapps/extensions/test/browser/browser_installssl.xpi";
const redirect = "browser/toolkit/mozapps/extensions/test/browser/redirect.sjs?";
const xpi = RELATIVE_DIR + "addons/browser_installssl.xpi";
const redirect = RELATIVE_DIR + "redirect.sjs?";
const SUCCESS = 0;
var gTests = [];

Двоичный файл не отображается.

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

@ -4,8 +4,8 @@
Components.utils.import("resource://gre/modules/AddonUpdateChecker.jsm");
const updaterdf = "browser/toolkit/mozapps/extensions/test/browser/browser_updatessl.rdf";
const redirect = "browser/toolkit/mozapps/extensions/test/browser/redirect.sjs?";
const updaterdf = RELATIVE_DIR + "browser_updatessl.rdf";
const redirect = RELATIVE_DIR + "redirect.sjs?";
const SUCCESS = 0;
var gTests = [];

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

@ -2,7 +2,14 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
const RELATIVE_DIR = "browser/toolkit/mozapps/extensions/test/browser/";
const TESTROOT = "http://example.com/" + RELATIVE_DIR;
const TESTROOT2 = "http://example.org/" + RELATIVE_DIR;
const CHROMEROOT = "chrome://mochikit/content/" + RELATIVE_DIR;
const MANAGER_URI = "about:addons";
const INSTALL_URI = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul";
const PREF_LOGGING_ENABLED = "extensions.logging.enabled";
var gPendingTests = [];
@ -24,6 +31,13 @@ function run_next_test() {
gPendingTests.shift()();
}
function get_addon_file_url(aFilename) {
var cr = Cc["@mozilla.org/chrome/chrome-registry;1"].
getService(Ci.nsIChromeRegistry);
var fileurl = cr.convertChromeURL(makeURI(CHROMEROOT + "addons/" + aFilename));
return fileurl.QueryInterface(Ci.nsIFileURL);
}
function wait_for_view_load(aManagerWindow, aCallback) {
if (!aManagerWindow.gViewController.currentViewObj.node.hasAttribute("loading")) {
aCallback(aManagerWindow);