summaryrefslogtreecommitdiffstats
path: root/netwerk/test/browser/browser_103_telemetry.js
blob: bf0f55fc2ed7389695cfeddf22d8037a86e7dfdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"use strict";

const { TelemetryTestUtils } = ChromeUtils.importESModule(
  "resource://testing-common/TelemetryTestUtils.sys.mjs"
);

Services.prefs.setCharPref("dom.securecontext.allowlist", "example.com");

var kTest103 =
  "http://example.com/browser/netwerk/test/browser/103_preload.html";
var kTestNo103 =
  "http://example.com/browser/netwerk/test/browser/no_103_preload.html";
var kTest404 =
  "http://example.com/browser/netwerk/test/browser/103_preload_and_404.html";

add_task(async function () {
  let hist_hints = TelemetryTestUtils.getAndClearHistogram(
    "EH_NUM_OF_HINTS_PER_PAGE"
  );
  let hist_final = TelemetryTestUtils.getAndClearHistogram("EH_FINAL_RESPONSE");
  let hist_time = TelemetryTestUtils.getAndClearHistogram(
    "EH_TIME_TO_FINAL_RESPONSE"
  );

  await BrowserTestUtils.openNewForegroundTab(gBrowser, kTest103, true);

  // This is a 200 response with 103:
  // EH_NUM_OF_HINTS_PER_PAGE should record 1.
  // EH_FINAL_RESPONSE should record 1 on position 0 (R2xx).
  // EH_TIME_TO_FINAL_RESPONSE should have a new value
  //   (we cannot determine what the timing will be therefore we only check that
  //    the histogram sum is > 0).
  TelemetryTestUtils.assertHistogram(hist_hints, 1, 1);
  TelemetryTestUtils.assertHistogram(hist_final, 0, 1);
  const snapshot = hist_time.snapshot();
  let found = false;
  for (let [val] of Object.entries(snapshot.values)) {
    if (val > 0) {
      found = true;
    }
  }
  Assert.ok(found);

  gBrowser.removeCurrentTab();
});

add_task(async function () {
  let hist_hints = TelemetryTestUtils.getAndClearHistogram(
    "EH_NUM_OF_HINTS_PER_PAGE"
  );
  let hist_final = TelemetryTestUtils.getAndClearHistogram("EH_FINAL_RESPONSE");
  let hist_time = TelemetryTestUtils.getAndClearHistogram(
    "EH_TIME_TO_FINAL_RESPONSE"
  );

  await BrowserTestUtils.openNewForegroundTab(gBrowser, kTestNo103, true);

  // This is a 200 response without 103:
  // EH_NUM_OF_HINTS_PER_PAGE should record 0.
  // EH_FINAL_RESPONSE andd EH_TIME_TO_FINAL_RESPONSE should not be recorded.
  TelemetryTestUtils.assertHistogram(hist_hints, 0, 1);
  const snapshot_final = hist_final.snapshot();
  Assert.equal(snapshot_final.sum, 0);
  const snapshot_time = hist_time.snapshot();
  let found = false;
  for (let [val] of Object.entries(snapshot_time.values)) {
    if (val > 0) {
      found = true;
    }
  }
  Assert.ok(!found);

  gBrowser.removeCurrentTab();
});

add_task(async function () {
  let hist_hints = TelemetryTestUtils.getAndClearHistogram(
    "EH_NUM_OF_HINTS_PER_PAGE"
  );
  let hist_final = TelemetryTestUtils.getAndClearHistogram("EH_FINAL_RESPONSE");
  let hist_time = TelemetryTestUtils.getAndClearHistogram(
    "EH_TIME_TO_FINAL_RESPONSE"
  );

  await BrowserTestUtils.openNewForegroundTab(gBrowser, kTest404, true);

  // This is a 404 response with 103:
  // EH_NUM_OF_HINTS_PER_PAGE and EH_TIME_TO_FINAL_RESPONSE should not be recorded.
  // EH_FINAL_RESPONSE should record 1 on index 2 (R4xx).
  const snapshot_hints = hist_hints.snapshot();
  Assert.equal(snapshot_hints.sum, 0);
  TelemetryTestUtils.assertHistogram(hist_final, 2, 1);
  const snapshot_time = hist_time.snapshot();
  let found = false;
  for (let [val] of Object.entries(snapshot_time.values)) {
    if (val > 0) {
      found = true;
    }
  }
  Assert.ok(!found);

  gBrowser.removeCurrentTab();
});

add_task(async function cleanup() {
  Services.prefs.clearUserPref("dom.securecontext.allowlist");
});