tor-browser

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

test_action_diffing_04.js (2828B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test that we compute census diffs.
      7 
      8 const {
      9  diffingState,
     10  snapshotState,
     11  viewState,
     12 } = require("resource://devtools/client/memory/constants.js");
     13 const {
     14  toggleDiffing,
     15  selectSnapshotForDiffingAndRefresh,
     16 } = require("resource://devtools/client/memory/actions/diffing.js");
     17 const {
     18  takeSnapshot,
     19  readSnapshot,
     20 } = require("resource://devtools/client/memory/actions/snapshot.js");
     21 const {
     22  changeView,
     23 } = require("resource://devtools/client/memory/actions/view.js");
     24 
     25 add_task(async function () {
     26  const front = new StubbedMemoryFront();
     27  const heapWorker = new HeapAnalysesClient();
     28  await front.attach();
     29  const store = Store();
     30  const { getState, dispatch } = store;
     31  dispatch(changeView(viewState.CENSUS));
     32 
     33  equal(getState().diffing, null, "not diffing by default");
     34 
     35  const s1 = await dispatch(takeSnapshot(front, heapWorker));
     36  const s2 = await dispatch(takeSnapshot(front, heapWorker));
     37  const s3 = await dispatch(takeSnapshot(front, heapWorker));
     38  dispatch(readSnapshot(heapWorker, s1));
     39  dispatch(readSnapshot(heapWorker, s2));
     40  dispatch(readSnapshot(heapWorker, s3));
     41  await waitUntilSnapshotState(store, [
     42    snapshotState.READ,
     43    snapshotState.READ,
     44    snapshotState.READ,
     45  ]);
     46 
     47  dispatch(toggleDiffing());
     48  dispatch(
     49    selectSnapshotForDiffingAndRefresh(heapWorker, getState().snapshots[0])
     50  );
     51  dispatch(
     52    selectSnapshotForDiffingAndRefresh(heapWorker, getState().snapshots[1])
     53  );
     54 
     55  ok(getState().diffing, "We should be diffing.");
     56  equal(
     57    getState().diffing.firstSnapshotId,
     58    getState().snapshots[0].id,
     59    "First snapshot selected."
     60  );
     61  equal(
     62    getState().diffing.secondSnapshotId,
     63    getState().snapshots[1].id,
     64    "Second snapshot selected."
     65  );
     66 
     67  await waitUntilState(
     68    store,
     69    state => state.diffing.state === diffingState.TAKING_DIFF
     70  );
     71  ok(
     72    true,
     73    "Selecting two snapshots for diffing should trigger computing a diff."
     74  );
     75 
     76  await waitUntilState(
     77    store,
     78    state => state.diffing.state === diffingState.TOOK_DIFF
     79  );
     80  ok(true, "And then the diff should complete.");
     81  ok(getState().diffing.census, "And we should have a census.");
     82  ok(getState().diffing.census.report, "And that census should have a report.");
     83  equal(
     84    getState().diffing.census.display,
     85    getState().censusDisplay,
     86    "And that census should have the correct display"
     87  );
     88  equal(
     89    getState().diffing.census.filter,
     90    getState().filter,
     91    "And that census should have the correct filter"
     92  );
     93  equal(
     94    getState().diffing.census.display.inverted,
     95    getState().censusDisplay.inverted,
     96    "And that census should have the correct inversion"
     97  );
     98 
     99  heapWorker.destroy();
    100  await front.detach();
    101 });