summaryrefslogtreecommitdiffstats
path: root/devtools/client/memory/test/browser/browser_memory_filter_01.js
blob: 448e2aaa914be1ba789f507328e1901f0e681e4c (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Sanity test that we can show allocation stack displays in the tree.

"use strict";

const {
  dominatorTreeState,
  snapshotState,
  viewState,
  censusState,
} = require("devtools/client/memory/constants");
const { changeViewAndRefresh, changeView } = require("devtools/client/memory/actions/view");

const TEST_URL = "http://example.com/browser/devtools/client/memory/test/browser/doc_steady_allocation.html";

this.test = makeMemoryTest(TEST_URL, function* ({ tab, panel }) {
  const heapWorker = panel.panelWin.gHeapAnalysesClient;
  const front = panel.panelWin.gFront;
  const store = panel.panelWin.gStore;
  const { getState, dispatch } = store;
  const doc = panel.panelWin.document;

  dispatch(changeView(viewState.CENSUS));

  const takeSnapshotButton = doc.getElementById("take-snapshot");
  EventUtils.synthesizeMouseAtCenter(takeSnapshotButton, {}, panel.panelWin);

  yield waitUntilState(store, state =>
    state.snapshots.length === 1 &&
    state.snapshots[0].census &&
    state.snapshots[0].census.state === censusState.SAVING);

  let filterInput = doc.getElementById("filter");
  EventUtils.synthesizeMouseAtCenter(filterInput, {}, panel.panelWin);
  EventUtils.sendString("js::Shape", panel.panelWin);

  yield waitUntilState(store, state =>
    state.snapshots.length === 1 &&
    state.snapshots[0].census &&
    state.snapshots[0].census.state === censusState.SAVING);
  ok(true, "adding a filter string should trigger census recompute");

  yield waitUntilState(store, state =>
    state.snapshots.length === 1 &&
    state.snapshots[0].census &&
    state.snapshots[0].census.state === censusState.SAVED);

  let nameElem = doc.querySelector(".heap-tree-item-field.heap-tree-item-name");
  ok(nameElem, "Should get a tree item row with a name");
  is(nameElem.textContent.trim(), "js::Shape", "the tree item should be the one we filtered for");
  is(filterInput.value, "js::Shape",
    "and filter input contains the user value");

  // Now switch the dominator view, then switch back to census view
  // and check that the filter word is still correctly applied
  dispatch(changeViewAndRefresh(viewState.DOMINATOR_TREE, heapWorker));
  ok(true, "change view to dominator tree");

  // Wait for the dominator tree to be computed and fetched.
  yield waitUntilDominatorTreeState(store, [dominatorTreeState.LOADED]);
  ok(true, "computed and fetched the dominator tree.");

  dispatch(changeViewAndRefresh(viewState.CENSUS, heapWorker));
  ok(true, "change view back to census");

  yield waitUntilState(store, state =>
    state.snapshots.length === 1 &&
    state.snapshots[0].census &&
    state.snapshots[0].census.state === censusState.SAVED);

  nameElem = doc.querySelector(".heap-tree-item-field.heap-tree-item-name");
  filterInput = doc.getElementById("filter");

  ok(nameElem, "Should still get a tree item row with a name");
  is(nameElem.textContent.trim(), "js::Shape",
    "the tree item should still be the one we filtered for");
  is(filterInput.value, "js::Shape",
    "and filter input still contains the user value");
});