Bug 1372069 - Part 2: Add a test case for making sure geolocation API has been disabled correctly when 'privacy.resistFingerprinting' is true. r?smaug,arthuredelstein
This patch adds a test case to check whether geolocation API is disabled when
fingerprinting resistance is enabled. The test will check that the successCallback
of geolocation API is not called, but the errorCallback is called with a
PERMISSION_DENIED error when 'privacy.resistFingerprinting' is true.
MozReview-Commit-ID: IyoEMyX5yNP
--- a/browser/components/resistfingerprinting/test/mochitest/.eslintrc.js
+++ b/browser/components/resistfingerprinting/test/mochitest/.eslintrc.js
@@ -1,5 +1,11 @@
+"use strict";
+
module.exports = {
+ "extends": [
+ "plugin:mozilla/mochitest-test"
+ ],
+
"rules": {
"no-eval": "off"
},
};
--- a/browser/components/resistfingerprinting/test/mochitest/mochitest.ini
+++ b/browser/components/resistfingerprinting/test/mochitest/mochitest.ini
@@ -1,10 +1,13 @@
[DEFAULT]
tags = resistfingerprinting
support-files =
worker_child.js
worker_grandchild.js
+ !/dom/tests/mochitest/geolocation/network_geolocation.sjs
[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
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/mochitest/test_geolocation.html
@@ -0,0 +1,69 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1372069
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 1372069</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">
+
+ const BASE_GEO_URL = "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs";
+
+ /** Test for Bug 1372069 **/
+ SimpleTest.waitForExplicitFinish();
+ window.onload = () => {
+ SimpleTest.waitForFocus(() => {
+ SpecialPowers.pushPrefEnv({"set":
+ [
+ ["privacy.resistFingerprinting", true],
+ ["geo.prompt.testing", true],
+ ["geo.prompt.testing.allow", true],
+ ["geo.wifi.uri", BASE_GEO_URL]
+ ]
+ }, doTest_getCurrentPosition);
+ }, window);
+ }
+
+ function doTest_getCurrentPosition() {
+ navigator.geolocation.getCurrentPosition(
+ (position) => {
+ ok(false, "Success callback is not expected to be called");
+ doTest_watchPosition();
+ },
+ (error) => {
+ ok(true, "Check for the error callback to be called for fingerprinting resistance");
+ is(error.code, error.PERMISSION_DENIED, "Check error code for fingerprinting resistance");
+ doTest_watchPosition();
+ }
+ );
+ }
+
+ function doTest_watchPosition() {
+ let wid = navigator.geolocation.watchPosition(
+ (position) => {
+ ok(false, "Success callback is not expected to be called");
+ navigator.geolocation.clearWatch(wid);
+ SimpleTest.finish();
+ },
+ (error) => {
+ ok(true, "Check for the error callback to be called for fingerprinting resistance");
+ is(error.code, error.PERMISSION_DENIED, "Check error code for fingerprinting resistance");
+ navigator.geolocation.clearWatch(wid);
+ SimpleTest.finish();
+ }
+ );
+ }
+ </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>