browser_dbg_controller-evaluate-02.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. * Tests the public evaluation API from the debugger controller.
  6. */
  7. const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
  8. function test() {
  9. Task.spawn(function* () {
  10. const options = {
  11. source: EXAMPLE_URL + "code_script-switching-01.js",
  12. line: 1
  13. };
  14. const [tab,, panel] = yield initDebugger(TAB_URL, options);
  15. const win = panel.panelWin;
  16. const frames = win.DebuggerController.StackFrames;
  17. const framesView = win.DebuggerView.StackFrames;
  18. const sourcesView = win.DebuggerView.Sources;
  19. const editorView = win.DebuggerView.editor;
  20. const events = win.EVENTS;
  21. const queries = win.require("./content/queries");
  22. const constants = win.require("./content/constants");
  23. const actions = bindActionCreators(panel);
  24. const getState = win.DebuggerController.getState;
  25. function checkView(selectedFrame, selectedSource, caretLine, editorText) {
  26. is(win.gThreadClient.state, "paused",
  27. "Should only be getting stack frames while paused.");
  28. is(framesView.itemCount, 2,
  29. "Should have four frames.");
  30. is(framesView.selectedDepth, selectedFrame,
  31. "The correct frame is selected in the widget.");
  32. is(sourcesView.selectedIndex, selectedSource,
  33. "The correct source is selected in the widget.");
  34. ok(isCaretPos(panel, caretLine),
  35. "Editor caret location is correct.");
  36. is(editorView.getText().search(editorText[0]), editorText[1],
  37. "The correct source is not displayed.");
  38. }
  39. // Cache the sources text to avoid having to wait for their
  40. // retrieval.
  41. const sources = queries.getSources(getState());
  42. yield promise.all(Object.keys(sources).map(k => {
  43. return actions.loadSourceText(sources[k]);
  44. }));
  45. // Allow this generator function to yield first.
  46. callInTab(tab, "firstCall");
  47. yield waitForSourceAndCaretAndScopes(panel, "-02.js", 6);
  48. checkView(0, 1, 6, [/secondCall/, 118]);
  49. // Change the selected frame and eval inside it.
  50. let updatedFrame = waitForDebuggerEvents(panel, events.FETCHED_SCOPES);
  51. framesView.selectedDepth = 1; // oldest frame
  52. yield updatedFrame;
  53. checkView(1, 0, 5, [/firstCall/, 118]);
  54. let updatedView = waitForDebuggerEvents(panel, events.FETCHED_SCOPES);
  55. try {
  56. yield frames.evaluate("foo");
  57. } catch (result) {
  58. is(result.return.type, "object", "The evaluation thrown type is correct.");
  59. is(result.return.class, "Error", "The evaluation thrown class is correct.");
  60. ok(!result.return, "The evaluation hasn't returned.");
  61. }
  62. yield updatedView;
  63. checkView(1, 0, 5, [/firstCall/, 118]);
  64. ok(true, "Evaluating while in a user-selected frame works properly.");
  65. yield resumeDebuggerThenCloseAndFinish(panel);
  66. });
  67. }