summaryrefslogtreecommitdiffstats
path: root/browser/components/resistfingerprinting/test/mochitest/test_bug1382499_touch_api.html
blob: c440d37cf220e8d381f4b6662b76844a9f4b8a16 (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
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script>
/* global SimpleTest SpecialPowers synthesizeTouch */

SimpleTest.waitForExplicitFinish();

function promiseEvent(target, eventName) {
  return new Promise(resolve => {
    target.addEventListener(eventName, resolve, {once: true});
  });
}

function promiseTouchEvent(target, type, offsetX, offsetY, params) {
  let touchEventPromise = promiseEvent(target, type);
  params.type = type;
  synthesizeTouch(target, offsetX, offsetY, params);
  return touchEventPromise;
}

document.addEventListener("DOMContentLoaded", async () => {
  const target0 = document.getElementById("target0");
  const touchParams = {force: 1.0, angle: 1.0, rx: 2, ry: 3};
  await SpecialPowers.pushPrefEnv({set: [["dom.w3c_touch_events.enabled", 1]]});

  for (let seq of [0, 1, 2, 3]) {
    let resist = false;
    if (seq == 0) {
      resist = true;
      await SpecialPowers.pushPrefEnv({set: [["privacy.resistFingerprinting", true]]});
    } else if (seq == 1) {
      await SpecialPowers.pushPrefEnv({set: [["privacy.resistFingerprinting", false]]});
    } else if (seq == 2) {
      resist = true;
      await SpecialPowers.pushPrefEnv({set: [
        ["privacy.fingerprintingProtection", true],
        ["privacy.fingerprintingProtection.overrides", "+TouchEvents"]
      ]});
    } else {
      await SpecialPowers.pushPrefEnv({set: [
        ["privacy.fingerprintingProtection", true],
        ["privacy.fingerprintingProtection.overrides", "-TouchEvents"]
      ]});
    }

    info("starting test with fingerprinting resistance " + (resist ? "on" : "off") + " sequence number " + seq);
    let touchEvent = await promiseTouchEvent(target0, "touchstart", 5, 5, touchParams);
    info("touch event received");
    let touch = touchEvent.touches[0];

    if (resist) {
      is(touch.screenX, touch.clientX, "touch.screenX should be the same as touch.clientX");
      is(touch.screenY, touch.clientY, "touch.screenY should be the same as touch.clientY");
      // radiusX/radiusY may differ from the original rx/ry because of AppUnitsPerCSSPixel and AppUnitsPerDevPixel.
      // So only check if the values are spoofed.
      is(touch.radiusX, 0, "touch.radiusX");
      is(touch.radiusY, 0, "touch.radiusY");
    }
    is(touch.force, resist ? 0.0 : touchParams.force, "touch.force");
    is(touch.rotationAngle, resist ? 0 : touchParams.angle, "touch.rotationAngle");
    await SpecialPowers.popPrefEnv();
  }

  SimpleTest.finish();
});
</script>
<div id="target0">target 0</div>