Bug 1337161 - Add test case r=arthuredelstein,smaug
authorChung-Sheng Fu <cfu@mozilla.com>
Mon, 19 Jun 2017 10:11:24 +0800
changeset 366599 5f871d33279117a6bf25bb484556c1f72710039f
parent 366598 41a148dc837d3f6b0330faf4f8fc2456a317104e
child 366600 97043840f1edf345b0a6284124898c4b03659088
push id92008
push usercbook@mozilla.com
push dateThu, 29 Jun 2017 13:50:12 +0000
treeherdermozilla-inbound@6e0dd1705c75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarthuredelstein, smaug
bugs1337161
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1337161 - Add test case r=arthuredelstein,smaug MozReview-Commit-ID: DseKBevAiuR
browser/components/resistfingerprinting/test/mochitest/mochitest.ini
browser/components/resistfingerprinting/test/mochitest/test_hide_gamepad_info.html
browser/components/resistfingerprinting/test/mochitest/test_hide_gamepad_info_iframe.html
--- a/browser/components/resistfingerprinting/test/mochitest/mochitest.ini
+++ b/browser/components/resistfingerprinting/test/mochitest/mochitest.ini
@@ -1,8 +1,10 @@
 [DEFAULT]
 tags = resistfingerprinting
 support-files =
   worker_child.js
   worker_grandchild.js
 
 [test_device_sensor_event.html]
 [test_reduce_time_precision.html]
+[test_hide_gamepad_info.html]
+support-files = test_hide_gamepad_info_iframe.html
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/mochitest/test_hide_gamepad_info.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<meta charset="utf8">
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<script>
+/* global SimpleTest SpecialPowers */
+
+SimpleTest.waitForExplicitFinish();
+document.addEventListener("DOMContentLoaded", function() {
+  SpecialPowers.pushPrefEnv({
+    set: [
+      ["dom.gamepad.test.enabled", true],
+      ["privacy.resistFingerprinting", true]
+    ]
+  }, function() {
+    // This test loads in an iframe, to ensure that the navigator instance is
+    // loaded with the correct value of the preference.
+    var iframe = document.createElement("iframe");
+    iframe.src = "test_hide_gamepad_info_iframe.html";
+    document.body.appendChild(iframe);
+  });
+});
+</script>
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/mochitest/test_hide_gamepad_info_iframe.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<meta charset="utf8">
+<!--<script src="/tests/SimpleTest/SimpleTest.js"></script>-->
+<script>
+var SimpleTest = window.parent.SimpleTest;
+
+function gamepadEventHandler() {
+  SimpleTest.ok(false, "privacy.resistFingerprinting is true, should not receive any gamepad events");
+}
+
+window.addEventListener("gamepadconnected", gamepadEventHandler);
+window.addEventListener("gamepaddisconnected", gamepadEventHandler);
+window.addEventListener("gamepadbuttondown", gamepadEventHandler);
+
+var GamepadService = navigator.requestGamepadServiceTest();
+GamepadService.addGamepad(
+    "test gamepad", // id
+    GamepadService.standardMapping,
+    GamepadService.noHand,
+    4, // buttons
+    2,
+    0).then((aIndex) => new Promise((aResolve) => {
+      // Press a button to make the gamepad visible to the page.
+      GamepadService.newButtonEvent(aIndex, 0, true, true);
+
+      // Wait for a while in order to guarantee navigator.getGamepads() can
+      // get up-to-date result.
+      setTimeout(() => aResolve(aIndex), 1000);
+    })).then((aIndex) => new Promise((aResolve) => {
+      SimpleTest.is(navigator.getGamepads().length, 0,
+          "privacy.resistFingerprinting is true, navigator.getGamepads() should always return an empty array");
+      GamepadService.removeGamepad(aIndex);
+
+      // Wait for gamepad events to be fired.
+      setTimeout(() => aResolve(), 3000);
+    })).then(() => {
+      SimpleTest.finish();
+    });
+</script>