browser_toolbox_raise.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. const TEST_URL = "data:text/html,test for opening toolbox in different hosts";
  5. var {Toolbox} = require("devtools/client/framework/toolbox");
  6. var toolbox, tab1, tab2;
  7. function test() {
  8. addTab(TEST_URL).then(tab => {
  9. tab2 = gBrowser.addTab();
  10. let target = TargetFactory.forTab(tab);
  11. gDevTools.showToolbox(target)
  12. .then(testBottomHost, console.error)
  13. .then(null, console.error);
  14. });
  15. }
  16. function testBottomHost(aToolbox) {
  17. toolbox = aToolbox;
  18. // switch to another tab and test toolbox.raise()
  19. gBrowser.selectedTab = tab2;
  20. executeSoon(function () {
  21. is(gBrowser.selectedTab, tab2, "Correct tab is selected before calling raise");
  22. toolbox.raise();
  23. executeSoon(function () {
  24. is(gBrowser.selectedTab, tab1, "Correct tab was selected after calling raise");
  25. toolbox.switchHost(Toolbox.HostType.WINDOW).then(testWindowHost).then(null, console.error);
  26. });
  27. });
  28. }
  29. function testWindowHost() {
  30. // Make sure toolbox is not focused.
  31. window.addEventListener("focus", onFocus, true);
  32. // Need to wait for focus as otherwise window.focus() is overridden by
  33. // toolbox window getting focused first on Linux and Mac.
  34. let onToolboxFocus = () => {
  35. toolbox.win.parent.removeEventListener("focus", onToolboxFocus, true);
  36. info("focusing main window.");
  37. window.focus();
  38. };
  39. // Need to wait for toolbox window to get focus.
  40. toolbox.win.parent.addEventListener("focus", onToolboxFocus, true);
  41. }
  42. function onFocus() {
  43. info("Main window is focused before calling toolbox.raise()");
  44. window.removeEventListener("focus", onFocus, true);
  45. // Check if toolbox window got focus.
  46. let onToolboxFocusAgain = () => {
  47. toolbox.win.parent.removeEventListener("focus", onToolboxFocusAgain, false);
  48. ok(true, "Toolbox window is the focused window after calling toolbox.raise()");
  49. cleanup();
  50. };
  51. toolbox.win.parent.addEventListener("focus", onToolboxFocusAgain, false);
  52. // Now raise toolbox.
  53. toolbox.raise();
  54. }
  55. function cleanup() {
  56. Services.prefs.setCharPref("devtools.toolbox.host", Toolbox.HostType.BOTTOM);
  57. toolbox.destroy().then(function () {
  58. toolbox = null;
  59. gBrowser.removeCurrentTab();
  60. gBrowser.removeCurrentTab();
  61. finish();
  62. });
  63. }