Backed out 2 changesets (bug 1881078, bug 1879806) for causing dt failures @ devtools...
[gecko.git] / netwerk / test / browser / browser_103_telemetry.js
blobc6cc7dd070646720f92c30ddecab3ea704b263f0
1 "use strict";
3 const { TelemetryTestUtils } = ChromeUtils.importESModule(
4   "resource://testing-common/TelemetryTestUtils.sys.mjs"
5 );
7 Services.prefs.setCharPref("dom.securecontext.allowlist", "example.com");
9 var kTest103 =
10   "https://example.com/browser/netwerk/test/browser/103_preload.html";
11 var kTestNo103 =
12   "https://example.com/browser/netwerk/test/browser/no_103_preload.html";
13 var kTest404 =
14   "https://example.com/browser/netwerk/test/browser/103_preload_and_404.html";
16 add_task(async function () {
17   let hist_hints = TelemetryTestUtils.getAndClearHistogram(
18     "EH_NUM_OF_HINTS_PER_PAGE"
19   );
20   let hist_final = TelemetryTestUtils.getAndClearHistogram("EH_FINAL_RESPONSE");
21   let hist_time = TelemetryTestUtils.getAndClearHistogram(
22     "EH_TIME_TO_FINAL_RESPONSE"
23   );
25   await BrowserTestUtils.openNewForegroundTab(gBrowser, kTest103, true);
27   // This is a 200 response with 103:
28   // EH_NUM_OF_HINTS_PER_PAGE should record 1.
29   // EH_FINAL_RESPONSE should record 1 on position 0 (R2xx).
30   // EH_TIME_TO_FINAL_RESPONSE should have a new value
31   //   (we cannot determine what the timing will be therefore we only check that
32   //    the histogram sum is > 0).
33   TelemetryTestUtils.assertHistogram(hist_hints, 1, 1);
34   TelemetryTestUtils.assertHistogram(hist_final, 0, 1);
35   const snapshot = hist_time.snapshot();
36   let found = false;
37   for (let [val] of Object.entries(snapshot.values)) {
38     if (val > 0) {
39       found = true;
40     }
41   }
42   Assert.ok(found);
44   gBrowser.removeCurrentTab();
45 });
47 add_task(async function () {
48   let hist_hints = TelemetryTestUtils.getAndClearHistogram(
49     "EH_NUM_OF_HINTS_PER_PAGE"
50   );
51   let hist_final = TelemetryTestUtils.getAndClearHistogram("EH_FINAL_RESPONSE");
52   let hist_time = TelemetryTestUtils.getAndClearHistogram(
53     "EH_TIME_TO_FINAL_RESPONSE"
54   );
56   await BrowserTestUtils.openNewForegroundTab(gBrowser, kTestNo103, true);
58   // This is a 200 response without 103:
59   // EH_NUM_OF_HINTS_PER_PAGE should record 0.
60   // EH_FINAL_RESPONSE andd EH_TIME_TO_FINAL_RESPONSE should not be recorded.
61   TelemetryTestUtils.assertHistogram(hist_hints, 0, 1);
62   const snapshot_final = hist_final.snapshot();
63   Assert.equal(snapshot_final.sum, 0);
64   const snapshot_time = hist_time.snapshot();
65   let found = false;
66   for (let [val] of Object.entries(snapshot_time.values)) {
67     if (val > 0) {
68       found = true;
69     }
70   }
71   Assert.ok(!found);
73   gBrowser.removeCurrentTab();
74 });
76 add_task(async function () {
77   let hist_hints = TelemetryTestUtils.getAndClearHistogram(
78     "EH_NUM_OF_HINTS_PER_PAGE"
79   );
80   let hist_final = TelemetryTestUtils.getAndClearHistogram("EH_FINAL_RESPONSE");
81   let hist_time = TelemetryTestUtils.getAndClearHistogram(
82     "EH_TIME_TO_FINAL_RESPONSE"
83   );
85   await BrowserTestUtils.openNewForegroundTab(gBrowser, kTest404, true);
87   // This is a 404 response with 103:
88   // EH_NUM_OF_HINTS_PER_PAGE and EH_TIME_TO_FINAL_RESPONSE should not be recorded.
89   // EH_FINAL_RESPONSE should record 1 on index 2 (R4xx).
90   const snapshot_hints = hist_hints.snapshot();
91   Assert.equal(snapshot_hints.sum, 0);
92   TelemetryTestUtils.assertHistogram(hist_final, 2, 1);
93   const snapshot_time = hist_time.snapshot();
94   let found = false;
95   for (let [val] of Object.entries(snapshot_time.values)) {
96     if (val > 0) {
97       found = true;
98     }
99   }
100   Assert.ok(!found);
102   gBrowser.removeCurrentTab();
105 add_task(async function cleanup() {
106   Services.prefs.clearUserPref("dom.securecontext.allowlist");