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

"use strict";

/**
 * Tests the async reducer responding to the action `takeSnapshot(front)`
 */

const actions = require("resource://devtools/client/memory/actions/snapshot.js");
const {
  snapshotState: states,
} = require("resource://devtools/client/memory/constants.js");

add_task(async function () {
  const front = new StubbedMemoryFront();
  await front.attach();
  const store = Store();

  const unsubscribe = store.subscribe(checkState);

  let foundPendingState = false;
  let foundDoneState = false;

  function checkState() {
    const { snapshots } = store.getState();
    const lastSnapshot = snapshots[snapshots.length - 1];

    if (lastSnapshot.state === states.SAVING) {
      foundPendingState = true;
      ok(
        foundPendingState,
        "Got state change for pending heap snapshot request"
      );
      ok(!lastSnapshot.path, "Snapshot does not yet have a path");
      ok(!lastSnapshot.census, "Has no census data when loading");
    } else if (lastSnapshot.state === states.SAVED) {
      foundDoneState = true;
      ok(
        foundDoneState,
        "Got state change for completed heap snapshot request"
      );
      ok(foundPendingState, "SAVED state occurs after SAVING state");
      ok(lastSnapshot.path, "Snapshot fetched with a path");
      ok(
        snapshots.every(s => s.selected === (s.id === lastSnapshot.id)),
        "Only recent snapshot is selected"
      );
    }
  }

  for (let i = 0; i < 4; i++) {
    store.dispatch(actions.takeSnapshot(front));
    await waitUntilState(store, () => foundPendingState && foundDoneState);

    // reset state trackers
    foundDoneState = foundPendingState = false;
  }

  unsubscribe();
});