Bug 1221365 - Tests for "Is origin potentially trustworthy?" logic. r=ckerschb,bkelly

This commit is contained in:
Paolo Amadini 2015-11-06 11:10:08 -08:00
Родитель a0a2b249c4
Коммит 0238bd1276
2 изменённых файлов: 33 добавлений и 0 удалений

Просмотреть файл

@ -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);
}
});

Просмотреть файл

@ -5,3 +5,4 @@ skip-if = toolkit == 'gonk'
[test_csp_reports.js]
skip-if = buildapp == 'mulet'
[test_isURIPotentiallyTrustworthy.js]