browser_browser_toolbox.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. // On debug test slave, it takes about 50s to run the test.
  4. requestLongerTimeout(4);
  5. add_task(function* runTest() {
  6. yield new Promise(done => {
  7. let options = {"set": [
  8. ["devtools.debugger.prompt-connection", false],
  9. ["devtools.debugger.remote-enabled", true],
  10. ["devtools.chrome.enabled", true],
  11. // Test-only pref to allow passing `testScript` argument to the browser
  12. // toolbox
  13. ["devtools.browser-toolbox.allow-unsafe-script", true],
  14. // On debug test slave, it takes more than the default time (20s)
  15. // to get a initialized console
  16. ["devtools.debugger.remote-timeout", 120000]
  17. ]};
  18. SpecialPowers.pushPrefEnv(options, done);
  19. });
  20. // Wait for a notification sent by a script evaluated in the webconsole
  21. // of the browser toolbox.
  22. let onCustomMessage = new Promise(done => {
  23. Services.obs.addObserver(function listener() {
  24. Services.obs.removeObserver(listener, "browser-toolbox-console-works");
  25. done();
  26. }, "browser-toolbox-console-works", false);
  27. });
  28. // Be careful, this JS function is going to be executed in the addon toolbox,
  29. // which lives in another process. So do not try to use any scope variable!
  30. let env = Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment);
  31. let testScript = function () {
  32. toolbox.selectTool("webconsole")
  33. .then(console => {
  34. let { jsterm } = console.hud;
  35. let js = "Services.obs.notifyObservers(null, 'browser-toolbox-console-works', null);";
  36. return jsterm.execute(js);
  37. })
  38. .then(() => toolbox.destroy());
  39. };
  40. env.set("MOZ_TOOLBOX_TEST_SCRIPT", "new " + testScript);
  41. registerCleanupFunction(() => {
  42. env.set("MOZ_TOOLBOX_TEST_SCRIPT", "");
  43. });
  44. let { BrowserToolboxProcess } = Cu.import("resource://devtools/client/framework/ToolboxProcess.jsm", {});
  45. let closePromise;
  46. yield new Promise(onRun => {
  47. closePromise = new Promise(onClose => {
  48. info("Opening the browser toolbox\n");
  49. BrowserToolboxProcess.init(onClose, onRun);
  50. });
  51. });
  52. ok(true, "Browser toolbox started\n");
  53. yield onCustomMessage;
  54. ok(true, "Received the custom message");
  55. yield closePromise;
  56. ok(true, "Browser toolbox process just closed");
  57. });