зеркало из https://github.com/mozilla/gecko-dev.git
Bug 553492 Add Addon.size to expose the addon's size on disk. r=robstrong
This commit is contained in:
Родитель
7a7598e3b8
Коммит
48472adcf7
|
@ -143,6 +143,12 @@ AddonSearchResult.prototype = {
|
|||
*/
|
||||
userDisabled: false,
|
||||
|
||||
/**
|
||||
* The size of the add-on's files in bytes. For an add-on that have not yet
|
||||
* been downloaded this may be an estimated value.
|
||||
*/
|
||||
size: null,
|
||||
|
||||
/**
|
||||
* Indicates what scope the add-on is installed in, per profile, user,
|
||||
* system or application
|
||||
|
@ -478,6 +484,8 @@ var AddonRepository = {
|
|||
break;
|
||||
}
|
||||
result.xpiURL = node.textContent.trim();
|
||||
if (node.hasAttribute("size"))
|
||||
addon.size = node.getAttribute("size");
|
||||
|
||||
// Ignore add-on installs
|
||||
if (aSkip.sourceURIs.indexOf(result.xpiURL) != -1)
|
||||
|
|
|
@ -415,6 +415,12 @@ function AddonWrapper(aTheme, aBeingEnabled) {
|
|||
return pending;
|
||||
});
|
||||
|
||||
this.__defineGetter__("size", function() {
|
||||
// The size changes depending on whether the theme is in use or not, this is
|
||||
// probably not worth exposing.
|
||||
return null;
|
||||
});
|
||||
|
||||
this.__defineGetter__("permissions", function() {
|
||||
let permissions = AddonManager.PERM_CAN_UNINSTALL;
|
||||
if (this.userDisabled)
|
||||
|
|
|
@ -205,6 +205,33 @@ function PluginWrapper(aId, aName, aDescription, aTags) {
|
|||
return bs.getPluginBlocklistState(aTags[0]);
|
||||
});
|
||||
|
||||
this.__defineGetter__("size", function() {
|
||||
function getDirectorySize(aFile) {
|
||||
let size = 0;
|
||||
let entries = aFile.directoryEntries.QueryInterface(Ci.nsIDirectoryEnumerator);
|
||||
let entry;
|
||||
while (entry = entries.nextFile) {
|
||||
if (entry.isSymlink() || !entry.isDirectory())
|
||||
size += entry.fileSize;
|
||||
else
|
||||
size += getDirectorySize(entry);
|
||||
}
|
||||
entries.close();
|
||||
return size;
|
||||
}
|
||||
|
||||
let size = 0;
|
||||
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
|
||||
aTags.forEach(function(aTag) {
|
||||
file.initWithPath(aTag.fullpath);
|
||||
if (file.isDirectory())
|
||||
size += getDirectorySize(file);
|
||||
else
|
||||
size += file.fileSize;
|
||||
});
|
||||
return size;
|
||||
});
|
||||
|
||||
this.__defineGetter__("scope", function() {
|
||||
let path = aTags[0].fullpath;
|
||||
// Plugins inside the application directory are in the application scope
|
||||
|
|
|
@ -98,7 +98,7 @@
|
|||
</compatible_applications>
|
||||
<compatible_os>ALL</compatible_os>
|
||||
<learnmore>https://addons.mozilla.org/addon/5992</learnmore>
|
||||
<install hash="sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3">http://localhost:4444/test.xpi</install>
|
||||
<install size="234" hash="sha1:c26f0b0d62e5dcddcda95074d3f3fedb9bbc26e3">http://localhost:4444/test.xpi</install>
|
||||
</addon>
|
||||
<addon>
|
||||
<name>FAIL</name>
|
||||
|
@ -160,7 +160,7 @@
|
|||
</application>
|
||||
</compatible_applications>
|
||||
<compatible_os>XPCShell</compatible_os>
|
||||
<install>http://localhost:4444/test.xpi</install>
|
||||
<install size="1204">http://localhost:4444/test.xpi</install>
|
||||
</addon>
|
||||
</searchresults>
|
||||
|
||||
|
|
|
@ -164,13 +164,13 @@
|
|||
<max_version>1</max_version>
|
||||
</application>
|
||||
</compatible_applications>
|
||||
<install os="Windows">
|
||||
<install os="Windows" size="123">
|
||||
http://localhost:4444/test.xpi
|
||||
</install>
|
||||
<install os="XPCShell">
|
||||
<install os="XPCShell" size="456">
|
||||
http://localhost:4444/XPCShell.xpi
|
||||
</install>
|
||||
<install os="Darwin">
|
||||
<install os="Darwin" size="789">
|
||||
http://localhost:4444/test.xpi
|
||||
</install>
|
||||
</addon>
|
||||
|
|
|
@ -70,7 +70,8 @@ var RESULTS = [
|
|||
screenshots: [],
|
||||
homepageURL: "https://addons.mozilla.org/addon/5992",
|
||||
type: "extension",
|
||||
sourceURI: "http://localhost:4444/test.xpi"
|
||||
sourceURI: "http://localhost:4444/test.xpi",
|
||||
size: 234
|
||||
},
|
||||
{
|
||||
id: "test6@tests.mozilla.org",
|
||||
|
@ -83,7 +84,8 @@ var RESULTS = [
|
|||
screenshots: ["http://localhost:4444/test_bug404024/thumbnail.png"],
|
||||
homepageURL: null,
|
||||
type: "theme",
|
||||
sourceURI: "http://localhost:4444/test.xpi"
|
||||
sourceURI: "http://localhost:4444/test.xpi",
|
||||
size: 1204
|
||||
}
|
||||
];
|
||||
|
||||
|
|
|
@ -70,7 +70,8 @@ var RESULTS = [
|
|||
screenshots: [],
|
||||
homepageURL: "https://addons.mozilla.org/addon/5992",
|
||||
type: "extension",
|
||||
sourceURI: "http://localhost:4444/test.xpi"
|
||||
sourceURI: "http://localhost:4444/test.xpi",
|
||||
size: null
|
||||
},
|
||||
{
|
||||
id: "test6@tests.mozilla.org",
|
||||
|
@ -83,7 +84,8 @@ var RESULTS = [
|
|||
screenshots: ["http://localhost:4444/test_bug404024/thumbnail.png"],
|
||||
homepageURL: null,
|
||||
type: "theme",
|
||||
sourceURI: "http://localhost:4444/XPCShell.xpi"
|
||||
sourceURI: "http://localhost:4444/XPCShell.xpi",
|
||||
size: 456,
|
||||
}
|
||||
];
|
||||
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
// install.rdf size, icon.png size, subfile.txt size
|
||||
const ADDON_SIZE = 635 + 15 + 26;
|
||||
|
||||
// This verifies the functionality of getResourceURI
|
||||
// There are two cases - with a filename it returns an nsIFileURL to the filename
|
||||
// and with no parameters, it returns an nsIFileURL to the root of the addon
|
||||
|
@ -28,6 +31,8 @@ function run_test() {
|
|||
|
||||
do_check_false(aInstall.addon.hasResource("subdir/missing.txt"));
|
||||
|
||||
do_check_eq(aInstall.addon.size, ADDON_SIZE);
|
||||
|
||||
completeAllInstalls([aInstall], function() {
|
||||
restartManager();
|
||||
AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
|
||||
|
@ -67,6 +72,8 @@ function run_test() {
|
|||
|
||||
do_check_false(a1.hasResource("subdir/missing.txt"));
|
||||
|
||||
do_check_eq(a1.size, ADDON_SIZE);
|
||||
|
||||
a1.uninstall();
|
||||
|
||||
restartManager();
|
||||
|
|
|
@ -11,6 +11,9 @@ const MAX_INSTALL_TIME = 10000;
|
|||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
Components.utils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
// install.rdf size, icon.png size
|
||||
const ADDON1_SIZE = 705 + 16;
|
||||
|
||||
do_load_httpd_js();
|
||||
var testserver;
|
||||
var gInstallDate;
|
||||
|
@ -61,6 +64,7 @@ function run_test_1() {
|
|||
do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);
|
||||
do_check_true(install.addon.hasResource("install.rdf"));
|
||||
do_check_eq(install.addon.install, install);
|
||||
do_check_eq(install.addon.size, ADDON1_SIZE);
|
||||
|
||||
let file = do_get_addon("test_install1");
|
||||
let uri = Services.io.newFileURI(file).spec;
|
||||
|
@ -122,6 +126,7 @@ function check_test_1() {
|
|||
do_check_true(isExtensionInAddonsList(profileDir, a1.id));
|
||||
do_check_true(do_get_addon("test_install1").exists());
|
||||
do_check_in_crash_annotation(a1.id, a1.version);
|
||||
do_check_eq(a1.size, ADDON1_SIZE);
|
||||
|
||||
do_check_eq(a1.sourceURI.spec,
|
||||
Services.io.newFileURI(do_get_addon("test_install1")).spec);
|
||||
|
|
|
@ -16,23 +16,51 @@ function run_test() {
|
|||
run_test_1();
|
||||
}
|
||||
|
||||
function get_unix_test_plugin() {
|
||||
let plugins = Components.classes["@mozilla.org/file/directory_service;1"].
|
||||
getService(Components.interfaces.nsIProperties).
|
||||
get("CurProcD", Components.interfaces.nsILocalFile);
|
||||
// Finds the test plugin library
|
||||
function get_test_plugin() {
|
||||
var plugins = Services.dirsvc.get("CurProcD", AM_Ci.nsILocalFile);
|
||||
plugins.append("plugins");
|
||||
do_check_true(plugins.exists());
|
||||
let plugin = plugins.clone();
|
||||
|
||||
var plugin = plugins.clone();
|
||||
// OSX plugin
|
||||
plugin.append("Test.plugin");
|
||||
if (plugin.exists())
|
||||
return plugin;
|
||||
|
||||
plugin = plugins.clone();
|
||||
// *nix plugin
|
||||
plugin.append("libnptest.so");
|
||||
if (plugin.exists())
|
||||
return plugin;
|
||||
|
||||
// Windows plugin
|
||||
plugin = plugins.clone();
|
||||
plugin.append("nptest.dll");
|
||||
if (plugin.exists())
|
||||
return plugin;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getFileSize(aFile) {
|
||||
if (!aFile.isDirectory())
|
||||
return aFile.fileSize;
|
||||
|
||||
let size = 0;
|
||||
let entries = aFile.directoryEntries.QueryInterface(AM_Ci.nsIDirectoryEnumerator);
|
||||
let entry;
|
||||
while (entry = entries.nextFile)
|
||||
size += getFileSize(entry);
|
||||
entries.close();
|
||||
return size;
|
||||
}
|
||||
|
||||
// Tests that the test plugin exists
|
||||
function run_test_1() {
|
||||
var testPlugin = get_test_plugin();
|
||||
do_check_neq(testPlugin, null);
|
||||
|
||||
AddonManager.getAddonsByTypes("plugin", function(addons) {
|
||||
do_check_true(addons.length > 0);
|
||||
|
||||
|
@ -58,13 +86,14 @@ function run_test_1() {
|
|||
do_check_eq(p.blocklistState, 0);
|
||||
do_check_eq(p.permissions, AddonManager.PERM_CAN_DISABLE);
|
||||
do_check_eq(p.pendingOperations, 0);
|
||||
do_check_true(p.size > 0);
|
||||
do_check_eq(p.size, getFileSize(testPlugin));
|
||||
|
||||
// Work around the fact that on Linux source builds, if we're using
|
||||
// symlinks (i.e. objdir), then Linux will see these as a different scope
|
||||
// to non-symlinks.
|
||||
// See Bug 562886 and Bug 568027.
|
||||
let pluginLoc = get_unix_test_plugin();
|
||||
if (pluginLoc && pluginLoc.isSymlink()) {
|
||||
if (testPlugin.isSymlink()) {
|
||||
do_check_neq(p.scope, AddonManager.SCOPE_APPLICATION);
|
||||
do_check_neq(p.scope, AddonManager.SCOPE_PROFILE);
|
||||
} else {
|
||||
|
|
Загрузка…
Ссылка в новой задаче