Bug 1857386 [wpt PR 42383] - Update wpt metadata, a=testonly
[gecko.git] / netwerk / test / unit / test_trr_telemetry.js
blobfff6f077748519fe32dfca51eda1415804f350c6
1 "use strict";
3 /* import-globals-from trr_common.js */
5 // Allow telemetry probes which may otherwise be disabled for some
6 // applications (e.g. Thunderbird).
7 Services.prefs.setBoolPref(
8   "toolkit.telemetry.testing.overrideProductsCheck",
9   true
12 const { TelemetryTestUtils } = ChromeUtils.importESModule(
13   "resource://testing-common/TelemetryTestUtils.sys.mjs"
16 function setup() {
17   h2Port = trr_test_setup();
20 setup();
21 registerCleanupFunction(async () => {
22   trr_clear_prefs();
23 });
25 async function trrLookup(mode, rolloutMode) {
26   let hist = TelemetryTestUtils.getAndClearKeyedHistogram(
27     "TRR_SKIP_REASON_TRR_FIRST2"
28   );
30   if (rolloutMode) {
31     info("Testing doh-rollout.mode");
32     setModeAndURI(0, "doh?responseIP=2.2.2.2");
33     Services.prefs.setIntPref("doh-rollout.mode", rolloutMode);
34   } else {
35     setModeAndURI(mode, "doh?responseIP=2.2.2.2");
36   }
38   Services.dns.clearCache(true);
39   await new TRRDNSListener("test.example.com", "2.2.2.2");
40   let expectedKey = `(other)_${mode}`;
41   if (mode == 0) {
42     expectedKey = "(other)";
43   }
45   let snapshot = hist.snapshot();
46   await TestUtils.waitForCondition(() => {
47     snapshot = hist.snapshot();
48     info("snapshot:" + JSON.stringify(snapshot));
49     return snapshot;
50   });
51   TelemetryTestUtils.assertKeyedHistogramValue(
52     hist,
53     expectedKey,
54     Ci.nsITRRSkipReason.TRR_OK,
55     1
56   );
59 add_task(async function test_trr_lookup_mode_2() {
60   await trrLookup(Ci.nsIDNSService.MODE_TRRFIRST);
61 });
63 add_task(async function test_trr_lookup_mode_3() {
64   await trrLookup(Ci.nsIDNSService.MODE_TRRONLY);
65 });
67 add_task(async function test_trr_lookup_mode_0() {
68   await trrLookup(
69     Ci.nsIDNSService.MODE_NATIVEONLY,
70     Ci.nsIDNSService.MODE_TRRFIRST
71   );
72 });
74 async function trrByTypeLookup(trrURI, expectedSuccess, expectedSkipReason) {
75   Services.prefs.setIntPref(
76     "doh-rollout.mode",
77     Ci.nsIDNSService.MODE_NATIVEONLY
78   );
80   let hist = TelemetryTestUtils.getAndClearKeyedHistogram(
81     "TRR_RELEVANT_SKIP_REASON_TRR_FIRST_TYPE_REC"
82   );
84   setModeAndURI(Ci.nsIDNSService.MODE_TRRFIRST, trrURI);
86   Services.dns.clearCache(true);
87   await new TRRDNSListener("test.httpssvc.com", {
88     type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
89     expectedSuccess,
90   });
91   let expectedKey = `(other)_2`;
93   let snapshot = hist.snapshot();
94   await TestUtils.waitForCondition(() => {
95     snapshot = hist.snapshot();
96     info("snapshot:" + JSON.stringify(snapshot));
97     return snapshot;
98   });
100   TelemetryTestUtils.assertKeyedHistogramValue(
101     hist,
102     expectedKey,
103     expectedSkipReason,
104     1
105   );
108 add_task(async function test_trr_by_type_lookup_success() {
109   await trrByTypeLookup("httpssvc", true, Ci.nsITRRSkipReason.TRR_OK);
112 add_task(async function test_trr_by_type_lookup_fail() {
113   await trrByTypeLookup(
114     "doh?responseIP=none",
115     false,
116     Ci.nsITRRSkipReason.TRR_NO_ANSWERS
117   );