tor-browser

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

browser_memory_diff_01.js (2817B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Test diffing.
      5 
      6 "use strict";
      7 
      8 const {
      9  diffingState,
     10  treeMapState,
     11 } = require("resource://devtools/client/memory/constants.js");
     12 
     13 const TEST_URL =
     14  "http://example.com/browser/devtools/client/memory/test/browser/doc_steady_allocation.html";
     15 
     16 this.test = makeMemoryTest(TEST_URL, async function ({ panel }) {
     17  const store = panel.panelWin.gStore;
     18  const { getState } = store;
     19  const doc = panel.panelWin.document;
     20 
     21  ok(!getState().diffing, "Not diffing by default.");
     22 
     23  // Take two snapshots.
     24  const takeSnapshotButton = doc.getElementById("take-snapshot");
     25  EventUtils.synthesizeMouseAtCenter(takeSnapshotButton, {}, panel.panelWin);
     26  await waitForTime(1000);
     27  EventUtils.synthesizeMouseAtCenter(takeSnapshotButton, {}, panel.panelWin);
     28 
     29  // Enable diffing mode.
     30  const diffButton = doc.getElementById("diff-snapshots");
     31  EventUtils.synthesizeMouseAtCenter(diffButton, {}, panel.panelWin);
     32  await waitUntilState(
     33    store,
     34    state => !!state.diffing && state.diffing.state === diffingState.SELECTING
     35  );
     36  ok(true, "Clicking the diffing button put us into the diffing state.");
     37  is(getDisplayedSnapshotStatus(doc), "Select the baseline snapshot");
     38 
     39  await waitUntilState(
     40    store,
     41    state =>
     42      state.snapshots.length === 2 &&
     43      state.snapshots[0].treeMap &&
     44      state.snapshots[1].treeMap &&
     45      state.snapshots[0].treeMap.state === treeMapState.SAVED &&
     46      state.snapshots[1].treeMap.state === treeMapState.SAVED
     47  );
     48 
     49  const listItems = [...doc.querySelectorAll(".snapshot-list-item")];
     50  is(listItems.length, 2, "Should have two snapshot list items");
     51 
     52  // Select the first snapshot.
     53  EventUtils.synthesizeMouseAtCenter(listItems[0], {}, panel.panelWin);
     54  await waitUntilState(
     55    store,
     56    state =>
     57      state.diffing.state === diffingState.SELECTING &&
     58      state.diffing.firstSnapshotId
     59  );
     60  is(
     61    getDisplayedSnapshotStatus(doc),
     62    "Select the snapshot to compare to the baseline"
     63  );
     64 
     65  // Select the second snapshot.
     66  EventUtils.synthesizeMouseAtCenter(listItems[1], {}, panel.panelWin);
     67  await waitUntilState(
     68    store,
     69    state => state.diffing.state === diffingState.TAKING_DIFF
     70  );
     71  ok(true, "Selecting two snapshots for diffing triggers computing the diff");
     72 
     73  // .startsWith because the ellipsis is lost in translation.
     74  ok(getDisplayedSnapshotStatus(doc).startsWith("Computing difference"));
     75 
     76  await waitUntilState(
     77    store,
     78    state => state.diffing.state === diffingState.TOOK_DIFF
     79  );
     80  ok(true, "And that diff is computed successfully");
     81  is(getDisplayedSnapshotStatus(doc), null, "No status text anymore");
     82  ok(
     83    doc.querySelector(".heap-tree-item"),
     84    "And instead we should be showing the tree"
     85  );
     86 });