browser_dbg_scripts-switching-01.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. * Make sure that switching the displayed source in the UI works as advertised.
  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 gLabel1 = "code_script-switching-01.js";
  20. const gLabel2 = "code_script-switching-02.js";
  21. function testSourcesDisplay() {
  22. let deferred = promise.defer();
  23. is(gSources.itemCount, 2,
  24. "Found the expected number of sources. (1)");
  25. is(gSources.items[0].target.querySelector(".dbg-source-item").getAttribute("tooltiptext"),
  26. EXAMPLE_URL + "code_script-switching-01.js",
  27. "The correct tooltip text is displayed for the first source. (1)");
  28. is(gSources.items[1].target.querySelector(".dbg-source-item").getAttribute("tooltiptext"),
  29. EXAMPLE_URL + "code_script-switching-02.js",
  30. "The correct tooltip text is displayed for the second source. (1)");
  31. ok(getSourceActor(gSources, EXAMPLE_URL + gLabel1),
  32. "First source url is incorrect. (1)");
  33. ok(getSourceActor(gSources, EXAMPLE_URL + gLabel2),
  34. "Second source url is incorrect. (1)");
  35. ok(gSources.getItemForAttachment(e => e.label == gLabel1),
  36. "First source label is incorrect. (1)");
  37. ok(gSources.getItemForAttachment(e => e.label == gLabel2),
  38. "Second source label is incorrect. (1)");
  39. ok(gSources.selectedItem,
  40. "There should be a selected item in the sources pane. (1)");
  41. is(getSelectedSourceURL(gSources), EXAMPLE_URL + gLabel2,
  42. "The selected value is the sources pane is incorrect. (1)");
  43. is(gEditor.getText().search(/firstCall/), -1,
  44. "The first source is not displayed. (1)");
  45. is(gEditor.getText().search(/debugger/), 166,
  46. "The second source is displayed. (1)");
  47. ok(isCaretPos(gPanel, 6),
  48. "Editor caret location is correct. (1)");
  49. // The editor's debug location takes a tick to update.
  50. is(gEditor.getDebugLocation(), 5,
  51. "Editor debugger location is correct. (1)");
  52. ok(gEditor.hasLineClass(5, "debug-line"),
  53. "The debugged line is highlighted appropriately (1).");
  54. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
  55. gSources.selectedIndex = 0;
  56. return deferred.promise;
  57. }
  58. function testSwitchPaused1() {
  59. let deferred = promise.defer();
  60. ok(gSources.selectedItem,
  61. "There should be a selected item in the sources pane. (2)");
  62. is(getSelectedSourceURL(gSources), EXAMPLE_URL + gLabel1,
  63. "The selected value is the sources pane is incorrect. (2)");
  64. is(gEditor.getText().search(/firstCall/), 118,
  65. "The first source is displayed. (2)");
  66. is(gEditor.getText().search(/debugger/), -1,
  67. "The second source is not displayed. (2)");
  68. // The editor's debug location takes a tick to update.
  69. ok(isCaretPos(gPanel, 1),
  70. "Editor caret location is correct. (2)");
  71. is(gEditor.getDebugLocation(), null,
  72. "Editor debugger location is correct. (2)");
  73. ok(!gEditor.hasLineClass(5, "debug-line"),
  74. "The debugged line highlight was removed. (2)");
  75. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
  76. gSources.selectedIndex = 1;
  77. return deferred.promise;
  78. }
  79. function testSwitchPaused2() {
  80. let deferred = promise.defer();
  81. ok(gSources.selectedItem,
  82. "There should be a selected item in the sources pane. (3)");
  83. is(getSelectedSourceURL(gSources), EXAMPLE_URL + gLabel2,
  84. "The selected value is the sources pane is incorrect. (3)");
  85. is(gEditor.getText().search(/firstCall/), -1,
  86. "The first source is not displayed. (3)");
  87. is(gEditor.getText().search(/debugger/), 166,
  88. "The second source is displayed. (3)");
  89. ok(isCaretPos(gPanel, 6),
  90. "Editor caret location is correct. (3)");
  91. is(gEditor.getDebugLocation(), 5,
  92. "Editor debugger location is correct. (3)");
  93. ok(gEditor.hasLineClass(5, "debug-line"),
  94. "The debugged line is highlighted appropriately (3).");
  95. // Step out twice.
  96. waitForThreadEvents(gPanel, "paused").then(() => {
  97. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
  98. gDebugger.gThreadClient.stepOut();
  99. });
  100. gDebugger.gThreadClient.stepOut();
  101. return deferred.promise;
  102. }
  103. function testSwitchRunning() {
  104. ok(gSources.selectedItem,
  105. "There should be a selected item in the sources pane. (4)");
  106. is(getSelectedSourceURL(gSources), EXAMPLE_URL + gLabel1,
  107. "The selected value is the sources pane is incorrect. (4)");
  108. is(gEditor.getText().search(/firstCall/), 118,
  109. "The first source is displayed. (4)");
  110. is(gEditor.getText().search(/debugger/), -1,
  111. "The second source is not displayed. (4)");
  112. ok(isCaretPos(gPanel, 6),
  113. "Editor caret location is correct. (4)");
  114. is(gEditor.getDebugLocation(), 5,
  115. "Editor debugger location is correct. (4)");
  116. ok(gEditor.hasLineClass(5, "debug-line"),
  117. "The debugged line is highlighted appropriately (3). (4)");
  118. }
  119. Task.spawn(function* () {
  120. const shown = waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1);
  121. callInTab(gTab, "firstCall");
  122. yield shown;
  123. yield testSourcesDisplay();
  124. yield testSwitchPaused1();
  125. yield testSwitchPaused2();
  126. yield testSwitchRunning();
  127. resumeDebuggerThenCloseAndFinish(gPanel);
  128. });
  129. });
  130. }