browser_toolbox_target.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/ */
  4. // Test about:devtools-toolbox?target which allows opening a toolbox in an
  5. // iframe while defining which document to debug by setting a `target`
  6. // attribute refering to the document to debug.
  7. add_task(function *() {
  8. // iframe loads the document to debug
  9. let iframe = document.createElement("browser");
  10. iframe.setAttribute("type", "content");
  11. document.documentElement.appendChild(iframe);
  12. let onLoad = once(iframe, "load", true);
  13. iframe.setAttribute("src", "data:text/html,document to debug");
  14. yield onLoad;
  15. is(iframe.contentWindow.document.body.innerHTML, "document to debug");
  16. // toolbox loads the toolbox document
  17. let toolboxIframe = document.createElement("iframe");
  18. document.documentElement.appendChild(toolboxIframe);
  19. // Important step to define which target to debug
  20. toolboxIframe.target = iframe;
  21. let onToolboxReady = gDevTools.once("toolbox-ready");
  22. onLoad = once(toolboxIframe, "load", true);
  23. toolboxIframe.setAttribute("src", "about:devtools-toolbox?target");
  24. yield onLoad;
  25. // Also wait for toolbox-ready, as toolbox document load isn't enough, there
  26. // is plenty of asynchronous steps during toolbox load
  27. info("Waiting for toolbox-ready");
  28. let toolbox = yield onToolboxReady;
  29. let onToolboxDestroyed = gDevTools.once("toolbox-destroyed");
  30. let onTabActorDetached = once(toolbox.target.client, "tabDetached");
  31. info("Removing the iframes");
  32. toolboxIframe.remove();
  33. // And wait for toolbox-destroyed as toolbox unload is also full of
  34. // asynchronous operation that outlast unload event
  35. info("Waiting for toolbox-destroyed");
  36. yield onToolboxDestroyed;
  37. info("Toolbox destroyed");
  38. // Also wait for tabDetached. Toolbox destroys the Target which calls
  39. // TabActor.detach(). But Target doesn't wait for detach's end to resolve.
  40. // Whereas it is quite important as it is a significant part of toolbox
  41. // cleanup. If we do not wait for it and starts removing debugged document,
  42. // the actor is still considered as being attached and continues processing
  43. // events.
  44. yield onTabActorDetached;
  45. iframe.remove();
  46. });