browser_toolbox_hosts.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. "use strict";
  5. var {Toolbox} = require("devtools/client/framework/toolbox");
  6. var {SIDE, BOTTOM, WINDOW} = Toolbox.HostType;
  7. var toolbox, target;
  8. const URL = "data:text/html;charset=utf8,test for opening toolbox in different hosts";
  9. add_task(function* runTest() {
  10. info("Create a test tab and open the toolbox");
  11. let tab = yield addTab(URL);
  12. target = TargetFactory.forTab(tab);
  13. toolbox = yield gDevTools.showToolbox(target, "webconsole");
  14. yield testBottomHost();
  15. yield testSidebarHost();
  16. yield testWindowHost();
  17. yield testToolSelect();
  18. yield testDestroy();
  19. yield testRememberHost();
  20. yield testPreviousHost();
  21. yield toolbox.destroy();
  22. toolbox = target = null;
  23. gBrowser.removeCurrentTab();
  24. });
  25. function* testBottomHost() {
  26. checkHostType(toolbox, BOTTOM);
  27. // test UI presence
  28. let nbox = gBrowser.getNotificationBox();
  29. let iframe = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-bottom-iframe");
  30. ok(iframe, "toolbox bottom iframe exists");
  31. checkToolboxLoaded(iframe);
  32. }
  33. function* testSidebarHost() {
  34. yield toolbox.switchHost(SIDE);
  35. checkHostType(toolbox, SIDE);
  36. // test UI presence
  37. let nbox = gBrowser.getNotificationBox();
  38. let bottom = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-bottom-iframe");
  39. ok(!bottom, "toolbox bottom iframe doesn't exist");
  40. let iframe = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-side-iframe");
  41. ok(iframe, "toolbox side iframe exists");
  42. checkToolboxLoaded(iframe);
  43. }
  44. function* testWindowHost() {
  45. yield toolbox.switchHost(WINDOW);
  46. checkHostType(toolbox, WINDOW);
  47. let nbox = gBrowser.getNotificationBox();
  48. let sidebar = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-side-iframe");
  49. ok(!sidebar, "toolbox sidebar iframe doesn't exist");
  50. let win = Services.wm.getMostRecentWindow("devtools:toolbox");
  51. ok(win, "toolbox separate window exists");
  52. let iframe = win.document.getElementById("toolbox-iframe");
  53. checkToolboxLoaded(iframe);
  54. }
  55. function* testToolSelect() {
  56. // make sure we can load a tool after switching hosts
  57. yield toolbox.selectTool("inspector");
  58. }
  59. function* testDestroy() {
  60. yield toolbox.destroy();
  61. target = TargetFactory.forTab(gBrowser.selectedTab);
  62. toolbox = yield gDevTools.showToolbox(target);
  63. }
  64. function* testRememberHost() {
  65. // last host was the window - make sure it's the same when re-opening
  66. is(toolbox.hostType, WINDOW, "host remembered");
  67. let win = Services.wm.getMostRecentWindow("devtools:toolbox");
  68. ok(win, "toolbox separate window exists");
  69. }
  70. function* testPreviousHost() {
  71. // last host was the window - make sure it's the same when re-opening
  72. is(toolbox.hostType, WINDOW, "host remembered");
  73. info("Switching to side");
  74. yield toolbox.switchHost(SIDE);
  75. checkHostType(toolbox, SIDE, WINDOW);
  76. info("Switching to bottom");
  77. yield toolbox.switchHost(BOTTOM);
  78. checkHostType(toolbox, BOTTOM, SIDE);
  79. info("Switching from bottom to side");
  80. yield toolbox.switchToPreviousHost();
  81. checkHostType(toolbox, SIDE, BOTTOM);
  82. info("Switching from side to bottom");
  83. yield toolbox.switchToPreviousHost();
  84. checkHostType(toolbox, BOTTOM, SIDE);
  85. info("Switching to window");
  86. yield toolbox.switchHost(WINDOW);
  87. checkHostType(toolbox, WINDOW, BOTTOM);
  88. info("Switching from window to bottom");
  89. yield toolbox.switchToPreviousHost();
  90. checkHostType(toolbox, BOTTOM, WINDOW);
  91. info("Forcing the previous host to match the current (bottom)");
  92. Services.prefs.setCharPref("devtools.toolbox.previousHost", BOTTOM);
  93. info("Switching from bottom to side (since previous=current=bottom");
  94. yield toolbox.switchToPreviousHost();
  95. checkHostType(toolbox, SIDE, BOTTOM);
  96. info("Forcing the previous host to match the current (side)");
  97. Services.prefs.setCharPref("devtools.toolbox.previousHost", SIDE);
  98. info("Switching from side to bottom (since previous=current=side");
  99. yield toolbox.switchToPreviousHost();
  100. checkHostType(toolbox, BOTTOM, SIDE);
  101. }
  102. function checkToolboxLoaded(iframe) {
  103. let tabs = iframe.contentDocument.getElementById("toolbox-tabs");
  104. ok(tabs, "toolbox UI has been loaded into iframe");
  105. }