Bug 863246 - Add test case draft
authorChung-Sheng Fu <cfu@mozilla.com>
Thu, 11 May 2017 16:12:01 +0800
changeset 579941 3352618d64189e148a09a3d9b0455a35b0e349a3
parent 579940 31edb2abf0d2fe11abf9ae9fe79475e8bae21d37
child 629162 a827004c3eb095982969f12bd45f6f7cb774570b
push id59417
push userbmo:cfu@mozilla.com
push dateThu, 18 May 2017 02:41:45 +0000
bugs863246
milestone55.0a1
Bug 863246 - Add test case MozReview-Commit-ID: G7sFwKSTEBc
browser/components/resistfingerprinting/moz.build
browser/components/resistfingerprinting/test/mochitest/.eslintrc.js
browser/components/resistfingerprinting/test/mochitest/mochitest.ini
browser/components/resistfingerprinting/test/mochitest/test_uri_resource.html
--- a/browser/components/resistfingerprinting/moz.build
+++ b/browser/components/resistfingerprinting/moz.build
@@ -5,8 +5,12 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 with Files("**"):
     BUG_COMPONENT = ("Core", "Security")
 
 BROWSER_CHROME_MANIFESTS += [
     'test/browser/browser.ini',
 ]
+
+MOCHITEST_MANIFESTS += [
+    'test/mochitest/mochitest.ini',
+]
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/mochitest/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+  extends: [
+    "plugin:mozilla/browser-test"
+  ]
+};
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/mochitest/mochitest.ini
@@ -0,0 +1,4 @@
+[DEFAULT]
+tags = resistfingerprinting
+
+[test_uri_resource.html]
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/mochitest/test_uri_resource.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<meta charset="utf8">
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<script>
+function printPref(aSrc, aKey, aValue) {
+  // console.log(aSrc + " - " + aKey + ":" + aValue);
+}
+
+var pref = printPref.bind(null, "pref");
+var sticky_pref  = printPref.bind(null, "sticky_pref");
+
+SimpleTest.waitForExplicitFinish();
+document.addEventListener("DOMContentLoaded", function() {
+  var kPrefName = "security.block_resource_uri";
+
+  var createPromise = function(aPrefVal) {
+    return new Promise(async function(aResolve, aReject) {
+      var dom;
+
+      var listener = function(aSucc) {
+        SimpleTest.ok(aSucc, "Loading of URI with scheme resource:// should "
+            + (aPrefVal ? "" : "not ")
+            + "be blocked when preference "
+            + kPrefName
+            + " is "
+            + aPrefVal);
+        aResolve();
+      };
+
+      await SpecialPowers.pushPrefEnv({
+        set: [["security.block_resource_uri", aPrefVal]]
+      });
+      dom = document.createElement("script");
+      dom.onload = listener.bind(dom, !aPrefVal);
+      dom.onerror = listener.bind(dom, aPrefVal);
+      document.head.appendChild(dom);
+      dom.src = "resource:///defaults/preferences/firefox.js";
+    });
+  };
+
+  Promise.resolve(createPromise(true))
+    .then(() => createPromise(false))
+    .then(() => SimpleTest.finish());
+});
+</script>