summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser_console_variables_view_filter.js
blob: 142410839741d414c1941ac8928c6392869f382d (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
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Check that variables view filter feature works fine in the console.

function props(view, prefix = "") {
  // First match only the visible one, not hidden by a search
  let visible = [...view].filter(([id, prop]) => prop._isMatch);
  // Then flatten the list into a list of strings
  // being the jsonpath of each attribute being visible in the view
  return visible.reduce((list, [id, prop]) => {
    list.push(prefix + id);
    return list.concat(props(prop, prefix + id + "."));
  }, []);
}

function assertAttrs(view, expected, message) {
  is(props(view).join(","), expected, message);
}

add_task(function* () {
  yield loadTab("data:text/html;charset=utf-8,webconsole-filter");

  let hud = yield openConsole();

  let jsterm = hud.jsterm;

  let fetched = jsterm.once("variablesview-fetched");

  yield jsterm.execute("inspect({ foo: { bar : \"baz\" } })");

  let view = yield fetched;
  let variablesView = view._variablesView;
  let searchbox = variablesView._searchboxNode;

  assertAttrs(view, "foo,__proto__",
              "To start with, we just see the top level foo attr");

  fetched = jsterm.once("variablesview-fetched");
  searchbox.value = "bar";
  searchbox.doCommand();
  view = yield fetched;

  assertAttrs(view, "",
              "If we don't manually expand nested attr, we don't see them");

  fetched = jsterm.once("variablesview-fetched");
  searchbox.value = "";
  searchbox.doCommand();
  view = yield fetched;

  assertAttrs(view, "foo",
              "If we reset the search, we get back to original state");

  yield [...view][0][1].expand();

  fetched = jsterm.once("variablesview-fetched");
  searchbox.value = "bar";
  searchbox.doCommand();
  view = yield fetched;

  assertAttrs(view, "foo,foo.bar", "Now if we expand, we see the nested attr");

  fetched = jsterm.once("variablesview-fetched");
  searchbox.value = "baz";
  searchbox.doCommand();
  view = yield fetched;

  assertAttrs(view, "foo,foo.bar", "We can also search for attr values");

  fetched = jsterm.once("variablesview-fetched");
  searchbox.value = "";
  searchbox.doCommand();
  view = yield fetched;

  assertAttrs(view, "foo",
              "If we reset again, we get back to original state again");
});