Bug 1369319 - Part2: Add a test case to verify that device sensor evevnts have been blocked when 'privacy.resistFingerprinting' is true. r?bz,arthuredelstein draft
authorTim Huang <tihuang@mozilla.com>
Tue, 20 Jun 2017 14:51:52 +0800
changeset 597341 c7d1b120a1dcdae0165781f882ae1f60918b24af
parent 597340 4951448c78d15331eb5da4a2c299d61df8080058
child 634217 16a7a8dba94883b91c68fc2ecf578ee505145390
push id64917
push userbmo:tihuang@mozilla.com
push dateTue, 20 Jun 2017 13:52:42 +0000
reviewersbz, arthuredelstein
bugs1369319
milestone56.0a1
Bug 1369319 - Part2: Add a test case to verify that device sensor evevnts have been blocked when 'privacy.resistFingerprinting' is true. r?bz,arthuredelstein MozReview-Commit-ID: 5hw5S56zDfE
browser/components/resistfingerprinting/test/mochitest/mochitest.ini
browser/components/resistfingerprinting/test/mochitest/test_device_sensor_event.html
--- a/browser/components/resistfingerprinting/test/mochitest/mochitest.ini
+++ b/browser/components/resistfingerprinting/test/mochitest/mochitest.ini
@@ -1,6 +1,8 @@
 [DEFAULT]
+tags = resistfingerprinting
 support-files =
   worker_child.js
   worker_grandchild.js
 
+[test_device_sensor_event.html]
 [test_reduce_time_precision.html]
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/mochitest/test_device_sensor_event.html
@@ -0,0 +1,50 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1369319
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1369319</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;version=1.7">
+
+  /** Test for Bug 1369319 **/
+  SimpleTest.waitForExplicitFinish();
+  window.onload = () => {
+    SimpleTest.waitForFocus(() => {
+      SpecialPowers.pushPrefEnv({"set":
+        [
+          ["device.sensors.test.events", true],
+          ["privacy.resistFingerprinting", true]
+        ]
+      }, doTest);
+    }, window);
+  }
+
+  function doTest() {
+    window.addEventListener("devicemotion", () => {
+      ok(false, "The device motion event should not be fired.")
+    }, {once: true});
+
+    window.addEventListener("TestEvent", () => {
+      // If we receive this event without receiving a 'devicemotion' event, this means
+      // the device sensor event has been blocked correctly.
+      ok(true, "Got the 'TestEvent' event.");
+      SimpleTest.finish();
+    }, {once: true});
+
+    window.dispatchEvent(new CustomEvent("TestEvent"));
+  }
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test"></pre>
+</body>
+</html>