diff --git a/devtools/client/aboutdebugging/test/addons/unpacked/bootstrap.js b/devtools/client/aboutdebugging/test/addons/unpacked/bootstrap.js index 396e829f780f..d96e31e5e894 100644 --- a/devtools/client/aboutdebugging/test/addons/unpacked/bootstrap.js +++ b/devtools/client/aboutdebugging/test/addons/unpacked/bootstrap.js @@ -7,6 +7,13 @@ "use strict"; Components.utils.import("resource://gre/modules/Services.jsm"); + +// This function is called from the webconsole test: +// browser_addons_debug_bootstrapped.js +function myBootstrapAddonFunction() { // eslint-disable-line no-unused-vars + Services.obs.notifyObservers(null, "addon-console-works", null); +} + function startup() { Services.obs.notifyObservers(null, "test-devtools", null); } diff --git a/devtools/client/aboutdebugging/test/browser.ini b/devtools/client/aboutdebugging/test/browser.ini index 04efc1383562..c32acb29eaca 100644 --- a/devtools/client/aboutdebugging/test/browser.ini +++ b/devtools/client/aboutdebugging/test/browser.ini @@ -11,6 +11,7 @@ support-files = service-workers/push-sw.html service-workers/push-sw.js +[browser_addons_debug_bootstrapped.js] [browser_addons_debugging_initial_state.js] [browser_addons_install.js] [browser_addons_toggle_debug.js] diff --git a/devtools/client/aboutdebugging/test/browser_addons_debug_bootstrapped.js b/devtools/client/aboutdebugging/test/browser_addons_debug_bootstrapped.js new file mode 100644 index 000000000000..99a775e5aabf --- /dev/null +++ b/devtools/client/aboutdebugging/test/browser_addons_debug_bootstrapped.js @@ -0,0 +1,76 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +const ADDON_ID = "test-devtools@mozilla.org"; +const ADDON_NAME = "test-devtools"; + +const { BrowserToolboxProcess } = Cu.import("resource://devtools/client/framework/ToolboxProcess.jsm", {}); + +add_task(function* () { + yield new Promise(resolve => { + let options = {"set": [ + // Force enabling of addons debugging + ["devtools.chrome.enabled", true], + ["devtools.debugger.remote-enabled", true], + // Disable security prompt + ["devtools.debugger.prompt-connection", false], + // Enable Browser toolbox test script execution via env variable + ["devtools.browser-toolbox.allow-unsafe-script", true], + ]}; + SpecialPowers.pushPrefEnv(options, resolve); + }); + + let { tab, document } = yield openAboutDebugging("addons"); + yield installAddon(document, "addons/unpacked/install.rdf", ADDON_NAME, + "test-devtools"); + + // Retrieve the DEBUG button for the addon + let names = [...document.querySelectorAll("#addons .target-name")]; + let name = names.filter(element => element.textContent === ADDON_NAME)[0]; + ok(name, "Found the addon in the list"); + let targetElement = name.parentNode.parentNode; + let debugBtn = targetElement.querySelector(".debug-button"); + ok(debugBtn, "Found its debug button"); + + // Wait for a notification sent by a script evaluated the test addon via + // the web console. + let onCustomMessage = new Promise(done => { + Services.obs.addObserver(function listener() { + Services.obs.removeObserver(listener, "addon-console-works"); + done(); + }, "addon-console-works", false); + }); + + // Be careful, this JS function is going to be executed in the addon toolbox, + // which lives in another process. So do not try to use any scope variable! + let env = Cc["@mozilla.org/process/environment;1"] + .getService(Ci.nsIEnvironment); + let testScript = function() { + /* eslint-disable no-undef */ + toolbox.selectTool("webconsole") + .then(console => { + let { jsterm } = console.hud; + return jsterm.execute("myBootstrapAddonFunction()"); + }) + .then(() => toolbox.destroy()); + /* eslint-enable no-undef */ + }; + env.set("MOZ_TOOLBOX_TEST_SCRIPT", "new " + testScript); + registerCleanupFunction(() => { + env.set("MOZ_TOOLBOX_TEST_SCRIPT", ""); + }); + + let onToolboxClose = BrowserToolboxProcess.once("close"); + + debugBtn.click(); + + yield onCustomMessage; + ok(true, "Received the notification message from the bootstrap.js function"); + + yield onToolboxClose; + ok(true, "Addon toolbox closed"); + + yield uninstallAddon(document, ADDON_ID, ADDON_NAME); + yield closeAboutDebugging(tab); +});