Bug 1221365 - Tests for "Is origin potentially trustworthy?" logic. r=ckerschb r=bkelly, a=ritu
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Fri, 06 Nov 2015 11:10:08 -0800
changeset 291486 d35eb3ac914be5e51e8b336cecb06eca5d90144c
parent 291485 9814dd56b94ff808c2a036bbad902f16eba944c1
child 291487 86a326cd514626d8ec7b603cddae345da95f298e
push id8711
push usercbook@mozilla.com
push dateThu, 12 Nov 2015 10:43:53 +0000
treeherdermozilla-aurora@0e9c6096f7e9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb, bkelly, ritu
bugs1221365
milestone44.0a2
Bug 1221365 - Tests for "Is origin potentially trustworthy?" logic. r=ckerschb r=bkelly, a=ritu
dom/security/test/unit/test_isURIPotentiallyTrustworthy.js
dom/security/test/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/dom/security/test/unit/test_isURIPotentiallyTrustworthy.js
@@ -0,0 +1,32 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/*
+ * Tests the "Is origin potentially trustworthy?" logic from
+ * <https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy>.
+ */
+
+const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
+
+Cu.import("resource://gre/modules/NetUtil.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyServiceGetter(this, "gContentSecurityManager",
+                                   "@mozilla.org/contentsecuritymanager;1",
+                                   "nsIContentSecurityManager");
+
+add_task(function* test_isURIPotentiallyTrustworthy() {
+  for (let [uriSpec, expectedResult] of [
+    ["http://example.com/", false],
+    ["https://example.com/", true],
+    ["http://localhost/", true],
+    ["http://127.0.0.1/", true],
+    ["file:///", true],
+    ["about:config", false],
+    ["urn:generic", false],
+  ]) {
+    let uri = NetUtil.newURI(uriSpec);
+    Assert.equal(gContentSecurityManager.isURIPotentiallyTrustworthy(uri),
+                 expectedResult);
+  }
+});
--- a/dom/security/test/unit/xpcshell.ini
+++ b/dom/security/test/unit/xpcshell.ini
@@ -1,7 +1,8 @@
 [DEFAULT]
 head =
 tail =
 skip-if = toolkit == 'gonk'
 
 [test_csp_reports.js]
 skip-if = buildapp == 'mulet'
+[test_isURIPotentiallyTrustworthy.js]