Bug 1337161 - Add test case
MozReview-Commit-ID: DseKBevAiuR
--- 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>