browser_target_events.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. var target;
  5. function test()
  6. {
  7. waitForExplicitFinish();
  8. gBrowser.selectedTab = gBrowser.addTab();
  9. BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(onLoad);
  10. }
  11. function onLoad() {
  12. target = TargetFactory.forTab(gBrowser.selectedTab);
  13. is(target.tab, gBrowser.selectedTab, "Target linked to the right tab.");
  14. target.once("hidden", onHidden);
  15. gBrowser.selectedTab = gBrowser.addTab();
  16. }
  17. function onHidden() {
  18. ok(true, "Hidden event received");
  19. target.once("visible", onVisible);
  20. gBrowser.removeCurrentTab();
  21. }
  22. function onVisible() {
  23. ok(true, "Visible event received");
  24. target.once("will-navigate", onWillNavigate);
  25. let mm = getFrameScript();
  26. mm.sendAsyncMessage("devtools:test:navigate", { location: "data:text/html,<meta charset='utf8'/>test navigation" });
  27. }
  28. function onWillNavigate(event, request) {
  29. ok(true, "will-navigate event received");
  30. // Wait for navigation handling to complete before removing the tab, in order
  31. // to avoid triggering assertions.
  32. target.once("navigate", executeSoon.bind(null, onNavigate));
  33. }
  34. function onNavigate() {
  35. ok(true, "navigate event received");
  36. target.once("close", onClose);
  37. gBrowser.removeCurrentTab();
  38. }
  39. function onClose() {
  40. ok(true, "close event received");
  41. target = null;
  42. finish();
  43. }