Bug 990074: Sources linked via the optionsURL in install.rdf do not show up in addon debugger. r=fitzgen

This commit is contained in:
Dave Townsend 2014-04-24 14:16:46 -07:00
parent d4458108bb
commit 6db9e6c28e
16 changed files with 185 additions and 47 deletions

View File

@ -0,0 +1 @@
content browser_dbg_addon4 .

View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="text/javascript" src="testxul.js"/>
<label value="test.xul"/>
</window>

View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="text/javascript" src="testxul2.js"/>
<label value="test2.xul"/>
</window>

View File

@ -0,0 +1,4 @@
// Define something in here or the script may get collected
window.addEventListener("unload", function() {
window.foo = "bar";
});

View File

@ -0,0 +1,4 @@
// Define something in here or the script may get collected
window.addEventListener("unload", function() {
window.foo = "bar";
});

View File

@ -0,0 +1 @@
content browser_dbg_addon5 .

View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="text/javascript" src="testxul.js"/>
<label value="test.xul"/>
</window>

View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="text/javascript" src="testxul2.js"/>
<label value="test2.xul"/>
</window>

View File

@ -0,0 +1,4 @@
// Define something in here or the script may get collected
window.addEventListener("unload", function() {
window.foo = "bar";
});

View File

@ -0,0 +1,4 @@
// Define something in here or the script may get collected
window.addEventListener("unload", function() {
window.foo = "bar";
});

View File

@ -8,6 +8,8 @@ const ADDON_URL = EXAMPLE_URL + "addon5.xpi";
function test() {
Task.spawn(function () {
let addon = yield addAddon(ADDON_URL);
let tab1 = yield addTab("chrome://browser_dbg_addon5/content/test.xul");
let addonDebugger = yield initAddonDebugger(ADDON_URL);
is(addonDebugger.title, "Debugger - Test unpacked add-on with JS Modules", "Saw the right toolbox title.");
@ -15,33 +17,44 @@ function test() {
// Check the inital list of sources is correct
let groups = yield addonDebugger.getSourceGroups();
is(groups[0].name, "browser_dbg_addon5@tests.mozilla.org", "Add-on code should be the first group");
is(groups.length, 1, "Should be only one group.");
is(groups[1].name, "chrome://global", "XUL code should be the second group");
is(groups.length, 2, "Should be only two groups.");
let sources = groups[0].sources;
is(sources.length, 2, "Should be two sources");
ok(sources[0].url.endsWith("/browser_dbg_addon5@tests.mozilla.org/bootstrap.js"), "correct url for bootstrap code")
is(sources[0].label, "bootstrap.js", "correct label for bootstrap code")
is(sources[1].url, "resource://browser_dbg_addon5/test.jsm", "correct url for addon code")
is(sources[1].label, "test.jsm", "correct label for addon code")
// Load a new module and check it appears in the list of sources
Cu.import("resource://browser_dbg_addon5/test2.jsm", {});
groups = yield addonDebugger.getSourceGroups();
is(groups[0].name, "browser_dbg_addon5@tests.mozilla.org", "Add-on code should be the first group");
is(groups.length, 1, "Should be only one group.");
sources = groups[0].sources;
is(sources.length, 3, "Should be three sources");
ok(sources[0].url.endsWith("/browser_dbg_addon5@tests.mozilla.org/bootstrap.js"), "correct url for bootstrap code")
is(sources[0].label, "bootstrap.js", "correct label for bootstrap code")
is(sources[1].url, "resource://browser_dbg_addon5/test.jsm", "correct url for addon code")
is(sources[1].label, "test.jsm", "correct label for addon code")
is(sources[2].url, "resource://browser_dbg_addon5/test2.jsm", "correct url for addon code")
is(sources[2].label, "test2.jsm", "correct label for addon code")
is(sources[2].url, "chrome://browser_dbg_addon5/content/testxul.js", "correct url for addon tab code")
is(sources[2].label, "testxul.js", "correct label for addon tab code")
// Load a new module and tab and check they appear in the list of sources
Cu.import("resource://browser_dbg_addon5/test2.jsm", {});
let tab2 = yield addTab("chrome://browser_dbg_addon5/content/test2.xul");
groups = yield addonDebugger.getSourceGroups();
is(groups[0].name, "browser_dbg_addon5@tests.mozilla.org", "Add-on code should be the first group");
is(groups[1].name, "chrome://global", "XUL code should be the second group");
is(groups.length, 2, "Should be only two groups.");
sources = groups[0].sources;
is(sources.length, 5, "Should be five sources");
ok(sources[0].url.endsWith("/browser_dbg_addon5@tests.mozilla.org/bootstrap.js"), "correct url for bootstrap code")
is(sources[0].label, "bootstrap.js", "correct label for bootstrap code")
is(sources[1].url, "resource://browser_dbg_addon5/test.jsm", "correct url for addon code")
is(sources[1].label, "test.jsm", "correct label for addon code")
is(sources[2].url, "chrome://browser_dbg_addon5/content/testxul.js", "correct url for addon tab code")
is(sources[2].label, "testxul.js", "correct label for addon tab code")
is(sources[3].url, "resource://browser_dbg_addon5/test2.jsm", "correct url for addon code")
is(sources[3].label, "test2.jsm", "correct label for addon code")
is(sources[4].url, "chrome://browser_dbg_addon5/content/testxul2.js", "correct url for addon tab code")
is(sources[4].label, "testxul2.js", "correct label for addon tab code")
Cu.unload("resource://browser_dbg_addon5/test2.jsm");
yield addonDebugger.destroy();
yield removeTab(tab1);
yield removeTab(tab2);
yield removeAddon(addon);
finish();
});

View File

@ -8,6 +8,8 @@ const ADDON_URL = EXAMPLE_URL + "addon4.xpi";
function test() {
Task.spawn(function () {
let addon = yield addAddon(ADDON_URL);
let tab1 = yield addTab("chrome://browser_dbg_addon4/content/test.xul");
let addonDebugger = yield initAddonDebugger(ADDON_URL);
is(addonDebugger.title, "Debugger - Test add-on with JS Modules", "Saw the right toolbox title.");
@ -15,33 +17,44 @@ function test() {
// Check the inital list of sources is correct
let groups = yield addonDebugger.getSourceGroups();
is(groups[0].name, "browser_dbg_addon4@tests.mozilla.org", "Add-on code should be the first group");
is(groups.length, 1, "Should be only one group.");
is(groups[1].name, "chrome://global", "XUL code should be the second group");
is(groups.length, 2, "Should be only two groups.");
let sources = groups[0].sources;
is(sources.length, 2, "Should be two sources");
ok(sources[0].url.endsWith("/browser_dbg_addon4@tests.mozilla.org.xpi!/bootstrap.js"), "correct url for bootstrap code")
is(sources[0].label, "bootstrap.js", "correct label for bootstrap code")
is(sources[1].url, "resource://browser_dbg_addon4/test.jsm", "correct url for addon code")
is(sources[1].label, "test.jsm", "correct label for addon code")
// Load a new module and check it appears in the list of sources
Cu.import("resource://browser_dbg_addon4/test2.jsm", {});
groups = yield addonDebugger.getSourceGroups();
is(groups[0].name, "browser_dbg_addon4@tests.mozilla.org", "Add-on code should be the first group");
is(groups.length, 1, "Should be only one group.");
sources = groups[0].sources;
is(sources.length, 3, "Should be three sources");
ok(sources[0].url.endsWith("/browser_dbg_addon4@tests.mozilla.org.xpi!/bootstrap.js"), "correct url for bootstrap code")
is(sources[0].label, "bootstrap.js", "correct label for bootstrap code")
is(sources[1].url, "resource://browser_dbg_addon4/test.jsm", "correct url for addon code")
is(sources[1].label, "test.jsm", "correct label for addon code")
is(sources[2].url, "resource://browser_dbg_addon4/test2.jsm", "correct url for addon code")
is(sources[2].label, "test2.jsm", "correct label for addon code")
is(sources[2].url, "chrome://browser_dbg_addon4/content/testxul.js", "correct url for addon tab code")
is(sources[2].label, "testxul.js", "correct label for addon tab code")
// Load a new module and tab and check they appear in the list of sources
Cu.import("resource://browser_dbg_addon4/test2.jsm", {});
let tab2 = yield addTab("chrome://browser_dbg_addon4/content/test2.xul");
groups = yield addonDebugger.getSourceGroups();
is(groups[0].name, "browser_dbg_addon4@tests.mozilla.org", "Add-on code should be the first group");
is(groups[1].name, "chrome://global", "XUL code should be the second group");
is(groups.length, 2, "Should be only two groups.");
sources = groups[0].sources;
is(sources.length, 5, "Should be five sources");
ok(sources[0].url.endsWith("/browser_dbg_addon4@tests.mozilla.org.xpi!/bootstrap.js"), "correct url for bootstrap code")
is(sources[0].label, "bootstrap.js", "correct label for bootstrap code")
is(sources[1].url, "resource://browser_dbg_addon4/test.jsm", "correct url for addon code")
is(sources[1].label, "test.jsm", "correct label for addon code")
is(sources[2].url, "chrome://browser_dbg_addon4/content/testxul.js", "correct url for addon tab code")
is(sources[2].label, "testxul.js", "correct label for addon tab code")
is(sources[3].url, "resource://browser_dbg_addon4/test2.jsm", "correct url for addon code")
is(sources[3].label, "test2.jsm", "correct label for addon code")
is(sources[4].url, "chrome://browser_dbg_addon4/content/testxul2.js", "correct url for addon tab code")
is(sources[4].label, "testxul2.js", "correct label for addon tab code")
Cu.unload("resource://browser_dbg_addon4/test2.jsm");
yield addonDebugger.destroy();
yield removeTab(tab1);
yield removeTab(tab2);
yield removeAddon(addon);
finish();
});

View File

@ -123,7 +123,11 @@ function addAddon(aUrl) {
let listener = {
onInstallEnded: function(aAddon, aAddonInstall) {
aInstaller.removeListener(listener);
deferred.resolve(aAddonInstall);
// Wait for add-on's startup scripts to execute. See bug 997408
executeSoon(function() {
deferred.resolve(aAddonInstall);
});
}
};
aInstaller.addListener(listener);

View File

@ -25,8 +25,9 @@ let addonManager = null;
* about them.
*/
function mapURIToAddonID(uri, id) {
if (Services.appinfo.ID == B2G_ID)
if (Services.appinfo.ID == B2G_ID) {
return false;
}
if (!addonManager) {
addonManager = Cc["@mozilla.org/addons/integration;1"].
@ -4778,6 +4779,33 @@ update(AddonThreadActor.prototype, {
// A constant prefix that will be used to form the actor ID by the server.
actorPrefix: "addonThread",
onAttach: function(aRequest) {
if (!this.attached) {
Services.obs.addObserver(this, "chrome-document-global-created", false);
Services.obs.addObserver(this, "content-document-global-created", false);
}
return ThreadActor.prototype.onAttach.call(this, aRequest);
},
disconnect: function() {
if (this.attached) {
Services.obs.removeObserver(this, "content-document-global-created");
Services.obs.removeObserver(this, "chrome-document-global-created");
}
return ThreadActor.prototype.disconnect.call(this);
},
/**
* Called when a new DOM document global is created. Check if the DOM was
* loaded from an add-on and if so make the window a debuggee.
*/
observe: function(aSubject, aTopic, aData) {
let id = {};
if (mapURIToAddonID(aSubject.location, id) && id.value === this.addonID) {
this.dbg.addDebuggee(aSubject.defaultView);
}
},
/**
* Override the eligibility check for scripts and sources to make
* sure every script and source with a URL is stored when debugging
@ -4785,12 +4813,14 @@ update(AddonThreadActor.prototype, {
*/
_allowSource: function(aSourceURL) {
// Hide eval scripts
if (!aSourceURL)
if (!aSourceURL) {
return false;
}
// XPIProvider.jsm evals some code in every add-on's bootstrap.js. Hide it
if (aSourceURL == "resource://gre/modules/addons/XPIProvider.jsm")
if (aSourceURL == "resource://gre/modules/addons/XPIProvider.jsm") {
return false;
}
return true;
},
@ -4837,27 +4867,50 @@ update(AddonThreadActor.prototype, {
* @param aGlobal Debugger.Object
*/
_checkGlobal: function ADA_checkGlobal(aGlobal) {
let obj = null;
try {
obj = aGlobal.unsafeDereference();
}
catch (e) {
// Because of bug 991399 we sometimes get bad objects here. If we can't
// dereference them then they won't be useful to us
return false;
}
try {
// This will fail for non-Sandbox objects, hence the try-catch block.
let metadata = Cu.getSandboxMetadata(aGlobal.unsafeDereference());
if (metadata)
let metadata = Cu.getSandboxMetadata(obj);
if (metadata) {
return metadata.addonID === this.addonID;
}
} catch (e) {
}
if (obj instanceof Ci.nsIDOMWindow) {
let id = {};
if (mapURIToAddonID(obj.document.documentURIObject, id)) {
return id.value === this.addonID;
}
return false;
}
// Check the global for a __URI__ property and then try to map that to an
// add-on
let uridescriptor = aGlobal.getOwnPropertyDescriptor("__URI__");
if (uridescriptor && "value" in uridescriptor) {
if (uridescriptor && "value" in uridescriptor && uridescriptor.value) {
let uri;
try {
let uri = Services.io.newURI(uridescriptor.value, null, null);
let id = {};
if (mapURIToAddonID(uri, id)) {
return id.value === this.addonID;
}
uri = Services.io.newURI(uridescriptor.value, null, null);
}
catch (e) {
DevToolsUtils.reportException("AddonThreadActor.prototype._checkGlobal", e);
DevToolsUtils.reportException("AddonThreadActor.prototype._checkGlobal",
new Error("Invalid URI: " + uridescriptor.value));
return false;
}
let id = {};
if (mapURIToAddonID(uri, id)) {
return id.value === this.addonID;
}
}
@ -4865,6 +4918,11 @@ update(AddonThreadActor.prototype, {
}
});
AddonThreadActor.prototype.requestTypes = Object.create(ThreadActor.prototype.requestTypes);
update(AddonThreadActor.prototype.requestTypes, {
"attach": AddonThreadActor.prototype.onAttach
});
/**
* Manages the sources for a thread. Handles source maps, locations in the
* sources, etc for ThreadActors.