browser_dbg_break-on-next.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 'break on next' functionality works from executions
  6. * in content that are triggered by the page.
  7. */
  8. const TAB_URL = EXAMPLE_URL + "doc_script-eval.html";
  9. function test() {
  10. let gTab, gPanel, gDebugger;
  11. let gSources, gBreakpoints, gTarget, gResumeButton, gResumeKey, gThreadClient;
  12. const options = {
  13. source: EXAMPLE_URL + "code_script-eval.js",
  14. line: 1
  15. };
  16. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  17. gTab = aTab;
  18. gPanel = aPanel;
  19. gDebugger = gPanel.panelWin;
  20. gSources = gDebugger.DebuggerView.Sources;
  21. gTarget = gDebugger.gTarget;
  22. gThreadClient = gDebugger.gThreadClient;
  23. gResumeButton = gDebugger.document.getElementById("resume");
  24. gResumeKey = gDebugger.document.getElementById("resumeKey");
  25. testInterval()
  26. .then(testEvent)
  27. .then(() => closeDebuggerAndFinish(gPanel));
  28. });
  29. // Testing an interval instead of a timeout / rAF because
  30. // it's less likely to fail due to timing issues. If the
  31. // first callback happens to fire before the break request
  32. // happens then we'll just get it next time.
  33. let testInterval = Task.async(function* () {
  34. info("Starting testInterval");
  35. yield evalInTab(gTab, `
  36. var interval = setInterval(function() {
  37. return 1+1;
  38. }, 100);
  39. `);
  40. let oncePaused = gTarget.once("thread-paused");
  41. EventUtils.sendMouseEvent({ type: "mousedown" }, gResumeButton, gDebugger);
  42. yield oncePaused;
  43. yield waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN);
  44. let variables = gDebugger.DebuggerView.Variables;
  45. is(variables._store.length, 3, "Correct number of scopes available");
  46. is(variables.getScopeAtIndex(0).name, "Function scope [interval<]",
  47. "Paused with correct scope (0)");
  48. is(variables.getScopeAtIndex(1).name, "Block scope",
  49. "Paused with correct scope (1)");
  50. is(variables.getScopeAtIndex(2).name, "Global scope [Window]",
  51. "Paused with correct scope (2)");
  52. yield evalInTab(gTab, "clearInterval(interval)");
  53. let onceResumed = gTarget.once("thread-resumed");
  54. EventUtils.sendMouseEvent({ type: "mousedown" }, gResumeButton, gDebugger);
  55. yield onceResumed;
  56. });
  57. let testEvent = Task.async(function* () {
  58. info("Starting testEvent");
  59. let oncePaused = gTarget.once("thread-paused");
  60. EventUtils.sendMouseEvent({ type: "mousedown" }, gResumeButton, gDebugger);
  61. once(gDebugger.gClient, "willInterrupt").then(() => {
  62. generateMouseClickInTab(gTab, "content.document.querySelector('button')");
  63. });
  64. yield oncePaused;
  65. yield waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN);
  66. let variables = gDebugger.DebuggerView.Variables;
  67. is(variables._store.length, 6, "Correct number of scopes available");
  68. is(variables.getScopeAtIndex(0).name, "Function scope [onclick]",
  69. "Paused with correct scope (0)");
  70. // Non-syntactic lexical scope introduced by non-syntactic scope chain.
  71. is(variables.getScopeAtIndex(1).name, "Block scope",
  72. "Paused with correct scope (1)");
  73. is(variables.getScopeAtIndex(2).name, "With scope [HTMLButtonElement]",
  74. "Paused with correct scope (2)");
  75. is(variables.getScopeAtIndex(3).name, "With scope [HTMLDocument]",
  76. "Paused with correct scope (3)");
  77. // Global lexical scope.
  78. is(variables.getScopeAtIndex(4).name, "Block scope",
  79. "Paused with correct scope (4)");
  80. is(variables.getScopeAtIndex(5).name, "Global scope [Window]",
  81. "Paused with correct scope (5)");
  82. let onceResumed = gTarget.once("thread-resumed");
  83. EventUtils.sendMouseEvent({ type: "mousedown" }, gResumeButton, gDebugger);
  84. yield onceResumed;
  85. });
  86. }