File: test_chrome_ext_contentscript_telemetry.html

package info (click to toggle)
thunderbird 1%3A91.12.0-1~deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,008,300 kB
  • sloc: cpp: 6,084,052; javascript: 4,790,441; ansic: 3,341,486; python: 862,958; asm: 366,542; xml: 204,277; java: 152,477; sh: 111,376; makefile: 21,388; perl: 15,312; yacc: 4,583; objc: 3,026; lex: 1,720; exp: 762; pascal: 635; awk: 564; sql: 453; php: 436; lisp: 432; ruby: 99; sed: 69; csh: 45
file content (64 lines) | stat: -rw-r--r-- 1,920 bytes parent folder | download | duplicates (10)
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
<!DOCTYPE html>
<html>
<head>
  <title>Test for telemetry for content script injection</title>
  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script src="chrome://mochikit/content/tests/SimpleTest/ExtensionTestUtils.js"></script>
  <script src="head.js"></script>
  <link rel="stylesheet" href="chrome://mochikit/contents/tests/SimpleTest/test.css"/>
</head>
<body>

<script>
"use strict";

const HISTOGRAM = "WEBEXT_CONTENT_SCRIPT_INJECTION_MS";

add_task(async function test_contentscript_telemetry() {
  // Turn on telemetry and reset it to the previous state once the test is completed.
  const telemetryCanRecordBase = SpecialPowers.Services.telemetry.canRecordBase;
  SpecialPowers.Services.telemetry.canRecordBase = true;
  SimpleTest.registerCleanupFunction(() => {
    SpecialPowers.Services.telemetry.canRecordBase = telemetryCanRecordBase;
  });

  function background() {
    browser.test.onMessage.addListener(() => {
      browser.tabs.executeScript({code: 'browser.test.sendMessage("content-script-run");'});
    });
  }

  let extensionData = {
    manifest: {
      permissions: ["<all_urls>"],
    },
    background,
  };

  let win = window.open("http://example.com/");

  let extension = ExtensionTestUtils.loadExtension(extensionData);

  let histogram = SpecialPowers.Services.telemetry.getHistogramById(HISTOGRAM);
  histogram.clear();
  is(histogram.snapshot().sum, 0,
     `No data recorded for histogram: ${HISTOGRAM}.`);

  await extension.startup();
  is(histogram.snapshot().sum, 0,
     `No data recorded for histogram after startup: ${HISTOGRAM}.`);

  extension.sendMessage();
  await extension.awaitMessage("content-script-run");

  let histogramSum = histogram.snapshot().sum;
  ok(histogramSum > 0,
     `Data recorded for first extension for histogram: ${HISTOGRAM}.`);

  win.close();
  await extension.unload();
});
</script>

</body>
</html>