browser_addons_debug_bootstrapped.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. // Avoid test timeouts that can occur while waiting for the "addon-console-works" message.
  5. requestLongerTimeout(2);
  6. const ADDON_ID = "test-devtools@mozilla.org";
  7. const ADDON_NAME = "test-devtools";
  8. const { BrowserToolboxProcess } = Cu.import("resource://devtools/client/framework/ToolboxProcess.jsm", {});
  9. add_task(function* () {
  10. yield new Promise(resolve => {
  11. let options = {"set": [
  12. // Force enabling of addons debugging
  13. ["devtools.chrome.enabled", true],
  14. ["devtools.debugger.remote-enabled", true],
  15. // Disable security prompt
  16. ["devtools.debugger.prompt-connection", false],
  17. // Enable Browser toolbox test script execution via env variable
  18. ["devtools.browser-toolbox.allow-unsafe-script", true],
  19. ]};
  20. SpecialPowers.pushPrefEnv(options, resolve);
  21. });
  22. let { tab, document } = yield openAboutDebugging("addons");
  23. yield waitForInitialAddonList(document);
  24. yield installAddon({
  25. document,
  26. path: "addons/unpacked/install.rdf",
  27. name: ADDON_NAME,
  28. });
  29. // Retrieve the DEBUG button for the addon
  30. let names = [...document.querySelectorAll("#addons .target-name")];
  31. let name = names.filter(element => element.textContent === ADDON_NAME)[0];
  32. ok(name, "Found the addon in the list");
  33. let targetElement = name.parentNode.parentNode;
  34. let debugBtn = targetElement.querySelector(".debug-button");
  35. ok(debugBtn, "Found its debug button");
  36. // Wait for a notification sent by a script evaluated the test addon via
  37. // the web console.
  38. let onCustomMessage = new Promise(done => {
  39. Services.obs.addObserver(function listener() {
  40. Services.obs.removeObserver(listener, "addon-console-works");
  41. done();
  42. }, "addon-console-works", false);
  43. });
  44. // Be careful, this JS function is going to be executed in the addon toolbox,
  45. // which lives in another process. So do not try to use any scope variable!
  46. let env = Cc["@mozilla.org/process/environment;1"]
  47. .getService(Ci.nsIEnvironment);
  48. let testScript = function () {
  49. /* eslint-disable no-undef */
  50. toolbox.selectTool("webconsole")
  51. .then(console => {
  52. let { jsterm } = console.hud;
  53. return jsterm.execute("myBootstrapAddonFunction()");
  54. })
  55. .then(() => toolbox.destroy());
  56. /* eslint-enable no-undef */
  57. };
  58. env.set("MOZ_TOOLBOX_TEST_SCRIPT", "new " + testScript);
  59. registerCleanupFunction(() => {
  60. env.set("MOZ_TOOLBOX_TEST_SCRIPT", "");
  61. });
  62. let onToolboxClose = BrowserToolboxProcess.once("close");
  63. debugBtn.click();
  64. yield onCustomMessage;
  65. ok(true, "Received the notification message from the bootstrap.js function");
  66. yield onToolboxClose;
  67. ok(true, "Addon toolbox closed");
  68. yield uninstallAddon({document, id: ADDON_ID, name: ADDON_NAME});
  69. yield closeAboutDebugging(tab);
  70. });