browser_dbg_cmd-blackbox.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. /**
  5. * Tests that the 'dbg blackbox' and 'dbg unblackbox' commands work as
  6. * they should.
  7. */
  8. const TEST_URL = EXAMPLE_URL + "doc_blackboxing.html";
  9. const BLACKBOXME_URL = EXAMPLE_URL + "code_blackboxing_blackboxme.js";
  10. const BLACKBOXONE_URL = EXAMPLE_URL + "code_blackboxing_one.js";
  11. const BLACKBOXTWO_URL = EXAMPLE_URL + "code_blackboxing_two.js";
  12. const BLACKBOXTHREE_URL = EXAMPLE_URL + "code_blackboxing_three.js";
  13. function test() {
  14. return Task.spawn(spawnTest).then(finish, helpers.handleError);
  15. }
  16. function* spawnTest() {
  17. let options = yield helpers.openTab(TEST_URL);
  18. yield helpers.openToolbar(options);
  19. let toolbox = yield gDevTools.showToolbox(options.target, "jsdebugger");
  20. let panel = toolbox.getCurrentPanel();
  21. let constants = panel.panelWin.require("./content/constants");
  22. yield waitForDebuggerEvents(panel, panel.panelWin.EVENTS.SOURCE_SHOWN);
  23. function cmd(aTyped, aEventRepeat = 1, aOutput = "") {
  24. return promise.all([
  25. waitForDispatch(panel, constants.BLACKBOX, aEventRepeat),
  26. helpers.audit(options, [{ setup: aTyped, output: aOutput, exec: {} }])
  27. ]);
  28. }
  29. // test Black-Box Source
  30. yield cmd("dbg blackbox " + BLACKBOXME_URL);
  31. let bbButton = yield selectSourceAndGetBlackBoxButton(panel, BLACKBOXME_URL);
  32. ok(bbButton.checked,
  33. "Should be able to black box a specific source.");
  34. // test Un-Black-Box Source
  35. yield cmd("dbg unblackbox " + BLACKBOXME_URL);
  36. bbButton = yield selectSourceAndGetBlackBoxButton(panel, BLACKBOXME_URL);
  37. ok(!bbButton.checked,
  38. "Should be able to stop black boxing a specific source.");
  39. // test Black-Box Glob
  40. yield cmd("dbg blackbox --glob *blackboxing_t*.js", 2,
  41. [/blackboxing_three\.js/g, /blackboxing_two\.js/g]);
  42. bbButton = yield selectSourceAndGetBlackBoxButton(panel, BLACKBOXME_URL);
  43. ok(!bbButton.checked,
  44. "blackboxme should not be black boxed because it doesn't match the glob.");
  45. bbButton = yield selectSourceAndGetBlackBoxButton(panel, BLACKBOXONE_URL);
  46. ok(!bbButton.checked,
  47. "blackbox_one should not be black boxed because it doesn't match the glob.");
  48. bbButton = yield selectSourceAndGetBlackBoxButton(panel, BLACKBOXTWO_URL);
  49. ok(bbButton.checked,
  50. "blackbox_two should be black boxed because it matches the glob.");
  51. bbButton = yield selectSourceAndGetBlackBoxButton(panel, BLACKBOXTHREE_URL);
  52. ok(bbButton.checked,
  53. "blackbox_three should be black boxed because it matches the glob.");
  54. // test Un-Black-Box Glob
  55. yield cmd("dbg unblackbox --glob *blackboxing_t*.js", 2);
  56. bbButton = yield selectSourceAndGetBlackBoxButton(panel, BLACKBOXTWO_URL);
  57. ok(!bbButton.checked,
  58. "blackbox_two should be un-black boxed because it matches the glob.");
  59. bbButton = yield selectSourceAndGetBlackBoxButton(panel, BLACKBOXTHREE_URL);
  60. ok(!bbButton.checked,
  61. "blackbox_three should be un-black boxed because it matches the glob.");
  62. // test Black-Box Invert
  63. yield cmd("dbg blackbox --invert --glob *blackboxing_t*.js", 3,
  64. [/blackboxing_three\.js/g, /blackboxing_two\.js/g]);
  65. bbButton = yield selectSourceAndGetBlackBoxButton(panel, BLACKBOXME_URL);
  66. ok(bbButton.checked,
  67. "blackboxme should be black boxed because it doesn't match the glob.");
  68. bbButton = yield selectSourceAndGetBlackBoxButton(panel, BLACKBOXONE_URL);
  69. ok(bbButton.checked,
  70. "blackbox_one should be black boxed because it doesn't match the glob.");
  71. bbButton = yield selectSourceAndGetBlackBoxButton(panel, TEST_URL);
  72. ok(bbButton.checked,
  73. "TEST_URL should be black boxed because it doesn't match the glob.");
  74. bbButton = yield selectSourceAndGetBlackBoxButton(panel, BLACKBOXTWO_URL);
  75. ok(!bbButton.checked,
  76. "blackbox_two should not be black boxed because it matches the glob.");
  77. bbButton = yield selectSourceAndGetBlackBoxButton(panel, BLACKBOXTHREE_URL);
  78. ok(!bbButton.checked,
  79. "blackbox_three should not be black boxed because it matches the glob.");
  80. // test Un-Black-Box Invert
  81. yield cmd("dbg unblackbox --invert --glob *blackboxing_t*.js", 3);
  82. bbButton = yield selectSourceAndGetBlackBoxButton(panel, BLACKBOXME_URL);
  83. ok(!bbButton.checked,
  84. "blackboxme should be un-black boxed because it does not match the glob.");
  85. bbButton = yield selectSourceAndGetBlackBoxButton(panel, BLACKBOXONE_URL);
  86. ok(!bbButton.checked,
  87. "blackbox_one should be un-black boxed because it does not match the glob.");
  88. bbButton = yield selectSourceAndGetBlackBoxButton(panel, TEST_URL);
  89. ok(!bbButton.checked,
  90. "TEST_URL should be un-black boxed because it doesn't match the glob.");
  91. yield teardown(panel, { noTabRemoval: true });
  92. yield helpers.closeToolbar(options);
  93. yield helpers.closeTab(options);
  94. }