tor-browser

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

test_action_diffing_03.js (4023B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test selecting snapshots for diffing.
      7 
      8 const {
      9  diffingState,
     10  snapshotState,
     11  viewState,
     12 } = require("resource://devtools/client/memory/constants.js");
     13 const {
     14  toggleDiffing,
     15  selectSnapshotForDiffing,
     16 } = require("resource://devtools/client/memory/actions/diffing.js");
     17 const {
     18  takeSnapshot,
     19 } = require("resource://devtools/client/memory/actions/snapshot.js");
     20 const {
     21  changeView,
     22 } = require("resource://devtools/client/memory/actions/view.js");
     23 
     24 // We test that you (1) cannot select a snapshot that is not in a diffable
     25 // state, and (2) cannot select more than 2 snapshots for diffing. Both attempts
     26 // trigger assertion failures.
     27 EXPECTED_DTU_ASSERT_FAILURE_COUNT = 2;
     28 
     29 add_task(async function () {
     30  const front = new StubbedMemoryFront();
     31  const heapWorker = new HeapAnalysesClient();
     32  await front.attach();
     33  const store = Store();
     34  const { getState, dispatch } = store;
     35 
     36  dispatch(changeView(viewState.CENSUS));
     37  equal(getState().diffing, null, "not diffing by default");
     38 
     39  dispatch(takeSnapshot(front, heapWorker));
     40  dispatch(takeSnapshot(front, heapWorker));
     41  dispatch(takeSnapshot(front, heapWorker));
     42 
     43  await waitUntilSnapshotState(store, [
     44    snapshotState.SAVED,
     45    snapshotState.SAVED,
     46    snapshotState.SAVED,
     47  ]);
     48  dispatch(takeSnapshot(front));
     49 
     50  // Start diffing.
     51  dispatch(toggleDiffing());
     52  ok(getState().diffing, "now diffing after toggling");
     53  equal(getState().diffing.firstSnapshotId, null, "no first snapshot selected");
     54  equal(
     55    getState().diffing.secondSnapshotId,
     56    null,
     57    "no second snapshot selected"
     58  );
     59  equal(
     60    getState().diffing.state,
     61    diffingState.SELECTING,
     62    "should be in diffing state SELECTING"
     63  );
     64 
     65  // Can't select a snapshot that is not in a diffable state.
     66  equal(
     67    getState().snapshots[3].state,
     68    snapshotState.SAVING,
     69    "the last snapshot is still in the process of being saved"
     70  );
     71  dumpn("Expecting exception:");
     72  let threw = false;
     73  try {
     74    dispatch(selectSnapshotForDiffing(getState().snapshots[3]));
     75  } catch (error) {
     76    threw = true;
     77  }
     78  ok(
     79    threw,
     80    "Should not be able to select snapshots that aren't ready for diffing"
     81  );
     82 
     83  // Select first snapshot for diffing.
     84  dispatch(selectSnapshotForDiffing(getState().snapshots[0]));
     85  ok(getState().diffing, "now diffing after toggling");
     86  equal(
     87    getState().diffing.firstSnapshotId,
     88    getState().snapshots[0].id,
     89    "first snapshot selected"
     90  );
     91  equal(
     92    getState().diffing.secondSnapshotId,
     93    null,
     94    "no second snapshot selected"
     95  );
     96  equal(
     97    getState().diffing.state,
     98    diffingState.SELECTING,
     99    "should still be in diffing state SELECTING"
    100  );
    101 
    102  // Can't diff first snapshot with itself; this is a noop.
    103  dispatch(selectSnapshotForDiffing(getState().snapshots[0]));
    104  ok(getState().diffing, "still diffing");
    105  equal(
    106    getState().diffing.firstSnapshotId,
    107    getState().snapshots[0].id,
    108    "first snapshot still selected"
    109  );
    110  equal(
    111    getState().diffing.secondSnapshotId,
    112    null,
    113    "still no second snapshot selected"
    114  );
    115  equal(
    116    getState().diffing.state,
    117    diffingState.SELECTING,
    118    "should still be in diffing state SELECTING"
    119  );
    120 
    121  // Select second snapshot for diffing.
    122  dispatch(selectSnapshotForDiffing(getState().snapshots[1]));
    123  ok(getState().diffing, "still diffing");
    124  equal(
    125    getState().diffing.firstSnapshotId,
    126    getState().snapshots[0].id,
    127    "first snapshot still selected"
    128  );
    129  equal(
    130    getState().diffing.secondSnapshotId,
    131    getState().snapshots[1].id,
    132    "second snapshot selected"
    133  );
    134 
    135  // Can't select more than two snapshots for diffing.
    136  dumpn("Expecting exception:");
    137  threw = false;
    138  try {
    139    dispatch(selectSnapshotForDiffing(getState().snapshots[2]));
    140  } catch (error) {
    141    threw = true;
    142  }
    143  ok(threw, "Can't select more than two snapshots for diffing");
    144 
    145  heapWorker.destroy();
    146  await front.detach();
    147 });