browser_toolbox_highlight.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 {Toolbox} = require("devtools/client/framework/toolbox");
  5. var toolbox = null;
  6. function test() {
  7. const URL = "data:text/plain;charset=UTF-8,Nothing to see here, move along";
  8. const TOOL_ID_1 = "jsdebugger";
  9. const TOOL_ID_2 = "webconsole";
  10. addTab(URL).then(() => {
  11. let target = TargetFactory.forTab(gBrowser.selectedTab);
  12. gDevTools.showToolbox(target, TOOL_ID_1, Toolbox.HostType.BOTTOM)
  13. .then(aToolbox => {
  14. toolbox = aToolbox;
  15. // select tool 2
  16. toolbox.selectTool(TOOL_ID_2)
  17. // and highlight the first one
  18. .then(highlightTab.bind(null, TOOL_ID_1))
  19. // to see if it has the proper class.
  20. .then(checkHighlighted.bind(null, TOOL_ID_1))
  21. // Now switch back to first tool
  22. .then(() => toolbox.selectTool(TOOL_ID_1))
  23. // to check again. But there is no easy way to test if
  24. // it is showing orange or not.
  25. .then(checkNoHighlightWhenSelected.bind(null, TOOL_ID_1))
  26. // Switch to tool 2 again
  27. .then(() => toolbox.selectTool(TOOL_ID_2))
  28. // and check again.
  29. .then(checkHighlighted.bind(null, TOOL_ID_1))
  30. // Now unhighlight the tool
  31. .then(unhighlightTab.bind(null, TOOL_ID_1))
  32. // to see the classes gone.
  33. .then(checkNoHighlight.bind(null, TOOL_ID_1))
  34. // Now close the toolbox and exit.
  35. .then(() => executeSoon(() => {
  36. toolbox.destroy()
  37. .then(() => {
  38. toolbox = null;
  39. gBrowser.removeCurrentTab();
  40. finish();
  41. });
  42. }));
  43. });
  44. });
  45. }
  46. function highlightTab(toolId) {
  47. info("Highlighting tool " + toolId + "'s tab.");
  48. toolbox.highlightTool(toolId);
  49. }
  50. function unhighlightTab(toolId) {
  51. info("Unhighlighting tool " + toolId + "'s tab.");
  52. toolbox.unhighlightTool(toolId);
  53. }
  54. function checkHighlighted(toolId) {
  55. let tab = toolbox.doc.getElementById("toolbox-tab-" + toolId);
  56. ok(tab.hasAttribute("highlighted"), "The highlighted attribute is present");
  57. ok(!tab.hasAttribute("selected") || tab.getAttribute("selected") != "true",
  58. "The tab is not selected");
  59. }
  60. function checkNoHighlightWhenSelected(toolId) {
  61. let tab = toolbox.doc.getElementById("toolbox-tab-" + toolId);
  62. ok(tab.hasAttribute("highlighted"), "The highlighted attribute is present");
  63. ok(tab.hasAttribute("selected") && tab.getAttribute("selected") == "true",
  64. "and the tab is selected, so the orange glow will not be present.");
  65. }
  66. function checkNoHighlight(toolId) {
  67. let tab = toolbox.doc.getElementById("toolbox-tab-" + toolId);
  68. ok(!tab.hasAttribute("highlighted"),
  69. "The highlighted attribute is not present");
  70. }