Bug 1337161 - Add test case draft
authorChung-Sheng Fu <cfu@mozilla.com>
Mon, 19 Jun 2017 10:11:24 +0800
changeset 601615 ca03bce8b0947b4a8dd799444ec98e5331543830
parent 601614 2ea460876c4264654c1300119efb763491a4c4f4
child 601616 863567c6a69e00f08d53626babf90902bf69ad1d
push id66146
push userbmo:cfu@mozilla.com
push dateWed, 28 Jun 2017 23:15:04 +0000
bugs1337161
milestone56.0a1
Bug 1337161 - Add test case 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>