Bug 1361859 - Enable eslint on caps/ directory; r=standard8

Stop excluding caps/ from eslint runs and apply mozilla/recommended rules.
This generally affects xpcshell and mochitest files under caps/tests.
Includes many mechanical changes to comply with mozilla recommended
formatting rules.
This commit is contained in:
Geoff Brown 2017-05-08 07:49:06 -06:00
parent 78c5013b6a
commit 21d0203054
10 changed files with 150 additions and 128 deletions

View file

@ -9,7 +9,6 @@ obj*/**
# below. # below.
addon-sdk/** addon-sdk/**
build/** build/**
caps/**
chrome/** chrome/**
config/** config/**
db/** db/**
@ -78,6 +77,9 @@ browser/extensions/activity-stream/vendor/**
# imported from chromium # imported from chromium
browser/extensions/mortar/** browser/extensions/mortar/**
# caps/ exclusions
caps/tests/mochitest/browser_checkloaduri.js
# devtools/ exclusions # devtools/ exclusions
devtools/client/canvasdebugger/** devtools/client/canvasdebugger/**
devtools/client/commandline/** devtools/client/commandline/**

7
caps/.eslintrc.js Normal file
View file

@ -0,0 +1,7 @@
"use strict";
module.exports = {
"extends": [
"plugin:mozilla/recommended"
]
};

View file

@ -0,0 +1,8 @@
"use strict";
module.exports = {
"extends": [
"plugin:mozilla/mochitest-test",
"plugin:mozilla/browser-test"
]
};

View file

@ -22,8 +22,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1180921
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
let oldAddonIdCallback = aps.setExtensionURIToAddonIdCallback(uri => uri.host); let oldAddonIdCallback = aps.setExtensionURIToAddonIdCallback(uri => uri.host);
SimpleTest.registerCleanupFunction(function() { SimpleTest.registerCleanupFunction(function() {
aps.setAddonLoadURICallback('addona', null); aps.setAddonLoadURICallback("addona", null);
aps.setAddonLoadURICallback('addonb', null); aps.setAddonLoadURICallback("addonb", null);
aps.setExtensionURIToAddonIdCallback(oldAddonIdCallback); aps.setExtensionURIToAddonIdCallback(oldAddonIdCallback);
}); });
@ -41,28 +41,28 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1180921
return p; return p;
} }
let addonA = new Cu.Sandbox(ssm.createCodebasePrincipal(Services.io.newURI('moz-extension://addonA/'), {}), let addonA = new Cu.Sandbox(ssm.createCodebasePrincipal(Services.io.newURI("moz-extension://addonA/"), {}),
{wantGlobalProperties: ['XMLHttpRequest']}); {wantGlobalProperties: ["XMLHttpRequest"]});
let addonB = new Cu.Sandbox(ssm.createCodebasePrincipal(Services.io.newURI('moz-extension://addonB/'), {}), let addonB = new Cu.Sandbox(ssm.createCodebasePrincipal(Services.io.newURI("moz-extension://addonB/"), {}),
{wantGlobalProperties: ['XMLHttpRequest']}); {wantGlobalProperties: ["XMLHttpRequest"]});
function uriForDomain(d) { return d + '/tests/caps/tests/mochitest/file_data.txt' } function uriForDomain(d) { return d + "/tests/caps/tests/mochitest/file_data.txt" }
tryLoad(addonA, uriForDomain('http://test1.example.org')) tryLoad(addonA, uriForDomain("http://test1.example.org"))
.then(function(success) { .then(function(success) {
ok(!success, "cross-origin load should fail for addon A"); ok(!success, "cross-origin load should fail for addon A");
aps.setAddonLoadURICallback('addona', function(uri) { return /test1/.test(uri.host); }); aps.setAddonLoadURICallback("addona", function(uri) { return /test1/.test(uri.host); });
aps.setAddonLoadURICallback('addonb', function(uri) { return /test2/.test(uri.host); }); aps.setAddonLoadURICallback("addonb", function(uri) { return /test2/.test(uri.host); });
return tryLoad(addonA, uriForDomain('http://test1.example.org')); return tryLoad(addonA, uriForDomain("http://test1.example.org"));
}).then(function(success) { }).then(function(success) {
ok(success, "whitelisted cross-origin load of test1 should succeed for addon A"); ok(success, "whitelisted cross-origin load of test1 should succeed for addon A");
return tryLoad(addonB, uriForDomain('http://test1.example.org')); return tryLoad(addonB, uriForDomain("http://test1.example.org"));
}).then(function(success) { }).then(function(success) {
ok(!success, "non-whitelisted cross-origin load of test1 should fail for addon B"); ok(!success, "non-whitelisted cross-origin load of test1 should fail for addon B");
return tryLoad(addonB, uriForDomain('http://test2.example.org')); return tryLoad(addonB, uriForDomain("http://test2.example.org"));
}).then(function(success) { }).then(function(success) {
ok(success, "whitelisted cross-origin load of test2 should succeed for addon B"); ok(success, "whitelisted cross-origin load of test2 should succeed for addon B");
return tryLoad(addonA, uriForDomain('http://test2.example.org')); return tryLoad(addonA, uriForDomain("http://test2.example.org"));
}).then(function(success) { }).then(function(success) {
ok(!success, "non-whitelisted cross-origin load of test2 should fail for addon A"); ok(!success, "non-whitelisted cross-origin load of test2 should fail for addon A");
SimpleTest.finish(); SimpleTest.finish();

View file

@ -21,35 +21,31 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=246699
** Test for Bug 246699 ** Test for Bug 246699
** (should produce stack information for caps errors) ** (should produce stack information for caps errors)
**/ **/
function isError(e) function isError(e) {
{
return e.constructor.name === "Error" || e.constructor.name === "TypeError"; return e.constructor.name === "Error" || e.constructor.name === "TypeError";
} }
function hasStack(e) function hasStack(e) {
{
return isError(e) && /inciteCaps/.test(e.stack); return isError(e) && /inciteCaps/.test(e.stack);
} }
function inciteCaps(f) function inciteCaps(f) {
{
try { try {
f(); f();
return "operation succeeded"; return "operation succeeded";
} catch (e if hasStack(e)) {
return "denied-stack";
} catch (e) { } catch (e) {
if (hasStack(e)) {
return "denied-stack";
}
return "unexpected: " + e; return "unexpected: " + e;
} }
} }
function tryChromeLoad() function tryChromeLoad() {
{
window.frames[0].location = "chrome://global/content/mozilla.xhtml"; window.frames[0].location = "chrome://global/content/mozilla.xhtml";
} }
function tryComponentsClasses() function tryComponentsClasses() {
{
return SpecialPowers.Components.classes["@mozilla.org/dummy;1"]; return SpecialPowers.Components.classes["@mozilla.org/dummy;1"];
} }

View file

@ -25,6 +25,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=292789
** even for ALLOW_CHROME mechanisms (<script>, <img> etc) ** even for ALLOW_CHROME mechanisms (<script>, <img> etc)
**/ **/
/* import-globals-from ../../../toolkit/content/treeUtils.js */
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
/** <script src=""> test **/ /** <script src=""> test **/
@ -75,14 +77,14 @@ function finishTest() {
function fail(event) { function fail(event) {
is("fail", event.target.expected, is("fail", event.target.expected,
"content should not be allowed to load "+event.target.src); "content should not be allowed to load " + event.target.src);
if (event.target.callback) if (event.target.callback)
event.target.callback(); event.target.callback();
} }
function success(event) { function success(event) {
is("success", event.target.expected, is("success", event.target.expected,
"content should be able to load "+event.target.src); "content should be able to load " + event.target.src);
if (event.target.callback) if (event.target.callback)
event.target.callback(); event.target.callback();
} }
@ -94,7 +96,7 @@ function loadImage(uri, expect, callback) {
img.expected = expect; img.expected = expect;
img.callback = callback; img.callback = callback;
img.src = uri; img.src = uri;
//document.getElementById("content").appendChild(img); // document.getElementById("content").appendChild(img);
} }
// Start off the script src test, and have it start the img tests when complete. // Start off the script src test, and have it start the img tests when complete.

View file

@ -21,14 +21,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=423375
** Test for Bug 423375 ** Test for Bug 423375
** (content shouldn't be able to load chrome: or resource:) ** (content shouldn't be able to load chrome: or resource:)
**/ **/
function tryLoad(url) function tryLoad(url) {
{
try { try {
window.frames[0].location = url; window.frames[0].location = url;
return "loaded"; return "loaded";
} catch (e if /Access.*denied/.test(String(e))) {
return "denied";
} catch (e) { } catch (e) {
if (/Access.*denied/.test(String(e))) {
return "denied";
}
return "unexpected: " + e; return "unexpected: " + e;
} }
} }

View file

@ -23,8 +23,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1161831
.QueryInterface(SpecialPowers.Ci.nsISubstitutingProtocolHandler); .QueryInterface(SpecialPowers.Ci.nsISubstitutingProtocolHandler);
SimpleTest.registerCleanupFunction(function() { SimpleTest.registerCleanupFunction(function() {
extensionHandler.setSubstitution('cherise', null); extensionHandler.setSubstitution("cherise", null);
extensionHandler.setSubstitution('liebchen', null); extensionHandler.setSubstitution("liebchen", null);
aps.setExtensionURILoadCallback(oldLoadCallback); aps.setExtensionURILoadCallback(oldLoadCallback);
aps.setExtensionURIToAddonIdCallback(oldMapCallback); aps.setExtensionURIToAddonIdCallback(oldMapCallback);
}); });
@ -33,16 +33,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1161831
// First, get a file:// URI to something - open to suggestions on how to do // First, get a file:// URI to something - open to suggestions on how to do
// this more easily. // this more easily.
var resURI = SpecialPowers.Services.io.newURI('resource://testing-common/resource_test_file.html'); var resURI = SpecialPowers.Services.io.newURI("resource://testing-common/resource_test_file.html");
var filePath = resourceHandler.resolveURI(resURI); var filePath = resourceHandler.resolveURI(resURI);
ok(filePath.startsWith('file://'), 'resource:// URI resolves where we expect: ' + filePath); ok(filePath.startsWith("file://"), "resource:// URI resolves where we expect: " + filePath);
var fileURI = SpecialPowers.Services.io.newURI(filePath); var fileURI = SpecialPowers.Services.io.newURI(filePath);
// Register a moz-extension:// URI. // Register a moz-extension:// URI.
extensionHandler.setSubstitution('cherise', fileURI); extensionHandler.setSubstitution("cherise", fileURI);
// Alias the above. // Alias the above.
extensionHandler.setSubstitution('liebchen', SpecialPowers.Services.io.newURI('moz-extension://cherise')); extensionHandler.setSubstitution("liebchen", SpecialPowers.Services.io.newURI("moz-extension://cherise"));
// //
// Make sure that non-file:// URIs don't work. // Make sure that non-file:// URIs don't work.
@ -50,7 +50,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1161831
// resource:// // resource://
try { try {
extensionHandler.setSubstitution('interdit', resURI); extensionHandler.setSubstitution("interdit", resURI);
ok(false, "Should have thrown for mapping moz-extension to resource"); ok(false, "Should have thrown for mapping moz-extension to resource");
} catch (e) { } catch (e) {
ok(true, "Threw correctly: " + e); ok(true, "Threw correctly: " + e);
@ -58,15 +58,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1161831
// chrome:// // chrome://
try { try {
var chromeURI = SpecialPowers.Services.io.newURI('chrome://global/content/mozilla.xhtml'); var chromeURI = SpecialPowers.Services.io.newURI("chrome://global/content/mozilla.xhtml");
extensionHandler.setSubstitution('verboten', chromeURI); extensionHandler.setSubstitution("verboten", chromeURI);
ok(false, "Should have thrown for mapping moz-extension to chrome"); ok(false, "Should have thrown for mapping moz-extension to chrome");
} catch (e) { } catch (e) {
ok(true, "Threw correctly: " + e); ok(true, "Threw correctly: " + e);
} }
function navigateWithLocation(ifr, url) { ifr.contentWindow.location = url; } function navigateWithLocation(ifr, url) { ifr.contentWindow.location = url; }
function navigateWithSrc(ifr, url) { ifr.setAttribute('src', url); } function navigateWithSrc(ifr, url) { ifr.setAttribute("src", url); }
function navigateFromChromeWithLocation(ifr, url) { SpecialPowers.wrap(ifr).contentWindow.location = url; } function navigateFromChromeWithLocation(ifr, url) { SpecialPowers.wrap(ifr).contentWindow.location = url; }
function navigateFromChromeWithWebNav(ifr, url) { function navigateFromChromeWithWebNav(ifr, url) {
SpecialPowers.wrap(ifr).contentWindow SpecialPowers.wrap(ifr).contentWindow
@ -81,25 +81,25 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1161831
aps.setExtensionURILoadCallback(cb); aps.setExtensionURILoadCallback(cb);
} }
aps.setExtensionURIToAddonIdCallback(SpecialPowers.wrapCallback(function (uri) { return 'imaginaryaddon-' + uri.host[0]; })); aps.setExtensionURIToAddonIdCallback(SpecialPowers.wrapCallback(function(uri) { return "imaginaryaddon-" + uri.host[0]; }));
function testLoad(url, navigate, shouldThrow) { function testLoad(url, navigate, shouldThrow) {
var ifr = document.createElement('iframe'); var ifr = document.createElement("iframe");
var p = new Promise(function(resolve, reject) { var p = new Promise(function(resolve, reject) {
ifr.onload = function() { ifr.onload = function() {
ok(true, 'Loaded ' + url); ok(true, "Loaded " + url);
var prin = SpecialPowers.wrap(ifr.contentWindow).document.nodePrincipal; var prin = SpecialPowers.wrap(ifr.contentWindow).document.nodePrincipal;
function stripTrailingSlash(s) { return s.replace(/\/$/, ''); }; function stripTrailingSlash(s) { return s.replace(/\/$/, ""); }
is(stripTrailingSlash(prin.URI.spec), url, 'Principal uri is correct: ' + url); is(stripTrailingSlash(prin.URI.spec), url, "Principal uri is correct: " + url);
function stripPath(s) { return s.replace(/(.*\/\/.+)\/.*/, '$1'); }; function stripPath(s) { return s.replace(/(.*\/\/.+)\/.*/, "$1"); }
is(prin.originNoSuffix, stripPath(url), 'Principal origin is correct: ' + prin.originNoSuffix); is(prin.originNoSuffix, stripPath(url), "Principal origin is correct: " + prin.originNoSuffix);
is(prin.addonId, 'imaginaryaddon-' + url[url.indexOf('/') + 2], 'addonId is correct'); is(prin.addonId, "imaginaryaddon-" + url[url.indexOf("/") + 2], "addonId is correct");
if (/_blank/.test(url)) { if (/_blank/.test(url)) {
is(SpecialPowers.wrap(ifr.contentWindow).document.documentElement.innerHTML, is(SpecialPowers.wrap(ifr.contentWindow).document.documentElement.innerHTML,
'<head></head><body></body>', 'blank document looks right'); "<head></head><body></body>", "blank document looks right");
} else { } else {
is(SpecialPowers.wrap(ifr.contentWindow).document.title, 'resource test file', is(SpecialPowers.wrap(ifr.contentWindow).document.title, "resource test file",
'document looks right'); "document looks right");
} }
ifr.remove(); ifr.remove();
resolve(); resolve();
@ -134,20 +134,20 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1161831
// //
// Perform some loads and make sure they work correctly. // Perform some loads and make sure they work correctly.
// //
testLoad.bind(null, 'moz-extension://cherise', navigateFromChromeWithLocation)() testLoad.bind(null, "moz-extension://cherise", navigateFromChromeWithLocation)()
.then(testLoad.bind(null, 'moz-extension://cherise', navigateFromChromeWithWebNav)) .then(testLoad.bind(null, "moz-extension://cherise", navigateFromChromeWithWebNav))
.then(testLoad.bind(null, 'moz-extension://cherise', navigateWithLocation, /* shouldThrow = */ true)) .then(testLoad.bind(null, "moz-extension://cherise", navigateWithLocation, /* shouldThrow = */ true))
.then(testXHR.bind(null, 'moz-extension://cherise', /* shouldError = */ true)) .then(testXHR.bind(null, "moz-extension://cherise", /* shouldError = */ true))
.then(setWhitelistCallback.bind(null, /cherise/)) .then(setWhitelistCallback.bind(null, /cherise/))
.then(testLoad.bind(null, 'moz-extension://cherise', navigateWithLocation)) .then(testLoad.bind(null, "moz-extension://cherise", navigateWithLocation))
.then(testXHR.bind(null, 'moz-extension://cherise')) .then(testXHR.bind(null, "moz-extension://cherise"))
.then(testLoad.bind(null, 'moz-extension://liebchen', navigateWithLocation, /* shouldThrow = */ true)) .then(testLoad.bind(null, "moz-extension://liebchen", navigateWithLocation, /* shouldThrow = */ true))
.then(testXHR.bind(null, 'moz-extension://liebchen', /* shouldError = */ true)) .then(testXHR.bind(null, "moz-extension://liebchen", /* shouldError = */ true))
.then(setWhitelistCallback.bind(null, /cherise|liebchen/)) .then(setWhitelistCallback.bind(null, /cherise|liebchen/))
.then(testLoad.bind(null, 'moz-extension://liebchen', navigateWithLocation)) .then(testLoad.bind(null, "moz-extension://liebchen", navigateWithLocation))
.then(testLoad.bind(null, 'moz-extension://liebchen', navigateWithSrc)) .then(testLoad.bind(null, "moz-extension://liebchen", navigateWithSrc))
.then(testLoad.bind(null, 'moz-extension://cherise', navigateWithSrc)) .then(testLoad.bind(null, "moz-extension://cherise", navigateWithSrc))
.then(testLoad.bind(null, 'moz-extension://cherise/_blank.html', navigateWithSrc)) .then(testLoad.bind(null, "moz-extension://cherise/_blank.html", navigateWithSrc))
.then(SimpleTest.finish.bind(SimpleTest), .then(SimpleTest.finish.bind(SimpleTest),
function(e) { ok(false, "rejected promise: " + e); SimpleTest.finish() } function(e) { ok(false, "rejected promise: " + e); SimpleTest.finish() }
); );

View file

@ -0,0 +1,7 @@
"use strict";
module.exports = {
"extends": [
"plugin:mozilla/xpcshell-test"
]
};

View file

@ -25,10 +25,10 @@ function checkOriginAttributes(prin, attrs, suffix) {
attrs = attrs || {}; attrs = attrs || {};
do_check_eq(prin.originAttributes.appId, attrs.appId || 0); do_check_eq(prin.originAttributes.appId, attrs.appId || 0);
do_check_eq(prin.originAttributes.inIsolatedMozBrowser, attrs.inIsolatedMozBrowser || false); do_check_eq(prin.originAttributes.inIsolatedMozBrowser, attrs.inIsolatedMozBrowser || false);
do_check_eq(prin.originSuffix, suffix || ''); do_check_eq(prin.originSuffix, suffix || "");
do_check_eq(ChromeUtils.originAttributesToSuffix(attrs), suffix || ''); do_check_eq(ChromeUtils.originAttributesToSuffix(attrs), suffix || "");
do_check_true(ChromeUtils.originAttributesMatchPattern(prin.originAttributes, attrs)); do_check_true(ChromeUtils.originAttributesMatchPattern(prin.originAttributes, attrs));
if (!prin.isNullPrincipal && !prin.origin.startsWith('[')) { if (!prin.isNullPrincipal && !prin.origin.startsWith("[")) {
do_check_true(ssm.createCodebasePrincipalFromOrigin(prin.origin).equals(prin)); do_check_true(ssm.createCodebasePrincipalFromOrigin(prin.origin).equals(prin));
} else { } else {
checkThrows(() => ssm.createCodebasePrincipalFromOrigin(prin.origin)); checkThrows(() => ssm.createCodebasePrincipalFromOrigin(prin.origin));
@ -55,33 +55,33 @@ function printAttrs(name, attrs) {
function checkValues(attrs, values) { function checkValues(attrs, values) {
values = values || {}; values = values || {};
//printAttrs("attrs", attrs); // printAttrs("attrs", attrs);
//printAttrs("values", values); // printAttrs("values", values);
do_check_eq(attrs.appId, values.appId || 0); do_check_eq(attrs.appId, values.appId || 0);
do_check_eq(attrs.userContextId, values.userContextId || 0); do_check_eq(attrs.userContextId, values.userContextId || 0);
do_check_eq(attrs.inIsolatedMozBrowser, values.inIsolatedMozBrowser || false); do_check_eq(attrs.inIsolatedMozBrowser, values.inIsolatedMozBrowser || false);
do_check_eq(attrs.privateBrowsingId, values.privateBrowsingId || ''); do_check_eq(attrs.privateBrowsingId, values.privateBrowsingId || "");
do_check_eq(attrs.firstPartyDomain, values.firstPartyDomain || ''); do_check_eq(attrs.firstPartyDomain, values.firstPartyDomain || "");
} }
function run_test() { function run_test() {
// Attributeless origins. // Attributeless origins.
do_check_eq(ssm.getSystemPrincipal().origin, '[System Principal]'); do_check_eq(ssm.getSystemPrincipal().origin, "[System Principal]");
checkOriginAttributes(ssm.getSystemPrincipal()); checkOriginAttributes(ssm.getSystemPrincipal());
var exampleOrg = ssm.createCodebasePrincipal(makeURI('http://example.org'), {}); var exampleOrg = ssm.createCodebasePrincipal(makeURI("http://example.org"), {});
do_check_eq(exampleOrg.origin, 'http://example.org'); do_check_eq(exampleOrg.origin, "http://example.org");
checkOriginAttributes(exampleOrg); checkOriginAttributes(exampleOrg);
var exampleCom = ssm.createCodebasePrincipal(makeURI('https://www.example.com:123'), {}); var exampleCom = ssm.createCodebasePrincipal(makeURI("https://www.example.com:123"), {});
do_check_eq(exampleCom.origin, 'https://www.example.com:123'); do_check_eq(exampleCom.origin, "https://www.example.com:123");
checkOriginAttributes(exampleCom); checkOriginAttributes(exampleCom);
var nullPrin = Cu.getObjectPrincipal(new Cu.Sandbox(null)); var nullPrin = Cu.getObjectPrincipal(new Cu.Sandbox(null));
do_check_true(/^moz-nullprincipal:\{([0-9]|[a-z]|\-){36}\}$/.test(nullPrin.origin)); do_check_true(/^moz-nullprincipal:\{([0-9]|[a-z]|\-){36}\}$/.test(nullPrin.origin));
checkOriginAttributes(nullPrin); checkOriginAttributes(nullPrin);
var ipv6Prin = ssm.createCodebasePrincipal(makeURI('https://[2001:db8::ff00:42:8329]:123'), {}); var ipv6Prin = ssm.createCodebasePrincipal(makeURI("https://[2001:db8::ff00:42:8329]:123"), {});
do_check_eq(ipv6Prin.origin, 'https://[2001:db8::ff00:42:8329]:123'); do_check_eq(ipv6Prin.origin, "https://[2001:db8::ff00:42:8329]:123");
checkOriginAttributes(ipv6Prin); checkOriginAttributes(ipv6Prin);
var ipv6NPPrin = ssm.createCodebasePrincipal(makeURI('https://[2001:db8::ff00:42:8329]'), {}); var ipv6NPPrin = ssm.createCodebasePrincipal(makeURI("https://[2001:db8::ff00:42:8329]"), {});
do_check_eq(ipv6NPPrin.origin, 'https://[2001:db8::ff00:42:8329]'); do_check_eq(ipv6NPPrin.origin, "https://[2001:db8::ff00:42:8329]");
checkOriginAttributes(ipv6NPPrin); checkOriginAttributes(ipv6NPPrin);
var ep = Cu.getObjectPrincipal(Cu.Sandbox([exampleCom, nullPrin, exampleOrg])); var ep = Cu.getObjectPrincipal(Cu.Sandbox([exampleCom, nullPrin, exampleOrg]));
checkOriginAttributes(ep); checkOriginAttributes(ep);
@ -92,42 +92,42 @@ function run_test() {
do_check_eq(ep.origin, `[Expanded Principal [${exampleOrg.origin}, ${exampleCom.origin}, ${nullPrin.origin}]]`); do_check_eq(ep.origin, `[Expanded Principal [${exampleOrg.origin}, ${exampleCom.origin}, ${nullPrin.origin}]]`);
// Make sure createCodebasePrincipal does what the rest of gecko does. // Make sure createCodebasePrincipal does what the rest of gecko does.
do_check_true(exampleOrg.equals(Cu.getObjectPrincipal(new Cu.Sandbox('http://example.org')))); do_check_true(exampleOrg.equals(Cu.getObjectPrincipal(new Cu.Sandbox("http://example.org"))));
// //
// Test origin attributes. // Test origin attributes.
// //
// Just app. // Just app.
var exampleOrg_app = ssm.createCodebasePrincipal(makeURI('http://example.org'), {appId: 42}); var exampleOrg_app = ssm.createCodebasePrincipal(makeURI("http://example.org"), {appId: 42});
var nullPrin_app = ssm.createNullPrincipal({appId: 42}); var nullPrin_app = ssm.createNullPrincipal({appId: 42});
checkOriginAttributes(exampleOrg_app, {appId: 42}, '^appId=42'); checkOriginAttributes(exampleOrg_app, {appId: 42}, "^appId=42");
checkOriginAttributes(nullPrin_app, {appId: 42}, '^appId=42'); checkOriginAttributes(nullPrin_app, {appId: 42}, "^appId=42");
do_check_eq(exampleOrg_app.origin, 'http://example.org^appId=42'); do_check_eq(exampleOrg_app.origin, "http://example.org^appId=42");
// Just browser. // Just browser.
var exampleOrg_browser = ssm.createCodebasePrincipal(makeURI('http://example.org'), {inIsolatedMozBrowser: true}); var exampleOrg_browser = ssm.createCodebasePrincipal(makeURI("http://example.org"), {inIsolatedMozBrowser: true});
var nullPrin_browser = ssm.createNullPrincipal({inIsolatedMozBrowser: true}); var nullPrin_browser = ssm.createNullPrincipal({inIsolatedMozBrowser: true});
checkOriginAttributes(exampleOrg_browser, {inIsolatedMozBrowser: true}, '^inBrowser=1'); checkOriginAttributes(exampleOrg_browser, {inIsolatedMozBrowser: true}, "^inBrowser=1");
checkOriginAttributes(nullPrin_browser, {inIsolatedMozBrowser: true}, '^inBrowser=1'); checkOriginAttributes(nullPrin_browser, {inIsolatedMozBrowser: true}, "^inBrowser=1");
do_check_eq(exampleOrg_browser.origin, 'http://example.org^inBrowser=1'); do_check_eq(exampleOrg_browser.origin, "http://example.org^inBrowser=1");
// App and browser. // App and browser.
var exampleOrg_appBrowser = ssm.createCodebasePrincipal(makeURI('http://example.org'), {inIsolatedMozBrowser: true, appId: 42}); var exampleOrg_appBrowser = ssm.createCodebasePrincipal(makeURI("http://example.org"), {inIsolatedMozBrowser: true, appId: 42});
var nullPrin_appBrowser = ssm.createNullPrincipal({inIsolatedMozBrowser: true, appId: 42}); var nullPrin_appBrowser = ssm.createNullPrincipal({inIsolatedMozBrowser: true, appId: 42});
checkOriginAttributes(exampleOrg_appBrowser, {appId: 42, inIsolatedMozBrowser: true}, '^appId=42&inBrowser=1'); checkOriginAttributes(exampleOrg_appBrowser, {appId: 42, inIsolatedMozBrowser: true}, "^appId=42&inBrowser=1");
checkOriginAttributes(nullPrin_appBrowser, {appId: 42, inIsolatedMozBrowser: true}, '^appId=42&inBrowser=1'); checkOriginAttributes(nullPrin_appBrowser, {appId: 42, inIsolatedMozBrowser: true}, "^appId=42&inBrowser=1");
do_check_eq(exampleOrg_appBrowser.origin, 'http://example.org^appId=42&inBrowser=1'); do_check_eq(exampleOrg_appBrowser.origin, "http://example.org^appId=42&inBrowser=1");
// App and browser, different domain. // App and browser, different domain.
var exampleCom_appBrowser = ssm.createCodebasePrincipal(makeURI('https://www.example.com:123'), {appId: 42, inIsolatedMozBrowser: true}); var exampleCom_appBrowser = ssm.createCodebasePrincipal(makeURI("https://www.example.com:123"), {appId: 42, inIsolatedMozBrowser: true});
checkOriginAttributes(exampleCom_appBrowser, {appId: 42, inIsolatedMozBrowser: true}, '^appId=42&inBrowser=1'); checkOriginAttributes(exampleCom_appBrowser, {appId: 42, inIsolatedMozBrowser: true}, "^appId=42&inBrowser=1");
do_check_eq(exampleCom_appBrowser.origin, 'https://www.example.com:123^appId=42&inBrowser=1'); do_check_eq(exampleCom_appBrowser.origin, "https://www.example.com:123^appId=42&inBrowser=1");
// First party Uri // First party Uri
var exampleOrg_firstPartyDomain = ssm.createCodebasePrincipal(makeURI('http://example.org'), {firstPartyDomain: 'example.org'}); var exampleOrg_firstPartyDomain = ssm.createCodebasePrincipal(makeURI("http://example.org"), {firstPartyDomain: "example.org"});
checkOriginAttributes(exampleOrg_firstPartyDomain, { firstPartyDomain: "example.org" }, '^firstPartyDomain=example.org'); checkOriginAttributes(exampleOrg_firstPartyDomain, { firstPartyDomain: "example.org" }, "^firstPartyDomain=example.org");
do_check_eq(exampleOrg_firstPartyDomain.origin, 'http://example.org^firstPartyDomain=example.org'); do_check_eq(exampleOrg_firstPartyDomain.origin, "http://example.org^firstPartyDomain=example.org");
// Make sure we don't crash when serializing principals with UNKNOWN_APP_ID. // Make sure we don't crash when serializing principals with UNKNOWN_APP_ID.
try { try {
@ -136,7 +136,7 @@ function run_test() {
let pipe = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe); let pipe = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe);
pipe.init(false, false, 0, 0xffffffff, null); pipe.init(false, false, 0, 0xffffffff, null);
binaryStream.setOutputStream(pipe.outputStream); binaryStream.setOutputStream(pipe.outputStream);
binaryStream.writeCompoundObject(simplePrin, Ci.nsISupports, true); binaryStream.writeCompoundObject(simplePrin, Ci.nsISupports, true); // eslint-disable-line no-undef
binaryStream.close(); binaryStream.close();
} catch (e) { } catch (e) {
do_check_true(true); do_check_true(true);
@ -144,24 +144,24 @@ function run_test() {
// Just userContext. // Just userContext.
var exampleOrg_userContext = ssm.createCodebasePrincipal(makeURI('http://example.org'), {userContextId: 42}); var exampleOrg_userContext = ssm.createCodebasePrincipal(makeURI("http://example.org"), {userContextId: 42});
checkOriginAttributes(exampleOrg_userContext, { userContextId: 42 }, '^userContextId=42'); checkOriginAttributes(exampleOrg_userContext, { userContextId: 42 }, "^userContextId=42");
do_check_eq(exampleOrg_userContext.origin, 'http://example.org^userContextId=42'); do_check_eq(exampleOrg_userContext.origin, "http://example.org^userContextId=42");
// UserContext and App. // UserContext and App.
var exampleOrg_userContextApp = ssm.createCodebasePrincipal(makeURI('http://example.org'), {appId: 24, userContextId: 42}); var exampleOrg_userContextApp = ssm.createCodebasePrincipal(makeURI("http://example.org"), {appId: 24, userContextId: 42});
var nullPrin_userContextApp = ssm.createNullPrincipal({appId: 24, userContextId: 42}); var nullPrin_userContextApp = ssm.createNullPrincipal({appId: 24, userContextId: 42});
checkOriginAttributes(exampleOrg_userContextApp, {appId: 24, userContextId: 42}, '^appId=24&userContextId=42'); checkOriginAttributes(exampleOrg_userContextApp, {appId: 24, userContextId: 42}, "^appId=24&userContextId=42");
checkOriginAttributes(nullPrin_userContextApp, {appId: 24, userContextId: 42}, '^appId=24&userContextId=42'); checkOriginAttributes(nullPrin_userContextApp, {appId: 24, userContextId: 42}, "^appId=24&userContextId=42");
do_check_eq(exampleOrg_userContextApp.origin, 'http://example.org^appId=24&userContextId=42'); do_check_eq(exampleOrg_userContextApp.origin, "http://example.org^appId=24&userContextId=42");
checkSandboxOriginAttributes(null, {}); checkSandboxOriginAttributes(null, {});
checkSandboxOriginAttributes('http://example.org', {}); checkSandboxOriginAttributes("http://example.org", {});
checkSandboxOriginAttributes('http://example.org', {}, {originAttributes: {}}); checkSandboxOriginAttributes("http://example.org", {}, {originAttributes: {}});
checkSandboxOriginAttributes('http://example.org', {appId: 42}, {originAttributes: {appId: 42}}); checkSandboxOriginAttributes("http://example.org", {appId: 42}, {originAttributes: {appId: 42}});
checkSandboxOriginAttributes(['http://example.org'], {}); checkSandboxOriginAttributes(["http://example.org"], {});
checkSandboxOriginAttributes(['http://example.org'], {}, {originAttributes: {}}); checkSandboxOriginAttributes(["http://example.org"], {}, {originAttributes: {}});
checkSandboxOriginAttributes(['http://example.org'], {appId: 42}, {originAttributes: {appId: 42}}); checkSandboxOriginAttributes(["http://example.org"], {appId: 42}, {originAttributes: {appId: 42}});
// Check that all of the above are cross-origin. // Check that all of the above are cross-origin.
checkCrossOrigin(exampleOrg_app, exampleOrg); checkCrossOrigin(exampleOrg_app, exampleOrg);
@ -177,15 +177,15 @@ function run_test() {
// Check Principal kinds. // Check Principal kinds.
function checkKind(prin, kind) { function checkKind(prin, kind) {
do_check_eq(prin.isNullPrincipal, kind == 'nullPrincipal'); do_check_eq(prin.isNullPrincipal, kind == "nullPrincipal");
do_check_eq(prin.isCodebasePrincipal, kind == 'codebasePrincipal'); do_check_eq(prin.isCodebasePrincipal, kind == "codebasePrincipal");
do_check_eq(prin.isExpandedPrincipal, kind == 'expandedPrincipal'); do_check_eq(prin.isExpandedPrincipal, kind == "expandedPrincipal");
do_check_eq(prin.isSystemPrincipal, kind == 'systemPrincipal'); do_check_eq(prin.isSystemPrincipal, kind == "systemPrincipal");
} }
checkKind(ssm.createNullPrincipal({}), 'nullPrincipal'); checkKind(ssm.createNullPrincipal({}), "nullPrincipal");
checkKind(ssm.createCodebasePrincipal(makeURI('http://www.example.com'), {}), 'codebasePrincipal'); checkKind(ssm.createCodebasePrincipal(makeURI("http://www.example.com"), {}), "codebasePrincipal");
checkKind(Cu.getObjectPrincipal(Cu.Sandbox([ssm.createCodebasePrincipal(makeURI('http://www.example.com'), {})])), 'expandedPrincipal'); checkKind(Cu.getObjectPrincipal(Cu.Sandbox([ssm.createCodebasePrincipal(makeURI("http://www.example.com"), {})])), "expandedPrincipal");
checkKind(ssm.getSystemPrincipal(), 'systemPrincipal'); checkKind(ssm.getSystemPrincipal(), "systemPrincipal");
// //
// Test Origin Attribute Manipulation // Test Origin Attribute Manipulation
@ -260,7 +260,7 @@ function run_test() {
let orig = ChromeUtils.createOriginAttributesFromOrigin(uri + t[0]); let orig = ChromeUtils.createOriginAttributesFromOrigin(uri + t[0]);
checkValues(orig, t[1]); checkValues(orig, t[1]);
let mod = orig; let mod = orig;
mod['userContextId'] = 0; mod["userContextId"] = 0;
checkValues(mod, t[2]); checkValues(mod, t[2]);
do_check_eq(ChromeUtils.originAttributesToSuffix(mod), t[3]); do_check_eq(ChromeUtils.originAttributesToSuffix(mod), t[3]);
}); });
@ -281,12 +281,12 @@ function run_test() {
let orig = ChromeUtils.createOriginAttributesFromOrigin(uri + t[0]); let orig = ChromeUtils.createOriginAttributesFromOrigin(uri + t[0]);
checkValues(orig, t[1]); checkValues(orig, t[1]);
let mod = orig; let mod = orig;
mod['firstPartyDomain'] = ""; mod["firstPartyDomain"] = "";
checkValues(mod, t[2]); checkValues(mod, t[2]);
do_check_eq(ChromeUtils.originAttributesToSuffix(mod), t[3]); do_check_eq(ChromeUtils.originAttributesToSuffix(mod), t[3]);
}); });
var fileURI = makeURI('file:///foo/bar').QueryInterface(Ci.nsIFileURL); var fileURI = makeURI("file:///foo/bar").QueryInterface(Ci.nsIFileURL);
var fileTests = [ var fileTests = [
[true, fileURI.spec], [true, fileURI.spec],
[false, "file://UNIVERSAL_FILE_URI_ORIGIN"], [false, "file://UNIVERSAL_FILE_URI_ORIGIN"],
@ -298,7 +298,7 @@ function run_test() {
}); });
Services.prefs.clearUserPref("security.fileuri.strict_origin_policy"); Services.prefs.clearUserPref("security.fileuri.strict_origin_policy");
var aboutBlankURI = makeURI('about:blank'); var aboutBlankURI = makeURI("about:blank");
var aboutBlankPrin = ssm.createCodebasePrincipal(aboutBlankURI, {}); var aboutBlankPrin = ssm.createCodebasePrincipal(aboutBlankURI, {});
do_check_true(/^moz-nullprincipal:\{([0-9]|[a-z]|\-){36}\}$/.test(aboutBlankPrin.origin)); do_check_true(/^moz-nullprincipal:\{([0-9]|[a-z]|\-){36}\}$/.test(aboutBlankPrin.origin));
} }