summaryrefslogtreecommitdiffstats
path: root/devtools/client/memory/test/unit/test_action-toggle-recording-allocations.js
blob: ebbc171736154d715c61539e7f1b234a0dfbd216 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

/**
 * Test toggling the recording of allocation stacks.
 */

let { toggleRecordingAllocationStacks } = require("devtools/client/memory/actions/allocations");

function run_test() {
  run_next_test();
}

add_task(function* () {
  let front = new StubbedMemoryFront();
  yield front.attach();
  let store = Store();
  const { getState, dispatch } = store;

  equal(getState().allocations.recording, false, "not recording by default");
  equal(getState().allocations.togglingInProgress, false,
        "not in the process of toggling by default");

  dispatch(toggleRecordingAllocationStacks(front));
  yield waitUntilState(store, () => getState().allocations.togglingInProgress);
  ok(true, "`togglingInProgress` set to true when toggling on");
  yield waitUntilState(store, () => !getState().allocations.togglingInProgress);

  equal(getState().allocations.recording, true, "now we are recording");
  ok(front.recordingAllocations, "front is recording too");

  dispatch(toggleRecordingAllocationStacks(front));
  yield waitUntilState(store, () => getState().allocations.togglingInProgress);
  ok(true, "`togglingInProgress` set to true when toggling off");
  yield waitUntilState(store, () => !getState().allocations.togglingInProgress);

  equal(getState().allocations.recording, false, "now we are not recording");
  ok(front.recordingAllocations, "front is not recording anymore");

  yield front.detach();
});