зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1180921 - Generalize test_origin to make it easier to add new origin attributes. r=gabor
This commit is contained in:
Родитель
5f00046776
Коммит
01a5c316e5
|
@ -25,9 +25,10 @@ function checkCrossOrigin(a, b) {
|
|||
a.originAttributes.inBrowser == b.originAttributes.inBrowser);
|
||||
}
|
||||
|
||||
function checkOriginAttributes(prin, appId, inBrowser, suffix) {
|
||||
do_check_eq(prin.originAttributes.appId, appId || 0);
|
||||
do_check_eq(prin.originAttributes.inBrowser, inBrowser || false);
|
||||
function checkOriginAttributes(prin, attrs, suffix) {
|
||||
attrs = attrs || {};
|
||||
do_check_eq(prin.originAttributes.appId, attrs.appId || 0);
|
||||
do_check_eq(prin.originAttributes.inBrowser, attrs.inBrowser || false);
|
||||
do_check_eq(prin.originSuffix, suffix || '');
|
||||
if (!prin.isNullPrincipal && !prin.origin.startsWith('[')) {
|
||||
do_check_true(BrowserUtils.principalFromOrigin(prin.origin).equals(prin));
|
||||
|
@ -67,27 +68,27 @@ function run_test() {
|
|||
// Just app.
|
||||
var exampleOrg_app = ssm.createCodebasePrincipal(makeURI('http://example.org'), {appId: 42});
|
||||
var nullPrin_app = ssm.createNullPrincipal({appId: 42});
|
||||
checkOriginAttributes(exampleOrg_app, 42, false, '!appId=42');
|
||||
checkOriginAttributes(nullPrin_app, 42, false, '!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'), {inBrowser: true});
|
||||
var nullPrin_browser = ssm.createNullPrincipal({inBrowser: true});
|
||||
checkOriginAttributes(exampleOrg_browser, 0, true, '!inBrowser=1');
|
||||
checkOriginAttributes(nullPrin_browser, 0, true, '!inBrowser=1');
|
||||
checkOriginAttributes(exampleOrg_browser, {inBrowser: true}, '!inBrowser=1');
|
||||
checkOriginAttributes(nullPrin_browser, {inBrowser: 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'), {inBrowser: true, appId: 42});
|
||||
var nullPrin_appBrowser = ssm.createNullPrincipal({inBrowser: true, appId: 42});
|
||||
checkOriginAttributes(exampleOrg_appBrowser, 42, true, '!appId=42&inBrowser=1');
|
||||
checkOriginAttributes(nullPrin_appBrowser, 42, true, '!appId=42&inBrowser=1');
|
||||
checkOriginAttributes(exampleOrg_appBrowser, {appId: 42, inBrowser: true}, '!appId=42&inBrowser=1');
|
||||
checkOriginAttributes(nullPrin_appBrowser, {appId: 42, inBrowser: 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, inBrowser: true});
|
||||
checkOriginAttributes(exampleCom_appBrowser, 42, true, '!appId=42&inBrowser=1');
|
||||
checkOriginAttributes(exampleCom_appBrowser, {appId: 42, inBrowser: true}, '!appId=42&inBrowser=1');
|
||||
do_check_eq(exampleCom_appBrowser.origin, 'https://www.example.com:123!appId=42&inBrowser=1');
|
||||
|
||||
// Check that all of the above are cross-origin.
|
||||
|
|
Загрузка…
Ссылка в новой задаче