Bug 1468402 - Part 3: Add test for subgrids in the grid list. r=pbro
[gecko.git] / startupcache / test / browser_startupcache_telemetry.js
blob2fa9f25d772d07fdb723b23835c6f7ea3c2e614a
1 /* Any copyright is dedicated to the Public Domain.
2    http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 const LABELS_STARTUP_CACHE_REQUESTS = {
7   HitMemory: 0,
8   HitDisk: 1,
9   Miss: 2,
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   });
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);
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   Assert.less(histValue(LABELS_STARTUP_CACHE_REQUESTS.Miss), 9);
35   await BrowserTestUtils.closeWindow(newWin);
37   Services.obs.notifyObservers(null, "startupcache-invalidate", "memoryOnly");
38   newWin = await BrowserTestUtils.openNewBrowserWindow();
39   snapshot = Services.telemetry.getSnapshotForHistograms("main", true);
40   Assert.less(histValue(LABELS_STARTUP_CACHE_REQUESTS.HitMemory), 4);
41   Assert.notEqual(histValue(LABELS_STARTUP_CACHE_REQUESTS.HitDisk), 0);
42   // Some misses can come through - just ensure it's a small number
43   Assert.less(histValue(LABELS_STARTUP_CACHE_REQUESTS.Miss), 5);
44   await BrowserTestUtils.closeWindow(newWin);
45 });