tor-browser

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

test_action-set-display.js (2118B)


      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 action creator `setCensusDisplay()` for display changing. Does not
      8 * test refreshing the census information, check `setCensusDisplayAndRefresh`
      9 * action for that.
     10 */
     11 
     12 const {
     13  censusDisplays,
     14  censusState,
     15  viewState,
     16 } = require("resource://devtools/client/memory/constants.js");
     17 const {
     18  setCensusDisplay,
     19 } = require("resource://devtools/client/memory/actions/census-display.js");
     20 const {
     21  takeSnapshotAndCensus,
     22 } = require("resource://devtools/client/memory/actions/snapshot.js");
     23 const {
     24  changeView,
     25 } = require("resource://devtools/client/memory/actions/view.js");
     26 
     27 // We test setting an invalid display, which triggers an assertion failure.
     28 EXPECTED_DTU_ASSERT_FAILURE_COUNT = 1;
     29 
     30 add_task(async function () {
     31  const front = new StubbedMemoryFront();
     32  const heapWorker = new HeapAnalysesClient();
     33  await front.attach();
     34  const store = Store();
     35  const { getState, dispatch } = store;
     36 
     37  dispatch(changeView(viewState.CENSUS));
     38 
     39  // Test default display with no snapshots
     40  equal(
     41    getState().censusDisplay.breakdown.by,
     42    "coarseType",
     43    "default coarseType display selected at start."
     44  );
     45 
     46  dispatch(setCensusDisplay(censusDisplays.allocationStack));
     47  equal(
     48    getState().censusDisplay.breakdown.by,
     49    "allocationStack",
     50    "display changed with no snapshots"
     51  );
     52 
     53  // Test invalid displays
     54  try {
     55    dispatch(setCensusDisplay({}));
     56    ok(false, "Throws when passing in an invalid display object");
     57  } catch (e) {
     58    ok(true, "Throws when passing in an invalid display object");
     59  }
     60  equal(
     61    getState().censusDisplay.breakdown.by,
     62    "allocationStack",
     63    "current display unchanged when passing invalid display"
     64  );
     65 
     66  // Test new snapshots
     67  dispatch(takeSnapshotAndCensus(front, heapWorker));
     68  await waitUntilCensusState(store, s => s.census, [censusState.SAVED]);
     69  equal(
     70    getState().snapshots[0].census.display,
     71    censusDisplays.allocationStack,
     72    "New snapshots use the current, non-default display"
     73  );
     74 });