author | Geoff Brown <gbrown@mozilla.com> |
Mon, 08 May 2017 07:49:06 -0600 | |
changeset 357095 | b99cdf171a9b0f01b3018266d656af50d5273d2d |
parent 357094 | 66c34adec7e9651e1e49202352b84fd85797bfd7 |
child 357096 | 79890abc6ff5b948d3508739a13d2064952fa40d |
push id | 31782 |
push user | kwierso@gmail.com |
push date | Mon, 08 May 2017 23:07:35 +0000 |
treeherder | mozilla-central@b21b974d60d3 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | standard8 |
bugs | 1361859 |
milestone | 55.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/.eslintignore +++ b/.eslintignore @@ -4,17 +4,16 @@ # Exclude expected objdirs. obj*/** # We ignore all these directories by default, until we get them enabled. # If you are enabling a directory, please add directory specific exclusions # below. addon-sdk/** build/** -caps/** chrome/** config/** db/** docshell/** editor/** embedding/** extensions/** gfx/** @@ -73,16 +72,19 @@ browser/extensions/pocket/content/panels browser/extensions/pocket/content/panels/js/vendor/** browser/locales/** # generated or library files in activity-stream browser/extensions/activity-stream/data/content/activity-stream.bundle.js browser/extensions/activity-stream/vendor/** # imported from chromium browser/extensions/mortar/** +# caps/ exclusions +caps/tests/mochitest/browser_checkloaduri.js + # devtools/ exclusions devtools/client/canvasdebugger/** devtools/client/commandline/** devtools/client/debugger/** devtools/client/framework/** !devtools/client/framework/devtools.js !devtools/client/framework/devtools-browser.js !devtools/client/framework/selection.js
new file mode 100644 --- /dev/null +++ b/caps/.eslintrc.js @@ -0,0 +1,7 @@ +"use strict"; + +module.exports = { + "extends": [ + "plugin:mozilla/recommended" + ] +};
new file mode 100644 --- /dev/null +++ b/caps/tests/mochitest/.eslintrc.js @@ -0,0 +1,8 @@ +"use strict"; + +module.exports = { + "extends": [ + "plugin:mozilla/mochitest-test", + "plugin:mozilla/browser-test" + ] +};
--- a/caps/tests/mochitest/test_addonMayLoad.html +++ b/caps/tests/mochitest/test_addonMayLoad.html @@ -17,18 +17,18 @@ https://bugzilla.mozilla.org/show_bug.cg const Cu = Components.utils; Cu.import("resource://gre/modules/Services.jsm"); let ssm = Services.scriptSecurityManager; let aps = Cc["@mozilla.org/addons/policy-service;1"].getService(Ci.nsIAddonPolicyService).wrappedJSObject; SimpleTest.waitForExplicitFinish(); let oldAddonIdCallback = aps.setExtensionURIToAddonIdCallback(uri => uri.host); SimpleTest.registerCleanupFunction(function() { - aps.setAddonLoadURICallback('addona', null); - aps.setAddonLoadURICallback('addonb', null); + aps.setAddonLoadURICallback("addona", null); + aps.setAddonLoadURICallback("addonb", null); aps.setExtensionURIToAddonIdCallback(oldAddonIdCallback); }); function tryLoad(sb, uri) { let p = new Promise(function(resolve, reject) { Cu.exportFunction(resolve, sb, { defineAs: "finish" }); Cu.exportFunction(reject, sb, { defineAs: "error" }); sb.eval("try { (function () { " + @@ -36,38 +36,38 @@ https://bugzilla.mozilla.org/show_bug.cg " xhr.onreadystatechange = function() { if (xhr.readyState == XMLHttpRequest.DONE) { finish(xhr.status == 200); } };" + " xhr.open('GET', '" + uri + "', true);" + " xhr.send();" + "})() } catch (e) { error(e); }"); }); return p; } - let addonA = new Cu.Sandbox(ssm.createCodebasePrincipal(Services.io.newURI('moz-extension://addonA/'), {}), - {wantGlobalProperties: ['XMLHttpRequest']}); - let addonB = new Cu.Sandbox(ssm.createCodebasePrincipal(Services.io.newURI('moz-extension://addonB/'), {}), - {wantGlobalProperties: ['XMLHttpRequest']}); + let addonA = new Cu.Sandbox(ssm.createCodebasePrincipal(Services.io.newURI("moz-extension://addonA/"), {}), + {wantGlobalProperties: ["XMLHttpRequest"]}); + let addonB = new Cu.Sandbox(ssm.createCodebasePrincipal(Services.io.newURI("moz-extension://addonB/"), {}), + {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) { ok(!success, "cross-origin load should fail for addon A"); - aps.setAddonLoadURICallback('addona', function(uri) { return /test1/.test(uri.host); }); - aps.setAddonLoadURICallback('addonb', function(uri) { return /test2/.test(uri.host); }); - return tryLoad(addonA, uriForDomain('http://test1.example.org')); + aps.setAddonLoadURICallback("addona", function(uri) { return /test1/.test(uri.host); }); + aps.setAddonLoadURICallback("addonb", function(uri) { return /test2/.test(uri.host); }); + return tryLoad(addonA, uriForDomain("http://test1.example.org")); }).then(function(success) { 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) { 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) { 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) { ok(!success, "non-whitelisted cross-origin load of test2 should fail for addon A"); SimpleTest.finish(); }, function(e) { ok(false, "Rejected promise chain: " + e); SimpleTest.finish(); });
--- a/caps/tests/mochitest/test_bug246699.html +++ b/caps/tests/mochitest/test_bug246699.html @@ -16,45 +16,41 @@ https://bugzilla.mozilla.org/show_bug.cg </div> <pre id="test"> <script class="testbody" type="text/javascript"> /** ** Test for Bug 246699 ** (should produce stack information for caps errors) **/ -function isError(e) -{ +function isError(e) { return e.constructor.name === "Error" || e.constructor.name === "TypeError"; } -function hasStack(e) -{ +function hasStack(e) { return isError(e) && /inciteCaps/.test(e.stack); } -function inciteCaps(f) -{ +function inciteCaps(f) { try { f(); return "operation succeeded"; - } catch (e if hasStack(e)) { - return "denied-stack"; } catch (e) { + if (hasStack(e)) { + return "denied-stack"; + } return "unexpected: " + e; } } -function tryChromeLoad() -{ +function tryChromeLoad() { window.frames[0].location = "chrome://global/content/mozilla.xhtml"; } -function tryComponentsClasses() -{ +function tryComponentsClasses() { return SpecialPowers.Components.classes["@mozilla.org/dummy;1"]; } is(inciteCaps(tryChromeLoad), "denied-stack", "should get stack for content-loading-chrome rejection"); is(inciteCaps(tryComponentsClasses), "denied-stack", "should get stack for SpecialPowers.Components.classes rejection");
--- a/caps/tests/mochitest/test_bug292789.html +++ b/caps/tests/mochitest/test_bug292789.html @@ -20,16 +20,18 @@ https://bugzilla.mozilla.org/show_bug.cg <script class="testbody" type="text/javascript"> /** Test for Bug 292789 ** ** Selectively allow access to whitelisted chrome packages ** even for ALLOW_CHROME mechanisms (<script>, <img> etc) **/ +/* import-globals-from ../../../toolkit/content/treeUtils.js */ + SimpleTest.waitForExplicitFinish(); /** <script src=""> test **/ function testScriptSrc(aCallback) { is(typeof gTreeUtils.sort, "function", "content can still load <script> from chrome://global"); is(typeof XPInstallConfirm, "undefined", "content should not be able to load <script> from chrome://mozapps"); @@ -70,36 +72,36 @@ function runImgTest() { } function finishTest() { SimpleTest.finish(); } function fail(event) { 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) event.target.callback(); } function success(event) { 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) event.target.callback(); } function loadImage(uri, expect, callback) { var img = document.createElement("img"); img.onerror = fail; img.onload = success; img.expected = expect; img.callback = callback; 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. testScriptSrc(runImgTest); </script> </pre> </body> </html>
--- a/caps/tests/mochitest/test_bug423375.html +++ b/caps/tests/mochitest/test_bug423375.html @@ -16,24 +16,24 @@ https://bugzilla.mozilla.org/show_bug.cg </div> <pre id="test"> <script class="testbody" type="text/javascript"> /** ** Test for Bug 423375 ** (content shouldn't be able to load chrome: or resource:) **/ -function tryLoad(url) -{ +function tryLoad(url) { try { window.frames[0].location = url; return "loaded"; - } catch (e if /Access.*denied/.test(String(e))) { - return "denied"; } catch (e) { + if (/Access.*denied/.test(String(e))) { + return "denied"; + } return "unexpected: " + e; } } is(tryLoad("chrome://global/content/mozilla.xhtml"), "denied", "content should have been prevented from loading chrome: URL"); is(tryLoad("resource://gre-resources/html.css"), "denied", "content should have been prevented from loading resource: URL");
--- a/caps/tests/mochitest/test_extensionURL.html +++ b/caps/tests/mochitest/test_extensionURL.html @@ -18,93 +18,93 @@ https://bugzilla.mozilla.org/show_bug.cg var oldLoadCallback = aps.setExtensionURILoadCallback(null); var oldMapCallback = aps.setExtensionURIToAddonIdCallback(null); var resourceHandler = SpecialPowers.Services.io.getProtocolHandler("resource") .QueryInterface(SpecialPowers.Ci.nsISubstitutingProtocolHandler); var extensionHandler = SpecialPowers.Services.io.getProtocolHandler("moz-extension") .QueryInterface(SpecialPowers.Ci.nsISubstitutingProtocolHandler); SimpleTest.registerCleanupFunction(function() { - extensionHandler.setSubstitution('cherise', null); - extensionHandler.setSubstitution('liebchen', null); + extensionHandler.setSubstitution("cherise", null); + extensionHandler.setSubstitution("liebchen", null); aps.setExtensionURILoadCallback(oldLoadCallback); aps.setExtensionURIToAddonIdCallback(oldMapCallback); }); addLoadEvent(function() { // First, get a file:// URI to something - open to suggestions on how to do // 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); - 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); // Register a moz-extension:// URI. - extensionHandler.setSubstitution('cherise', fileURI); + extensionHandler.setSubstitution("cherise", fileURI); // 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. // // resource:// try { - extensionHandler.setSubstitution('interdit', resURI); + extensionHandler.setSubstitution("interdit", resURI); ok(false, "Should have thrown for mapping moz-extension to resource"); } catch (e) { ok(true, "Threw correctly: " + e); } // chrome:// try { - var chromeURI = SpecialPowers.Services.io.newURI('chrome://global/content/mozilla.xhtml'); - extensionHandler.setSubstitution('verboten', chromeURI); + var chromeURI = SpecialPowers.Services.io.newURI("chrome://global/content/mozilla.xhtml"); + extensionHandler.setSubstitution("verboten", chromeURI); ok(false, "Should have thrown for mapping moz-extension to chrome"); } catch (e) { ok(true, "Threw correctly: " + e); } 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 navigateFromChromeWithWebNav(ifr, url) { SpecialPowers.wrap(ifr).contentWindow .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor) .getInterface(SpecialPowers.Ci.nsIWebNavigation) .loadURI(url, 0, null, null, null); } function setWhitelistCallback(rgxp) { var cb = SpecialPowers.wrapCallback(function(uri) { return rgxp.test(uri.spec); }); 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) { - var ifr = document.createElement('iframe'); + var ifr = document.createElement("iframe"); var p = new Promise(function(resolve, reject) { ifr.onload = function() { - ok(true, 'Loaded ' + url); + ok(true, "Loaded " + url); var prin = SpecialPowers.wrap(ifr.contentWindow).document.nodePrincipal; - function stripTrailingSlash(s) { return s.replace(/\/$/, ''); }; - is(stripTrailingSlash(prin.URI.spec), url, 'Principal uri is correct: ' + url); - function stripPath(s) { return s.replace(/(.*\/\/.+)\/.*/, '$1'); }; - is(prin.originNoSuffix, stripPath(url), 'Principal origin is correct: ' + prin.originNoSuffix); - is(prin.addonId, 'imaginaryaddon-' + url[url.indexOf('/') + 2], 'addonId is correct'); + function stripTrailingSlash(s) { return s.replace(/\/$/, ""); } + is(stripTrailingSlash(prin.URI.spec), url, "Principal uri is correct: " + url); + function stripPath(s) { return s.replace(/(.*\/\/.+)\/.*/, "$1"); } + is(prin.originNoSuffix, stripPath(url), "Principal origin is correct: " + prin.originNoSuffix); + is(prin.addonId, "imaginaryaddon-" + url[url.indexOf("/") + 2], "addonId is correct"); if (/_blank/.test(url)) { 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 { - is(SpecialPowers.wrap(ifr.contentWindow).document.title, 'resource test file', - 'document looks right'); + is(SpecialPowers.wrap(ifr.contentWindow).document.title, "resource test file", + "document looks right"); } ifr.remove(); resolve(); }; document.body.appendChild(ifr); var threw = false; try { @@ -129,30 +129,30 @@ https://bugzilla.mozilla.org/show_bug.cg xhr.open("GET", url, true); xhr.send(); }); } // // Perform some loads and make sure they work correctly. // - testLoad.bind(null, 'moz-extension://cherise', navigateFromChromeWithLocation)() - .then(testLoad.bind(null, 'moz-extension://cherise', navigateFromChromeWithWebNav)) - .then(testLoad.bind(null, 'moz-extension://cherise', navigateWithLocation, /* shouldThrow = */ true)) - .then(testXHR.bind(null, 'moz-extension://cherise', /* shouldError = */ true)) + testLoad.bind(null, "moz-extension://cherise", navigateFromChromeWithLocation)() + .then(testLoad.bind(null, "moz-extension://cherise", navigateFromChromeWithWebNav)) + .then(testLoad.bind(null, "moz-extension://cherise", navigateWithLocation, /* shouldThrow = */ true)) + .then(testXHR.bind(null, "moz-extension://cherise", /* shouldError = */ true)) .then(setWhitelistCallback.bind(null, /cherise/)) - .then(testLoad.bind(null, 'moz-extension://cherise', navigateWithLocation)) - .then(testXHR.bind(null, 'moz-extension://cherise')) - .then(testLoad.bind(null, 'moz-extension://liebchen', navigateWithLocation, /* shouldThrow = */ true)) - .then(testXHR.bind(null, 'moz-extension://liebchen', /* shouldError = */ true)) + .then(testLoad.bind(null, "moz-extension://cherise", navigateWithLocation)) + .then(testXHR.bind(null, "moz-extension://cherise")) + .then(testLoad.bind(null, "moz-extension://liebchen", navigateWithLocation, /* shouldThrow = */ true)) + .then(testXHR.bind(null, "moz-extension://liebchen", /* shouldError = */ true)) .then(setWhitelistCallback.bind(null, /cherise|liebchen/)) - .then(testLoad.bind(null, 'moz-extension://liebchen', navigateWithLocation)) - .then(testLoad.bind(null, 'moz-extension://liebchen', 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://liebchen", navigateWithLocation)) + .then(testLoad.bind(null, "moz-extension://liebchen", navigateWithSrc)) + .then(testLoad.bind(null, "moz-extension://cherise", navigateWithSrc)) + .then(testLoad.bind(null, "moz-extension://cherise/_blank.html", navigateWithSrc)) .then(SimpleTest.finish.bind(SimpleTest), function(e) { ok(false, "rejected promise: " + e); SimpleTest.finish() } ); }); </script> </head> <body>
new file mode 100644 --- /dev/null +++ b/caps/tests/unit/.eslintrc.js @@ -0,0 +1,7 @@ +"use strict"; + +module.exports = { + "extends": [ + "plugin:mozilla/xpcshell-test" + ] +};
--- a/caps/tests/unit/test_origin.js +++ b/caps/tests/unit/test_origin.js @@ -20,20 +20,20 @@ function checkCrossOrigin(a, b) { do_check_false(b.subsumes(a)); do_check_false(b.subsumesConsideringDomain(a)); } function checkOriginAttributes(prin, attrs, suffix) { attrs = attrs || {}; do_check_eq(prin.originAttributes.appId, attrs.appId || 0); do_check_eq(prin.originAttributes.inIsolatedMozBrowser, attrs.inIsolatedMozBrowser || false); - do_check_eq(prin.originSuffix, suffix || ''); - do_check_eq(ChromeUtils.originAttributesToSuffix(attrs), suffix || ''); + do_check_eq(prin.originSuffix, suffix || ""); + do_check_eq(ChromeUtils.originAttributesToSuffix(attrs), suffix || ""); 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)); } else { checkThrows(() => ssm.createCodebasePrincipalFromOrigin(prin.origin)); } } function checkSandboxOriginAttributes(arr, attrs, options) { options = options || {}; @@ -50,147 +50,147 @@ function printAttrs(name, attrs) { "\tinIsolatedMozBrowser: " + attrs.inIsolatedMozBrowser + ",\n" + "\tprivateBrowsingId: '" + attrs.privateBrowsingId + "',\n" + "\tfirstPartyDomain: '" + attrs.firstPartyDomain + "'\n}"); } function checkValues(attrs, values) { values = values || {}; - //printAttrs("attrs", attrs); - //printAttrs("values", values); + // printAttrs("attrs", attrs); + // printAttrs("values", values); do_check_eq(attrs.appId, values.appId || 0); do_check_eq(attrs.userContextId, values.userContextId || 0); do_check_eq(attrs.inIsolatedMozBrowser, values.inIsolatedMozBrowser || false); - do_check_eq(attrs.privateBrowsingId, values.privateBrowsingId || ''); - do_check_eq(attrs.firstPartyDomain, values.firstPartyDomain || ''); + do_check_eq(attrs.privateBrowsingId, values.privateBrowsingId || ""); + do_check_eq(attrs.firstPartyDomain, values.firstPartyDomain || ""); } function run_test() { // Attributeless origins. - do_check_eq(ssm.getSystemPrincipal().origin, '[System Principal]'); + do_check_eq(ssm.getSystemPrincipal().origin, "[System Principal]"); checkOriginAttributes(ssm.getSystemPrincipal()); - var exampleOrg = ssm.createCodebasePrincipal(makeURI('http://example.org'), {}); - do_check_eq(exampleOrg.origin, 'http://example.org'); + var exampleOrg = ssm.createCodebasePrincipal(makeURI("http://example.org"), {}); + do_check_eq(exampleOrg.origin, "http://example.org"); checkOriginAttributes(exampleOrg); - var exampleCom = ssm.createCodebasePrincipal(makeURI('https://www.example.com:123'), {}); - do_check_eq(exampleCom.origin, '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"); checkOriginAttributes(exampleCom); var nullPrin = Cu.getObjectPrincipal(new Cu.Sandbox(null)); do_check_true(/^moz-nullprincipal:\{([0-9]|[a-z]|\-){36}\}$/.test(nullPrin.origin)); checkOriginAttributes(nullPrin); - var ipv6Prin = ssm.createCodebasePrincipal(makeURI('https://[2001:db8::ff00:42:8329]:123'), {}); - do_check_eq(ipv6Prin.origin, '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"); checkOriginAttributes(ipv6Prin); - var ipv6NPPrin = ssm.createCodebasePrincipal(makeURI('https://[2001:db8::ff00:42:8329]'), {}); - do_check_eq(ipv6NPPrin.origin, '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]"); checkOriginAttributes(ipv6NPPrin); var ep = Cu.getObjectPrincipal(Cu.Sandbox([exampleCom, nullPrin, exampleOrg])); checkOriginAttributes(ep); checkCrossOrigin(exampleCom, exampleOrg); checkCrossOrigin(exampleOrg, nullPrin); // nsEP origins should be in lexical order. do_check_eq(ep.origin, `[Expanded Principal [${exampleOrg.origin}, ${exampleCom.origin}, ${nullPrin.origin}]]`); // 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. // // 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}); - checkOriginAttributes(exampleOrg_app, {appId: 42}, '^appId=42'); - checkOriginAttributes(nullPrin_app, {appId: 42}, '^appId=42'); - do_check_eq(exampleOrg_app.origin, 'http://example.org^appId=42'); + checkOriginAttributes(exampleOrg_app, {appId: 42}, "^appId=42"); + checkOriginAttributes(nullPrin_app, {appId: 42}, "^appId=42"); + do_check_eq(exampleOrg_app.origin, "http://example.org^appId=42"); // 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}); - checkOriginAttributes(exampleOrg_browser, {inIsolatedMozBrowser: true}, '^inBrowser=1'); - checkOriginAttributes(nullPrin_browser, {inIsolatedMozBrowser: true}, '^inBrowser=1'); - do_check_eq(exampleOrg_browser.origin, 'http://example.org^inBrowser=1'); + checkOriginAttributes(exampleOrg_browser, {inIsolatedMozBrowser: true}, "^inBrowser=1"); + checkOriginAttributes(nullPrin_browser, {inIsolatedMozBrowser: true}, "^inBrowser=1"); + do_check_eq(exampleOrg_browser.origin, "http://example.org^inBrowser=1"); // 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}); - checkOriginAttributes(exampleOrg_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'); + checkOriginAttributes(exampleOrg_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"); // App and browser, different domain. - 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'); - do_check_eq(exampleCom_appBrowser.origin, 'https://www.example.com:123^appId=42&inBrowser=1'); + 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"); + do_check_eq(exampleCom_appBrowser.origin, "https://www.example.com:123^appId=42&inBrowser=1"); // First party Uri - var exampleOrg_firstPartyDomain = ssm.createCodebasePrincipal(makeURI('http://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'); + var exampleOrg_firstPartyDomain = ssm.createCodebasePrincipal(makeURI("http://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"); // Make sure we don't crash when serializing principals with UNKNOWN_APP_ID. try { let binaryStream = Cc["@mozilla.org/binaryoutputstream;1"]. createInstance(Ci.nsIObjectOutputStream); let pipe = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe); pipe.init(false, false, 0, 0xffffffff, null); binaryStream.setOutputStream(pipe.outputStream); - binaryStream.writeCompoundObject(simplePrin, Ci.nsISupports, true); + binaryStream.writeCompoundObject(simplePrin, Ci.nsISupports, true); // eslint-disable-line no-undef binaryStream.close(); } catch (e) { do_check_true(true); } // Just userContext. - var exampleOrg_userContext = ssm.createCodebasePrincipal(makeURI('http://example.org'), {userContextId: 42}); - checkOriginAttributes(exampleOrg_userContext, { userContextId: 42 }, '^userContextId=42'); - do_check_eq(exampleOrg_userContext.origin, 'http://example.org^userContextId=42'); + var exampleOrg_userContext = ssm.createCodebasePrincipal(makeURI("http://example.org"), {userContextId: 42}); + checkOriginAttributes(exampleOrg_userContext, { userContextId: 42 }, "^userContextId=42"); + do_check_eq(exampleOrg_userContext.origin, "http://example.org^userContextId=42"); // 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}); - checkOriginAttributes(exampleOrg_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'); + checkOriginAttributes(exampleOrg_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"); checkSandboxOriginAttributes(null, {}); - checkSandboxOriginAttributes('http://example.org', {}); - checkSandboxOriginAttributes('http://example.org', {}, {originAttributes: {}}); - checkSandboxOriginAttributes('http://example.org', {appId: 42}, {originAttributes: {appId: 42}}); - checkSandboxOriginAttributes(['http://example.org'], {}); - checkSandboxOriginAttributes(['http://example.org'], {}, {originAttributes: {}}); - checkSandboxOriginAttributes(['http://example.org'], {appId: 42}, {originAttributes: {appId: 42}}); + checkSandboxOriginAttributes("http://example.org", {}); + checkSandboxOriginAttributes("http://example.org", {}, {originAttributes: {}}); + checkSandboxOriginAttributes("http://example.org", {appId: 42}, {originAttributes: {appId: 42}}); + checkSandboxOriginAttributes(["http://example.org"], {}); + checkSandboxOriginAttributes(["http://example.org"], {}, {originAttributes: {}}); + checkSandboxOriginAttributes(["http://example.org"], {appId: 42}, {originAttributes: {appId: 42}}); // Check that all of the above are cross-origin. checkCrossOrigin(exampleOrg_app, exampleOrg); checkCrossOrigin(exampleOrg_app, nullPrin_app); checkCrossOrigin(exampleOrg_browser, exampleOrg_app); checkCrossOrigin(exampleOrg_browser, nullPrin_browser); checkCrossOrigin(exampleOrg_appBrowser, exampleOrg_app); checkCrossOrigin(exampleOrg_appBrowser, nullPrin_appBrowser); checkCrossOrigin(exampleOrg_appBrowser, exampleCom_appBrowser); checkCrossOrigin(exampleOrg_firstPartyDomain, exampleOrg); checkCrossOrigin(exampleOrg_userContext, exampleOrg); checkCrossOrigin(exampleOrg_userContext, exampleOrg_userContextApp); // Check Principal kinds. function checkKind(prin, kind) { - do_check_eq(prin.isNullPrincipal, kind == 'nullPrincipal'); - do_check_eq(prin.isCodebasePrincipal, kind == 'codebasePrincipal'); - do_check_eq(prin.isExpandedPrincipal, kind == 'expandedPrincipal'); - do_check_eq(prin.isSystemPrincipal, kind == 'systemPrincipal'); + do_check_eq(prin.isNullPrincipal, kind == "nullPrincipal"); + do_check_eq(prin.isCodebasePrincipal, kind == "codebasePrincipal"); + do_check_eq(prin.isExpandedPrincipal, kind == "expandedPrincipal"); + do_check_eq(prin.isSystemPrincipal, kind == "systemPrincipal"); } - checkKind(ssm.createNullPrincipal({}), 'nullPrincipal'); - checkKind(ssm.createCodebasePrincipal(makeURI('http://www.example.com'), {}), 'codebasePrincipal'); - checkKind(Cu.getObjectPrincipal(Cu.Sandbox([ssm.createCodebasePrincipal(makeURI('http://www.example.com'), {})])), 'expandedPrincipal'); - checkKind(ssm.getSystemPrincipal(), 'systemPrincipal'); + checkKind(ssm.createNullPrincipal({}), "nullPrincipal"); + checkKind(ssm.createCodebasePrincipal(makeURI("http://www.example.com"), {}), "codebasePrincipal"); + checkKind(Cu.getObjectPrincipal(Cu.Sandbox([ssm.createCodebasePrincipal(makeURI("http://www.example.com"), {})])), "expandedPrincipal"); + checkKind(ssm.getSystemPrincipal(), "systemPrincipal"); // // Test Origin Attribute Manipulation // // check that we can create an empty origin attributes dict with default // members and values. var emptyAttrs = ChromeUtils.fillNonDefaultOriginAttributes({}); @@ -255,17 +255,17 @@ function run_test() { [ "^appId=5", {appId: 5}, {appId: 5}, "^appId=5" ], [ "^appId=5&userContextId=3", {appId: 5, userContextId: 3}, {appId: 5}, "^appId=5" ] ]; // check that we can set the userContextId to default properly dflt_tests.forEach(t => { let orig = ChromeUtils.createOriginAttributesFromOrigin(uri + t[0]); checkValues(orig, t[1]); let mod = orig; - mod['userContextId'] = 0; + mod["userContextId"] = 0; checkValues(mod, t[2]); do_check_eq(ChromeUtils.originAttributesToSuffix(mod), t[3]); }); // each row in the dflt2_tests array has these values: // [0] - the suffix used to create an origin attribute from // [1] - the expected result of creating an origin attributes from [0] // [2] - the expected result after setting firstPartyUri to the default @@ -276,29 +276,29 @@ function run_test() { [ "^appId=5", {appId: 5}, {appId: 5}, "^appId=5" ], [ "^appId=5&firstPartyDomain=foo.com", {appId: 5, firstPartyDomain: "foo.com"}, {appId: 5}, "^appId=5" ] ]; // check that we can set the userContextId to default properly dflt2_tests.forEach(t => { let orig = ChromeUtils.createOriginAttributesFromOrigin(uri + t[0]); checkValues(orig, t[1]); let mod = orig; - mod['firstPartyDomain'] = ""; + mod["firstPartyDomain"] = ""; checkValues(mod, t[2]); 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 = [ [true, fileURI.spec], [false, "file://UNIVERSAL_FILE_URI_ORIGIN"], ]; fileTests.forEach(t => { Services.prefs.setBoolPref("security.fileuri.strict_origin_policy", t[0]); var filePrin = ssm.createCodebasePrincipal(fileURI, {}); do_check_eq(filePrin.origin, t[1]); }); Services.prefs.clearUserPref("security.fileuri.strict_origin_policy"); - var aboutBlankURI = makeURI('about:blank'); + var aboutBlankURI = makeURI("about:blank"); var aboutBlankPrin = ssm.createCodebasePrincipal(aboutBlankURI, {}); do_check_true(/^moz-nullprincipal:\{([0-9]|[a-z]|\-){36}\}$/.test(aboutBlankPrin.origin)); }