tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_action-set-display-and-refresh-02.js (1988B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Tests the task creator `setCensusDisplayAndRefreshAndRefresh()` for custom
      8 * displays.
      9 */
     10 
     11 const {
     12  censusState,
     13  viewState,
     14 } = require("resource://devtools/client/memory/constants.js");
     15 const {
     16  setCensusDisplayAndRefresh,
     17 } = require("resource://devtools/client/memory/actions/census-display.js");
     18 const {
     19  takeSnapshotAndCensus,
     20 } = require("resource://devtools/client/memory/actions/snapshot.js");
     21 const {
     22  changeView,
     23 } = require("resource://devtools/client/memory/actions/view.js");
     24 
     25 const CUSTOM = {
     26  displayName: "Custom",
     27  tooltip: "Custom tooltip",
     28  inverted: false,
     29  breakdown: {
     30    by: "internalType",
     31    then: { by: "count", bytes: true, count: false },
     32  },
     33 };
     34 
     35 add_task(async function () {
     36  const front = new StubbedMemoryFront();
     37  const heapWorker = new HeapAnalysesClient();
     38  await front.attach();
     39  const store = Store();
     40  const { getState, dispatch } = store;
     41 
     42  dispatch(changeView(viewState.CENSUS));
     43  dispatch(setCensusDisplayAndRefresh(heapWorker, CUSTOM));
     44  equal(
     45    getState().censusDisplay,
     46    CUSTOM,
     47    "CUSTOM display stored in display state."
     48  );
     49 
     50  dispatch(takeSnapshotAndCensus(front, heapWorker));
     51  await waitUntilCensusState(store, s => s.census, [censusState.SAVED]);
     52 
     53  equal(
     54    getState().snapshots[0].census.display,
     55    CUSTOM,
     56    "New snapshot stored CUSTOM display when done taking census"
     57  );
     58  ok(
     59    getState().snapshots[0].census.report.children.length,
     60    "Census has some children"
     61  );
     62  // Ensure we don't have `count` in any results
     63  ok(
     64    getState().snapshots[0].census.report.children.every(c => !c.count),
     65    "Census used CUSTOM display without counts"
     66  );
     67  // Ensure we do have `bytes` in the results
     68  ok(
     69    getState().snapshots[0].census.report.children.every(
     70      c => typeof c.bytes === "number"
     71    ),
     72    "Census used CUSTOM display with bytes"
     73  );
     74 });