browser_dbg_stack-05.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 that switching between stack frames properly sets the current debugger
  6. * location in the source editor.
  7. */
  8. const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
  9. function test() {
  10. let options = {
  11. source: EXAMPLE_URL + "code_script-switching-01.js",
  12. line: 1
  13. };
  14. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  15. const gTab = aTab;
  16. const gPanel = aPanel;
  17. const gDebugger = gPanel.panelWin;
  18. const gEditor = gDebugger.DebuggerView.editor;
  19. const gSources = gDebugger.DebuggerView.Sources;
  20. const gFrames = gDebugger.DebuggerView.StackFrames;
  21. const gClassicFrames = gDebugger.DebuggerView.StackFramesClassicList;
  22. function initialChecks() {
  23. is(gDebugger.gThreadClient.state, "paused",
  24. "Should only be getting stack frames while paused.");
  25. is(gFrames.itemCount, 2,
  26. "Should have four frames.");
  27. is(gClassicFrames.itemCount, 2,
  28. "Should also have four frames in the mirrored view.");
  29. }
  30. function testNewestFrame() {
  31. is(gFrames.selectedIndex, 1,
  32. "Newest frame should be selected by default.");
  33. is(gClassicFrames.selectedIndex, 0,
  34. "Newest frame should be selected in the mirrored view as well.");
  35. is(gSources.selectedIndex, 1,
  36. "The second source is selected in the widget.");
  37. ok(isCaretPos(gPanel, 6),
  38. "Editor caret location is correct.");
  39. is(gEditor.getDebugLocation(), 5,
  40. "Editor debug location is correct.");
  41. }
  42. function testOldestFrame() {
  43. const shown = waitForSourceAndCaret(gPanel, "-01.js", 5).then(() => {
  44. is(gFrames.selectedIndex, 0,
  45. "Second frame should be selected after click.");
  46. is(gClassicFrames.selectedIndex, 1,
  47. "Second frame should be selected in the mirrored view as well.");
  48. is(gSources.selectedIndex, 0,
  49. "The first source is now selected in the widget.");
  50. ok(isCaretPos(gPanel, 5),
  51. "Editor caret location is correct (3).");
  52. is(gEditor.getDebugLocation(), 4,
  53. "Editor debug location is correct.");
  54. });
  55. EventUtils.sendMouseEvent({ type: "mousedown" },
  56. gDebugger.document.querySelector("#stackframe-1"),
  57. gDebugger);
  58. return shown;
  59. }
  60. function testAfterResume() {
  61. let deferred = promise.defer();
  62. gDebugger.once(gDebugger.EVENTS.AFTER_FRAMES_CLEARED, () => {
  63. is(gFrames.itemCount, 0,
  64. "Should have no frames after resume.");
  65. is(gClassicFrames.itemCount, 0,
  66. "Should have no frames in the mirrored view as well.");
  67. ok(isCaretPos(gPanel, 5),
  68. "Editor caret location is correct after resume.");
  69. is(gEditor.getDebugLocation(), null,
  70. "Editor debug location is correct after resume.");
  71. deferred.resolve();
  72. }, true);
  73. gDebugger.gThreadClient.resume();
  74. return deferred.promise;
  75. }
  76. Task.spawn(function* () {
  77. yield waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6);
  78. yield initialChecks();
  79. yield testNewestFrame();
  80. yield testOldestFrame();
  81. yield testAfterResume();
  82. closeDebuggerAndFinish(gPanel);
  83. });
  84. callInTab(gTab, "firstCall");
  85. });
  86. }