summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_jsterm_autocomplete_in_debugger_stackframe.js
blob: 3ac24ba0748c99d8f1cbd212b9f02e675f906896 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Test that makes sure web console autocomplete happens in the user-selected
// stackframe from the js debugger.

"use strict";

const TEST_URI =
  "http://example.com/browser/devtools/client/webconsole/" +
  "test/browser/test-autocomplete-in-stackframe.html";

requestLongerTimeout(20);

add_task(async function () {
  const hud = await openNewTabAndConsole(TEST_URI);
  const { jsterm } = hud;
  const { autocompletePopup: popup } = jsterm;

  const toolbox = gDevTools.getToolboxForTab(gBrowser.selectedTab);

  const jstermComplete = value => setInputValueForAutocompletion(hud, value);

  // Test that document.title gives string methods. Native getters must execute.
  await jstermComplete("document.title.");

  const newItemsLabels = getAutocompletePopupLabels(popup);
  ok(!!newItemsLabels.length, "'document.title.' gave a list of suggestions");
  ok(newItemsLabels.includes("substr"), `results do contain "substr"`);
  ok(
    newItemsLabels.includes("toLowerCase"),
    `results do contain "toLowerCase"`
  );
  ok(newItemsLabels.includes("strike"), `results do contain "strike"`);

  // Test if 'foo' gives 'foo1' but not 'foo2' or 'foo3'
  await jstermComplete("foo");
  ok(
    hasExactPopupLabels(popup, ["foo1", "foo1Obj"]),
    `"foo" gave the expected suggestions`
  );

  // Test if 'foo1Obj.' gives 'prop1' and 'prop2'
  await jstermComplete("foo1Obj.");
  checkInputCompletionValue(hud, "method", "foo1Obj completion");
  ok(
    hasExactPopupLabels(popup, ["method", "prop1", "prop2"]),
    `"foo1Obj." gave the expected suggestions`
  );

  // Test if 'foo1Obj.prop2.' gives 'prop21'
  await jstermComplete("foo1Obj.prop2.");
  ok(
    hasPopupLabel(popup, "prop21"),
    `"foo1Obj.prop2." gave the expected suggestions`
  );
  await closeAutocompletePopup(hud);

  info("Opening Debugger");
  await openDebugger();
  const dbg = createDebuggerContext(toolbox);

  info("Waiting for pause");
  await pauseDebugger(dbg);
  const stackFrames = dbg.selectors.getCurrentThreadFrames();

  info("Opening Console again");
  await toolbox.selectTool("webconsole");

  // Test if 'this.' gives 'method', 'prop1', and 'prop2', not global variables, since we are paused in
  // `foo1Obj.method()` (called by `secondCall`)
  await jstermComplete("this.");
  ok(
    hasExactPopupLabels(popup, ["method", "prop1", "prop2"]),
    `"this." gave the expected suggestions`
  );

  await selectFrame(dbg, stackFrames[1]);

  // Test if 'foo' gives 'foo3' and 'foo1' but not 'foo2', since we are now in the `secondCall`
  // frame (called by `firstCall`, which we call in `pauseDebugger`).
  await jstermComplete("foo");
  ok(
    hasExactPopupLabels(popup, ["foo1", "foo1Obj", "foo3", "foo3Obj"]),
    `"foo." gave the expected suggestions`
  );

  // Test that 'shadowed.' autocompletes properties from the local variable named "shadowed".
  await jstermComplete("shadowed.");
  ok(
    hasExactPopupLabels(popup, ["bar"]),
    `"shadowed." gave the expected suggestions`
  );

  await openDebugger();

  // Select the frame for the `firstCall` function.
  await selectFrame(dbg, stackFrames[2]);

  info("openConsole");
  await toolbox.selectTool("webconsole");

  // Test if 'foo' gives 'foo2' and 'foo1' but not 'foo3', since we are now in the
  // `firstCall` frame.
  await jstermComplete("foo");
  ok(
    hasExactPopupLabels(popup, ["foo1", "foo1Obj", "foo2", "foo2Obj"]),
    `"foo" gave the expected suggestions`
  );

  // Test that 'shadowed.' autocompletes properties from the global variable named "shadowed".
  await jstermComplete("shadowed.");
  ok(
    hasExactPopupLabels(popup, ["foo"]),
    `"shadowed." gave the expected suggestions`
  );

  // Test if 'foo2Obj.' gives 'prop1'
  await jstermComplete("foo2Obj.");
  ok(hasPopupLabel(popup, "prop1"), `"foo2Obj." returns "prop1"`);

  // Test if 'foo2Obj.prop1.' gives 'prop11'
  await jstermComplete("foo2Obj.prop1.");
  ok(hasPopupLabel(popup, "prop11"), `"foo2Obj.prop1" returns "prop11"`);

  // Test if 'foo2Obj.prop1.prop11.' gives suggestions for a string,i.e. 'length'
  await jstermComplete("foo2Obj.prop1.prop11.");
  ok(hasPopupLabel(popup, "length"), `results do contain "length"`);

  // Test if 'foo2Obj[0].' throws no errors.
  await jstermComplete("foo2Obj[0].");
  is(getAutocompletePopupLabels(popup).length, 0, "no items for foo2Obj[0]");
});