summaryrefslogtreecommitdiffstats
path: root/browser/components/resistfingerprinting/test/browser/browser_timezone.js
blob: 91229c55739579b0fb53647848f5dd928bc39840 (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
/**
 * Bug 1330890 - A test case for verifying Date() object of javascript will use
 *               UTC timezone after fingerprinting resistance is enabled.
 */

const TEST_DOMAIN = "http://example.net/";
const TEST_PATH =
  TEST_DOMAIN + "browser/browser/components/resistfingerprinting/test/browser/";

add_task(async function setup() {
  await SpecialPowers.pushPrefEnv({
    set: [["privacy.resistFingerprinting", true]],
  });
});

add_task(async function test_timezone() {
  // Load a page and verify the timezone.
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    TEST_PATH + "file_dummy.html"
  );

  await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
    let dateObj = new Date();
    let dateString = dateObj.toString();

    ok(
      dateString.endsWith("(Coordinated Universal Time)"),
      "The date string is in UTC timezone."
    );
    is(
      dateObj.getFullYear(),
      dateObj.getUTCFullYear(),
      "The full year reports in UTC timezone."
    );
    is(
      dateObj.getMonth(),
      dateObj.getUTCMonth(),
      "The month reports in UTC timezone."
    );
    is(
      dateObj.getDate(),
      dateObj.getUTCDate(),
      "The month reports in UTC timezone."
    );
    is(
      dateObj.getDay(),
      dateObj.getUTCDay(),
      "The day reports in UTC timezone."
    );
    is(
      dateObj.getHours(),
      dateObj.getUTCHours(),
      "The hours reports in UTC timezone."
    );
    is(
      dateObj.getTimezoneOffset(),
      0,
      "The difference with UTC timezone is 0."
    );
  });

  BrowserTestUtils.removeTab(tab);
});