browser_cmd_highlight_02.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Any copyright is dedicated to the Public Domain.
  2. * http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. // Tests that the highlight command actually creates a highlighter
  5. const TEST_PAGE = "data:text/html;charset=utf-8,<div></div>";
  6. function test() {
  7. return Task.spawn(function* () {
  8. let options = yield helpers.openTab(TEST_PAGE);
  9. yield helpers.openToolbar(options);
  10. info("highlighting the body node");
  11. yield runCommand("highlight body", options);
  12. is(yield getHighlighterNumber(), 1, "The highlighter element exists for body");
  13. info("highlighting the div node");
  14. yield runCommand("highlight div", options);
  15. is(yield getHighlighterNumber(), 1, "The highlighter element exists for div");
  16. info("highlighting the body node again, asking to keep the div");
  17. yield runCommand("highlight body --keep", options);
  18. is(yield getHighlighterNumber(), 2, "2 highlighter elements have been created");
  19. info("unhighlighting all nodes");
  20. yield runCommand("unhighlight", options);
  21. is(yield getHighlighterNumber(), 0, "All highlighters have been removed");
  22. yield helpers.closeToolbar(options);
  23. yield helpers.closeTab(options);
  24. }).then(finish, helpers.handleError);
  25. }
  26. function getHighlighterNumber() {
  27. return ContentTask.spawn(gBrowser.selectedBrowser, {}, function* () {
  28. const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
  29. return require("devtools/shared/gcli/commands/highlight").highlighters.length;
  30. });
  31. }
  32. function* runCommand(cmd, options) {
  33. yield helpers.audit(options, [{ setup: cmd, exec: {} }]);
  34. }