tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug1382499_touch_api.html (2686B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
      4 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      5 <script src="/tests/SimpleTest/EventUtils.js"></script>
      6 <script>
      7 /* global SimpleTest SpecialPowers synthesizeTouch */
      8 
      9 SimpleTest.waitForExplicitFinish();
     10 
     11 function promiseEvent(target, eventName) {
     12  return new Promise(resolve => {
     13    target.addEventListener(eventName, resolve, {once: true});
     14  });
     15 }
     16 
     17 function promiseTouchEvent(target, type, offsetX, offsetY, params) {
     18  let touchEventPromise = promiseEvent(target, type);
     19  params.type = type;
     20  synthesizeTouch(target, offsetX, offsetY, params);
     21  return touchEventPromise;
     22 }
     23 
     24 document.addEventListener("DOMContentLoaded", async () => {
     25  const target0 = document.getElementById("target0");
     26  const touchParams = {force: 1.0, angle: 1.0, rx: 2, ry: 3};
     27  await SpecialPowers.pushPrefEnv({set: [["dom.w3c_touch_events.enabled", 1]]});
     28 
     29  for (let seq of [0, 1, 2, 3]) {
     30    let resist = false;
     31    if (seq == 0) {
     32      resist = true;
     33      await SpecialPowers.pushPrefEnv({set: [["privacy.resistFingerprinting", true]]});
     34    } else if (seq == 1) {
     35      await SpecialPowers.pushPrefEnv({set: [["privacy.resistFingerprinting", false]]});
     36    } else if (seq == 2) {
     37      resist = true;
     38      await SpecialPowers.pushPrefEnv({set: [
     39        ["privacy.fingerprintingProtection", true],
     40        ["privacy.fingerprintingProtection.overrides", "+TouchEvents"]
     41      ]});
     42    } else {
     43      await SpecialPowers.pushPrefEnv({set: [
     44        ["privacy.fingerprintingProtection", true],
     45        ["privacy.fingerprintingProtection.overrides", "-TouchEvents"]
     46      ]});
     47    }
     48 
     49    info("starting test with fingerprinting resistance " + (resist ? "on" : "off") + " sequence number " + seq);
     50    let touchEvent = await promiseTouchEvent(target0, "touchstart", 5, 5, touchParams);
     51    info("touch event received");
     52    let touch = touchEvent.touches[0];
     53 
     54    if (resist) {
     55      is(touch.screenX, touch.clientX, "touch.screenX should be the same as touch.clientX");
     56      is(touch.screenY, touch.clientY, "touch.screenY should be the same as touch.clientY");
     57      // radiusX/radiusY may differ from the original rx/ry because of AppUnitsPerCSSPixel and AppUnitsPerDevPixel.
     58      // So only check if the values are spoofed.
     59      is(touch.radiusX, 0, "touch.radiusX");
     60      is(touch.radiusY, 0, "touch.radiusY");
     61    }
     62    is(touch.force, resist ? 0.0 : touchParams.force, "touch.force");
     63    is(touch.rotationAngle, resist ? 0 : touchParams.angle, "touch.rotationAngle");
     64    await SpecialPowers.popPrefEnv();
     65  }
     66 
     67  SimpleTest.finish();
     68 });
     69 </script>
     70 <div id="target0">target 0</div>