summaryrefslogtreecommitdiffstats
path: root/toolkit/components/resistfingerprinting/tests/browser/browser_usercharacteristics.js
blob: 98969483116605c959c07356de9680635a589785 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

const emptyPage =
  getRootDirectory(gTestPath).replace(
    "chrome://mochitests/content",
    "https://example.com"
  ) + "empty.html";

function promiseObserverNotification() {
  return TestUtils.topicObserved(
    "user-characteristics-populating-data-done",
    _ => {
      var submitted = false;
      GleanPings.userCharacteristics.testBeforeNextSubmit(_ => {
        submitted = true;

        // Did we assign a value we got out of about:fingerprinting?
        // For now, we are sticking the test value in a random telemetry
        // metric, but once we have a real metric, we'll update this
        Assert.equal(
          "Hello World",
          Glean.characteristics.timezone.testGetValue()
        );
      });
      GleanPings.userCharacteristics.submit();

      return submitted;
    }
  );
}

add_task(async function run_test() {
  info("Starting test...");

  await BrowserTestUtils.withNewTab(
    { gBrowser, url: emptyPage },
    async function tabTask(_) {
      let promise = promiseObserverNotification();

      Services.obs.notifyObservers(
        null,
        "user-characteristics-testing-please-populate-data"
      );

      let submitted = await promise;
      Assert.ok(submitted);
    }
  );
});