2014-03-26 16:04:20 -07:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
// Make sure the add-on actor can see loaded JS Modules from an add-on
|
|
|
|
|
|
|
|
const ADDON4_URL = EXAMPLE_URL + "addon4.xpi";
|
|
|
|
|
2014-03-27 10:29:03 -07:00
|
|
|
let gAddon, gClient, gThreadClient, gDebugger, gSources, gTitle;
|
|
|
|
|
|
|
|
function onMessage(event) {
|
|
|
|
try {
|
|
|
|
let json = JSON.parse(event.data);
|
|
|
|
switch (json.name) {
|
|
|
|
case "toolbox-title":
|
|
|
|
gTitle = json.data.value;
|
|
|
|
break;
|
|
|
|
}
|
2014-03-31 10:19:15 -07:00
|
|
|
} catch(e) {
|
|
|
|
DevToolsUtils.reportException("onMessage", e);
|
|
|
|
}
|
2014-03-27 10:29:03 -07:00
|
|
|
}
|
2014-03-26 16:04:20 -07:00
|
|
|
|
|
|
|
function test() {
|
|
|
|
Task.spawn(function () {
|
|
|
|
if (!DebuggerServer.initialized) {
|
|
|
|
DebuggerServer.init(() => true);
|
|
|
|
DebuggerServer.addBrowserActors();
|
|
|
|
}
|
|
|
|
|
|
|
|
gBrowser.selectedTab = gBrowser.addTab();
|
|
|
|
let iframe = document.createElement("iframe");
|
|
|
|
document.documentElement.appendChild(iframe);
|
|
|
|
|
2014-03-27 10:29:03 -07:00
|
|
|
window.addEventListener("message", onMessage);
|
|
|
|
|
2014-03-26 16:04:20 -07:00
|
|
|
let transport = DebuggerServer.connectPipe();
|
|
|
|
gClient = new DebuggerClient(transport);
|
|
|
|
|
|
|
|
let connected = promise.defer();
|
|
|
|
gClient.connect(connected.resolve);
|
|
|
|
yield connected.promise;
|
|
|
|
|
|
|
|
yield installAddon();
|
|
|
|
let debuggerPanel = yield initAddonDebugger(gClient, ADDON4_URL, iframe);
|
|
|
|
gDebugger = debuggerPanel.panelWin;
|
|
|
|
gThreadClient = gDebugger.gThreadClient;
|
|
|
|
gSources = gDebugger.DebuggerView.Sources;
|
|
|
|
|
|
|
|
yield testSources(false);
|
|
|
|
|
|
|
|
Cu.import("resource://browser_dbg_addon4/test2.jsm", {});
|
|
|
|
|
|
|
|
yield testSources(true);
|
|
|
|
|
|
|
|
Cu.unload("resource://browser_dbg_addon4/test2.jsm");
|
|
|
|
|
|
|
|
yield uninstallAddon();
|
|
|
|
yield closeConnection();
|
|
|
|
yield debuggerPanel._toolbox.destroy();
|
|
|
|
iframe.remove();
|
2014-03-27 10:29:03 -07:00
|
|
|
window.removeEventListener("message", onMessage);
|
2014-03-26 16:04:20 -07:00
|
|
|
finish();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function installAddon () {
|
|
|
|
return addAddon(ADDON4_URL).then(aAddon => {
|
|
|
|
gAddon = aAddon;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSources(expectSecondModule) {
|
|
|
|
let deferred = promise.defer();
|
|
|
|
let foundAddonModule = false;
|
|
|
|
let foundAddonModule2 = false;
|
|
|
|
let foundAddonBootstrap = false;
|
|
|
|
|
|
|
|
gThreadClient.getSources(({sources}) => {
|
|
|
|
ok(sources.length, "retrieved sources");
|
|
|
|
|
2014-03-27 09:02:39 -07:00
|
|
|
for (let source of sources) {
|
2014-03-26 16:04:20 -07:00
|
|
|
let url = source.url.split(" -> ").pop();
|
|
|
|
let { label, group } = gSources.getItemByValue(source.url).attachment;
|
|
|
|
|
|
|
|
if (url.indexOf("resource://browser_dbg_addon4/test.jsm") === 0) {
|
|
|
|
is(label, "test.jsm", "correct label for addon code");
|
2014-03-31 10:19:15 -07:00
|
|
|
is(group, "browser_dbg_addon4@tests.mozilla.org", "addon module is in the add-on's group");
|
2014-03-26 16:04:20 -07:00
|
|
|
foundAddonModule = true;
|
|
|
|
} else if (url.indexOf("resource://browser_dbg_addon4/test2.jsm") === 0) {
|
|
|
|
is(label, "test2.jsm", "correct label for addon code");
|
2014-03-31 10:19:15 -07:00
|
|
|
is(group, "browser_dbg_addon4@tests.mozilla.org", "addon module is in the add-on's group");
|
2014-03-26 16:04:20 -07:00
|
|
|
foundAddonModule2 = true;
|
|
|
|
} else if (url.endsWith("/browser_dbg_addon4@tests.mozilla.org.xpi!/bootstrap.js")) {
|
|
|
|
is(label, "bootstrap.js", "correct label for bootstrap code");
|
2014-03-31 10:19:15 -07:00
|
|
|
is(group, "browser_dbg_addon4@tests.mozilla.org", "addon bootstrap script is in the add-on's group");
|
2014-03-26 16:04:20 -07:00
|
|
|
foundAddonBootstrap = true;
|
|
|
|
} else {
|
|
|
|
ok(false, "Saw an unexpected source: " + url);
|
|
|
|
}
|
2014-03-27 09:02:39 -07:00
|
|
|
}
|
2014-03-26 16:04:20 -07:00
|
|
|
|
|
|
|
ok(foundAddonModule, "found JS module for the addon in the list");
|
|
|
|
is(foundAddonModule2, expectSecondModule, "saw the second addon module");
|
|
|
|
ok(foundAddonBootstrap, "found bootstrap script for the addon in the list");
|
|
|
|
|
2014-03-27 10:29:03 -07:00
|
|
|
is(gTitle, "Debugger - Test add-on with JS Modules", "Saw the right toolbox title.");
|
|
|
|
|
2014-03-27 11:35:14 -07:00
|
|
|
let groups = gDebugger.document.querySelectorAll(".side-menu-widget-group-title .name");
|
2014-03-31 10:19:15 -07:00
|
|
|
is(groups[0].value, "browser_dbg_addon4@tests.mozilla.org", "Add-on code should be the first group");
|
|
|
|
is(groups.length, 1, "Should be only one group.");
|
2014-03-27 11:35:14 -07:00
|
|
|
|
2014-03-26 16:04:20 -07:00
|
|
|
deferred.resolve();
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
function uninstallAddon() {
|
|
|
|
return removeAddon(gAddon);
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeConnection () {
|
|
|
|
let deferred = promise.defer();
|
|
|
|
gClient.close(deferred.resolve);
|
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
registerCleanupFunction(function() {
|
|
|
|
gClient = null;
|
|
|
|
gAddon = null;
|
|
|
|
gThreadClient = null;
|
|
|
|
gDebugger = null;
|
|
|
|
gSources = null;
|
2014-03-31 10:19:15 -07:00
|
|
|
while (gBrowser.tabs.length > 1) {
|
2014-03-26 16:04:20 -07:00
|
|
|
gBrowser.removeCurrentTab();
|
2014-03-31 10:19:15 -07:00
|
|
|
}
|
2014-03-26 16:04:20 -07:00
|
|
|
});
|