Bug 740612: Inject values into bootstrap scope before running bootstrap.js and properly handle errors. r=Unfocused

This commit is contained in:
Dave Townsend 2012-05-09 14:54:02 -07:00
parent 4d5c363c02
commit 699a0190c9
7 changed files with 152 additions and 11 deletions

View File

@ -3597,6 +3597,16 @@ var XPIProvider = {
createInstance(Ci.mozIJSSubScriptLoader); createInstance(Ci.mozIJSSubScriptLoader);
try { try {
// Copy the reason values from the global object into the bootstrap scope.
for (let name in BOOTSTRAP_REASONS)
this.bootstrapScopes[aId][name] = BOOTSTRAP_REASONS[name];
// Add other stuff that extensions want.
const features = [ "Worker", "ChromeWorker" ];
for (let feature of features)
this.bootstrapScopes[aId][feature] = gGlobalScope[feature];
// As we don't want our caller to control the JS version used for the // As we don't want our caller to control the JS version used for the
// bootstrap file, we run loadSubScript within the context of the // bootstrap file, we run loadSubScript within the context of the
// sandbox with the latest JS version set explicitly. // sandbox with the latest JS version set explicitly.
@ -3614,17 +3624,6 @@ var XPIProvider = {
catch (e) { catch (e) {
WARN("Error loading bootstrap.js for " + aId, e); WARN("Error loading bootstrap.js for " + aId, e);
} }
// Copy the reason values from the global object into the bootstrap scope.
for (let name in BOOTSTRAP_REASONS)
this.bootstrapScopes[aId][name] = BOOTSTRAP_REASONS[name];
// Add other stuff that extensions want.
const features = [ "Worker", "ChromeWorker" ];
for each (let feature in features)
this.bootstrapScopes[aId][feature] = gGlobalScope[feature];
}, },
/** /**

View File

@ -0,0 +1 @@
const APP_STARTUP = 1;

View File

@ -0,0 +1,24 @@
<?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>bug740612_1@tests.mozilla.org</em:id>
<em:version>1.0</em:version>
<em:bootstrap>true</em:bootstrap>
<!-- Front End MetaData -->
<em:name>Test Bootstrap 1</em:name>
<em:description>Test Description</em:description>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>

View File

@ -0,0 +1,23 @@
Components.utils.import("resource://gre/modules/Services.jsm");
const VERSION = "1.0";
function install(data, reason) {
Services.prefs.setIntPref("bootstraptest.installed_version", VERSION);
Services.prefs.setIntPref("bootstraptest.install_reason", reason);
}
function startup(data, reason) {
Services.prefs.setIntPref("bootstraptest.active_version", VERSION);
Services.prefs.setIntPref("bootstraptest.startup_reason", reason);
}
function shutdown(data, reason) {
Services.prefs.setIntPref("bootstraptest.active_version", 0);
Services.prefs.setIntPref("bootstraptest.shutdown_reason", reason);
}
function uninstall(data, reason) {
Services.prefs.setIntPref("bootstraptest.installed_version", 0);
Services.prefs.setIntPref("bootstraptest.uninstall_reason", reason);
}

View File

@ -0,0 +1,24 @@
<?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>bug740612_2@tests.mozilla.org</em:id>
<em:version>1.0</em:version>
<em:bootstrap>true</em:bootstrap>
<!-- Front End MetaData -->
<em:name>Test Bootstrap 2</em:name>
<em:description>Test Description</em:description>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>

View File

@ -0,0 +1,69 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// This verifies that attempts to override the global values fails but doesn't
// destroy the world with it
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
const profileDir = gProfD.clone();
profileDir.append("extensions");
function getActiveVersion() {
return Services.prefs.getIntPref("bootstraptest.active_version");
}
function getInstalledVersion() {
return Services.prefs.getIntPref("bootstraptest.installed_version");
}
function manuallyInstall(aXPIFile, aInstallLocation, aID) {
if (TEST_UNPACKED) {
let dir = aInstallLocation.clone();
dir.append(aID);
dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755);
let zip = AM_Cc["@mozilla.org/libjar/zip-reader;1"].
createInstance(AM_Ci.nsIZipReader);
zip.open(aXPIFile);
let entries = zip.findEntries(null);
while (entries.hasMore()) {
let entry = entries.getNext();
let target = dir.clone();
entry.split("/").forEach(function(aPart) {
target.append(aPart);
});
zip.extract(entry, target);
}
zip.close();
return dir;
}
else {
let target = aInstallLocation.clone();
target.append(aID + ".xpi");
aXPIFile.copyTo(target.parent, target.leafName);
return target;
}
}
function run_test() {
do_test_pending();
manuallyInstall(do_get_addon("test_bug740612_1"), profileDir,
"bug740612_1@tests.mozilla.org");
manuallyInstall(do_get_addon("test_bug740612_2"), profileDir,
"bug740612_2@tests.mozilla.org");
startupManager();
AddonManager.getAddonsByIDs(["bug740612_1@tests.mozilla.org",
"bug740612_2@tests.mozilla.org"],
function([a1, a2]) {
do_check_neq(a1, null);
do_check_neq(a2, null);
do_check_eq(getInstalledVersion(), "1.0");
do_check_eq(getActiveVersion(), "1.0");
do_test_finished();
});
}

View File

@ -128,6 +128,7 @@ fail-if = os == "android"
[test_bug655254.js] [test_bug655254.js]
[test_bug659772.js] [test_bug659772.js]
[test_bug675371.js] [test_bug675371.js]
[test_bug740612.js]
[test_cacheflush.js] [test_cacheflush.js]
[test_checkcompatibility.js] [test_checkcompatibility.js]
[test_ChromeManifestParser.js] [test_ChromeManifestParser.js]