Bug 1382545 - Part 2: Add a test case for making sure that Animation API doesn't expose a high resolution time when 'privacy.resistFingerprinting' is true. r=arthuredelstein,birtles
authorTim Huang <tihuang@mozilla.com>
Fri, 18 Aug 2017 13:55:05 +0800
changeset 653135 ad3bc2177e896fcf5d8c919043797cbbf711525e
parent 653134 e2213726a3d34e5b211d242ff9663b5c95864fe8
child 653136 007265934857bcc881a893389eb69a3de6519d0f
push id76247
push userbmo:jryans@gmail.com
push dateFri, 25 Aug 2017 16:24:21 +0000
reviewersarthuredelstein, birtles
bugs1382545, 16337
milestone57.0a1
Bug 1382545 - Part 2: Add a test case for making sure that Animation API doesn't expose a high resolution time when 'privacy.resistFingerprinting' is true. r=arthuredelstein,birtles Adopt from Tor #16337 This patch adds a test case for testing that Animation API doesn't expose a high resolution time when 'privacy.resistFingerprinting' is true. The test case will play an animation and wait a certain amount of time, one second, and then verify the animation.startTime, animation.currentTime, animation.timeline.currentTime and document.timeline.currentTime are all rounded with 100ms. MozReview-Commit-ID: KiMYySYaQ7V
browser/components/resistfingerprinting/test/mochitest/file_animation_api.html
browser/components/resistfingerprinting/test/mochitest/mochitest.ini
browser/components/resistfingerprinting/test/mochitest/test_animation_api.html
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/mochitest/file_animation_api.html
@@ -0,0 +1,59 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1382545</title>
+<script>
+  function waitForCondition(aCond, aCallback, aErrorMsg) {
+    var tries = 0;
+    var interval = setInterval(() => {
+      if (tries >= 30) {
+        opener.ok(false, aErrorMsg);
+        moveOn();
+        return;
+      }
+      var conditionPassed;
+      try {
+        conditionPassed = aCond();
+      } catch (e) {
+        opener.ok(false, `${e}\n${e.stack}`);
+        conditionPassed = false;
+      }
+      if (conditionPassed) {
+        moveOn();
+      }
+      tries++;
+    }, 100);
+    var moveOn = () => { clearInterval(interval); aCallback(); };
+  }
+
+  function runTest() {
+    const isRounded = x => (Math.floor(x / 100) * 100) === x;
+    const testDiv = document.getElementById("testDiv");
+    const animation = testDiv.animate({ opacity: [0, 1] }, 100000);
+    animation.play();
+
+    waitForCondition(
+      () => animation.currentTime > 100,
+        () => {
+          opener.ok(isRounded(animation.startTime),
+             "animation.startTime is rounded");
+          opener.ok(isRounded(animation.currentTime),
+             "animation.currentTime is rounded");
+          opener.ok(isRounded(animation.timeline.currentTime),
+             "animation.timeline.currentTime is rounded");
+          if (document.timeline) {
+            opener.ok(isRounded(document.timeline.currentTime),
+               "document.timeline.currentTime is rounded");
+          }
+          opener.done();
+          window.close();
+        },
+        "animation failed to start");
+  }
+</script>
+</head>
+<body onload="runTest();">
+<div id="testDiv">test</div>
+</body>
+</html>
--- a/browser/components/resistfingerprinting/test/mochitest/mochitest.ini
+++ b/browser/components/resistfingerprinting/test/mochitest/mochitest.ini
@@ -1,16 +1,18 @@
 [DEFAULT]
 tags = resistfingerprinting
 
 support-files =
+  file_animation_api.html
   worker_child.js
   worker_grandchild.js
   !/dom/tests/mochitest/geolocation/network_geolocation.sjs
 
+[test_animation_api.html]
 [test_device_sensor_event.html]
 [test_geolocation.html]
 scheme = https
 [test_reduce_time_precision.html]
 [test_hide_gamepad_info.html]
 support-files = test_hide_gamepad_info_iframe.html
 [test_speech_synthesis.html]
 [test_bug1382499_touch_api.html]
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/mochitest/test_animation_api.html
@@ -0,0 +1,37 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1382545
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1382545</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript">
+
+  /** Test for Bug 1382545 **/
+  SimpleTest.waitForExplicitFinish();
+
+  window.onload = () => {
+    SpecialPowers.pushPrefEnv({"set":
+      [
+        ["privacy.resistFingerprinting", true],
+        ["dom.animations-api.core.enabled", true]
+      ]
+    }, runTest);
+  }
+
+  function runTest() {
+    window.open("file_animation_api.html");
+  }
+
+  function done() {
+    SimpleTest.finish();
+  }
+
+  </script>
+</head>
+<body>
+</body>
+</html>