tor-browser

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

browser_startupcache_telemetry.js (2251B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const LABELS_STARTUP_CACHE_REQUESTS = {
      7  HitMemory: 0,
      8  HitDisk: 1,
      9  Miss: 2,
     10 };
     11 
     12 add_task(async function () {
     13  // Turn off tab preloading to avoid issues with RemoteController.js
     14  await SpecialPowers.pushPrefEnv({
     15    set: [["browser.newtab.preload", false]],
     16  });
     17 
     18  Services.obs.notifyObservers(null, "startupcache-invalidate");
     19  Services.telemetry.getSnapshotForHistograms("main", true);
     20  let newWin = await BrowserTestUtils.openNewBrowserWindow();
     21  let snapshot = Services.telemetry.getSnapshotForHistograms("main", true);
     22  function histValue(label) {
     23    return snapshot.parent.STARTUP_CACHE_REQUESTS.values[label] || 0;
     24  }
     25  Assert.equal(histValue(LABELS_STARTUP_CACHE_REQUESTS.HitMemory), 0);
     26  Assert.equal(histValue(LABELS_STARTUP_CACHE_REQUESTS.HitDisk), 0);
     27  Assert.notEqual(histValue(LABELS_STARTUP_CACHE_REQUESTS.Miss), 0);
     28  await BrowserTestUtils.closeWindow(newWin);
     29 
     30  newWin = await BrowserTestUtils.openNewBrowserWindow();
     31  snapshot = Services.telemetry.getSnapshotForHistograms("main", true);
     32  Assert.notEqual(histValue(LABELS_STARTUP_CACHE_REQUESTS.HitMemory), 0);
     33  Assert.equal(histValue(LABELS_STARTUP_CACHE_REQUESTS.HitDisk), 0);
     34 
     35  // Here and below, 50 is just a nice round number that should be well over
     36  // what we should observe under normal circumstances, and well under what
     37  // we should see if something is seriously wrong. It won't catch everything,
     38  // but it's better than nothing, and better than a test that cries wolf.
     39  Assert.less(histValue(LABELS_STARTUP_CACHE_REQUESTS.Miss), 50);
     40  await BrowserTestUtils.closeWindow(newWin);
     41 
     42  Services.obs.notifyObservers(null, "startupcache-invalidate", "memoryOnly");
     43  newWin = await BrowserTestUtils.openNewBrowserWindow();
     44  snapshot = Services.telemetry.getSnapshotForHistograms("main", true);
     45  Assert.less(histValue(LABELS_STARTUP_CACHE_REQUESTS.HitMemory), 50);
     46  Assert.notEqual(histValue(LABELS_STARTUP_CACHE_REQUESTS.HitDisk), 0);
     47  // Some misses can come through - just ensure it's a small number
     48  Assert.less(histValue(LABELS_STARTUP_CACHE_REQUESTS.Miss), 50);
     49  await BrowserTestUtils.closeWindow(newWin);
     50 });