3 const { TelemetryTestUtils } = ChromeUtils.importESModule(
4 "resource://testing-common/TelemetryTestUtils.sys.mjs"
7 Services.prefs.setCharPref("dom.securecontext.allowlist", "example.com");
10 "https://example.com/browser/netwerk/test/browser/103_preload.html";
12 "https://example.com/browser/netwerk/test/browser/no_103_preload.html";
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"
20 let hist_final = TelemetryTestUtils.getAndClearHistogram("EH_FINAL_RESPONSE");
21 let hist_time = TelemetryTestUtils.getAndClearHistogram(
22 "EH_TIME_TO_FINAL_RESPONSE"
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();
37 for (let [val] of Object.entries(snapshot.values)) {
44 gBrowser.removeCurrentTab();
47 add_task(async function () {
48 let hist_hints = TelemetryTestUtils.getAndClearHistogram(
49 "EH_NUM_OF_HINTS_PER_PAGE"
51 let hist_final = TelemetryTestUtils.getAndClearHistogram("EH_FINAL_RESPONSE");
52 let hist_time = TelemetryTestUtils.getAndClearHistogram(
53 "EH_TIME_TO_FINAL_RESPONSE"
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();
66 for (let [val] of Object.entries(snapshot_time.values)) {
73 gBrowser.removeCurrentTab();
76 add_task(async function () {
77 let hist_hints = TelemetryTestUtils.getAndClearHistogram(
78 "EH_NUM_OF_HINTS_PER_PAGE"
80 let hist_final = TelemetryTestUtils.getAndClearHistogram("EH_FINAL_RESPONSE");
81 let hist_time = TelemetryTestUtils.getAndClearHistogram(
82 "EH_TIME_TO_FINAL_RESPONSE"
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();
95 for (let [val] of Object.entries(snapshot_time.values)) {
102 gBrowser.removeCurrentTab();
105 add_task(async function cleanup() {
106 Services.prefs.clearUserPref("dom.securecontext.allowlist");