browser_dbg_breakpoints-highlight.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. * Test if breakpoints are highlighted when they should.
  6. */
  7. const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
  8. function test() {
  9. let options = {
  10. source: EXAMPLE_URL + "code_script-switching-01.js",
  11. line: 1
  12. };
  13. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  14. const gTab = aTab;
  15. const gPanel = aPanel;
  16. const gDebugger = gPanel.panelWin;
  17. const gEditor = gDebugger.DebuggerView.editor;
  18. const gSources = gDebugger.DebuggerView.Sources;
  19. const queries = gDebugger.require("./content/queries");
  20. const actions = bindActionCreators(gPanel);
  21. const getState = gDebugger.DebuggerController.getState;
  22. const addBreakpoints = Task.async(function* () {
  23. yield actions.addBreakpoint({ actor: gSources.values[0], line: 5 });
  24. yield actions.addBreakpoint({ actor: gSources.values[1], line: 6 });
  25. yield actions.addBreakpoint({ actor: gSources.values[1], line: 7 });
  26. yield actions.addBreakpoint({ actor: gSources.values[1], line: 8 });
  27. yield actions.addBreakpoint({ actor: gSources.values[1], line: 9 });
  28. });
  29. function clickBreakpointAndCheck(aBreakpointIndex, aSourceIndex, aCaretLine) {
  30. let finished = waitForCaretUpdated(gPanel, aCaretLine).then(() => {
  31. checkHighlight(gSources.values[aSourceIndex], aCaretLine);
  32. checkEditorContents(aSourceIndex);
  33. is(queries.getSelectedSource(getState()).actor,
  34. gSources.items[aSourceIndex].value,
  35. "The currently selected source value is incorrect (1).");
  36. ok(isCaretPos(gPanel, aCaretLine),
  37. "The editor caret line and column were incorrect (1).");
  38. });
  39. EventUtils.sendMouseEvent(
  40. { type: "click" },
  41. gDebugger.document.querySelectorAll(".dbg-breakpoint")[aBreakpointIndex],
  42. gDebugger
  43. );
  44. return finished;
  45. }
  46. function checkHighlight(actor, line) {
  47. let breakpoint = gSources._selectedBreakpoint;
  48. let breakpointItem = gSources._getBreakpoint(breakpoint);
  49. is(breakpoint.location.actor, actor,
  50. "The currently selected breakpoint actor is incorrect.");
  51. is(breakpoint.location.line, line,
  52. "The currently selected breakpoint line is incorrect.");
  53. is(breakpointItem.attachment.actor, actor,
  54. "The selected breakpoint item's source location attachment is incorrect.");
  55. ok(breakpointItem.target.classList.contains("selected"),
  56. "The selected breakpoint item's target should have a selected class.");
  57. }
  58. function checkEditorContents(aSourceIndex) {
  59. if (aSourceIndex == 0) {
  60. is(gEditor.getText().indexOf("firstCall"), 118,
  61. "The first source is correctly displayed.");
  62. } else {
  63. is(gEditor.getText().indexOf("debugger"), 166,
  64. "The second source is correctly displayed.");
  65. }
  66. }
  67. Task.spawn(function* () {
  68. yield addBreakpoints();
  69. yield clickBreakpointAndCheck(0, 0, 5);
  70. yield clickBreakpointAndCheck(1, 1, 6);
  71. yield clickBreakpointAndCheck(2, 1, 7);
  72. yield clickBreakpointAndCheck(3, 1, 8);
  73. yield clickBreakpointAndCheck(4, 1, 9);
  74. closeDebuggerAndFinish(gPanel);
  75. });
  76. });
  77. }