mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1229222 - tests for bug 1229222. r=sicking
(HEAD -> oa, refs/patches/oa/Bug_1229222_Tests) Tests Bug 1229222
This commit is contained in:
parent
0621eb9f1f
commit
9161c81842
@ -35,6 +35,28 @@ function checkOriginAttributes(prin, attrs, suffix) {
|
||||
}
|
||||
}
|
||||
|
||||
// utility function useful for debugging
|
||||
function printAttrs(name, attrs) {
|
||||
do_print(name + " {\n" +
|
||||
"\tappId: " + attrs.appId + ",\n" +
|
||||
"\tuserContextId: " + attrs.userContextId + ",\n" +
|
||||
"\tinBrowser: " + attrs.inBrowser + ",\n" +
|
||||
"\taddonId: '" + attrs.addonId + "',\n" +
|
||||
"\tsignedPkg: '" + attrs.signedPkg + "'\n}");
|
||||
}
|
||||
|
||||
|
||||
function checkValues(attrs, values) {
|
||||
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.inBrowser, values.inBrowser || false);
|
||||
do_check_eq(attrs.addonId, values.addonId || '');
|
||||
do_check_eq(attrs.signedPkg, values.signedPkg || '');
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
// Attributeless origins.
|
||||
do_check_eq(ssm.getSystemPrincipal().origin, '[System Principal]');
|
||||
@ -174,4 +196,83 @@ function run_test() {
|
||||
checkKind(ssm.createCodebasePrincipal(makeURI('http://www.example.com'), {}), 'codebasePrincipal');
|
||||
checkKind(ssm.createExpandedPrincipal([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.
|
||||
emptyAttrs = ChromeUtils.createDefaultOriginAttributes();
|
||||
checkValues(emptyAttrs);
|
||||
|
||||
var uri = "http://example.org";
|
||||
var tests = [
|
||||
[ "", {} ],
|
||||
[ "^appId=5", {appId: 5} ],
|
||||
[ "^userContextId=3", {userContextId: 3} ],
|
||||
[ "^addonId=fooBar", {addonId: "fooBar"} ],
|
||||
[ "^inBrowser=1", {inBrowser: true} ],
|
||||
[ "^signedPkg=bazQux", {signedPkg: "bazQux"} ],
|
||||
[ "^appId=3&inBrowser=1&userContextId=6",
|
||||
{appId: 3, userContextId: 6, inBrowser: true} ] ];
|
||||
|
||||
// check that we can create an origin attributes from an origin properly
|
||||
tests.forEach(function(t) {
|
||||
let attrs = ChromeUtils.createOriginAttributesFromOrigin(uri + t[0]);
|
||||
checkValues(attrs, t[1]);
|
||||
do_check_eq(ChromeUtils.originAttributesToSuffix(attrs), t[0]);
|
||||
});
|
||||
|
||||
// check that we can create an origin attributes from a dict properly
|
||||
tests.forEach(function(t) {
|
||||
let attrs = ChromeUtils.createOriginAttributesFromDict(t[1]);
|
||||
checkValues(attrs, t[1]);
|
||||
do_check_eq(ChromeUtils.originAttributesToSuffix(attrs), t[0]);
|
||||
});
|
||||
|
||||
// each row in the set_tests array has these values:
|
||||
// [0] - the suffix used to create an origin attribute from
|
||||
// [1] - the expected result of creating an origin attribute from [0]
|
||||
// [2] - the pattern to set on the origin attributes
|
||||
// [3] - the expected result of setting [2] values on [1]
|
||||
// [4] - the expected result of creating a suffix from [3]
|
||||
var set_tests = [
|
||||
[ "", {}, {appId: 5}, {appId: 5}, "^appId=5" ],
|
||||
[ "^appId=5", {appId: 5}, {appId: 3}, {appId: 3}, "^appId=3" ],
|
||||
[ "^appId=5", {appId: 5}, {userContextId: 3}, {appId: 5, userContextId: 3}, "^appId=5&userContextId=3" ],
|
||||
[ "^appId=5", {appId: 5}, {appId: 3, userContextId: 7}, {appId: 3, userContextId: 7}, "^appId=3&userContextId=7" ] ];
|
||||
|
||||
// check that we can set origin attributes values properly
|
||||
set_tests.forEach(function(t) {
|
||||
let orig = ChromeUtils.createOriginAttributesFromOrigin(uri + t[0]);
|
||||
checkValues(orig, t[1]);
|
||||
let mod = orig;
|
||||
for (var key in t[2]) {
|
||||
mod[key] = t[2][key];
|
||||
}
|
||||
checkValues(mod, t[3]);
|
||||
do_check_eq(ChromeUtils.originAttributesToSuffix(mod), t[4]);
|
||||
});
|
||||
|
||||
// each row in the dflt_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 userContextId to the default
|
||||
// [3] - the expected result of creating a suffix from [2]
|
||||
var dflt_tests = [
|
||||
[ "", {}, {}, "" ],
|
||||
[ "^userContextId=3", {userContextId: 3}, {}, "" ],
|
||||
[ "^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(function(t) {
|
||||
let orig = ChromeUtils.createOriginAttributesFromOrigin(uri + t[0]);
|
||||
checkValues(orig, t[1]);
|
||||
let mod = orig;
|
||||
mod['userContextId'] = 0;
|
||||
checkValues(mod, t[2]);
|
||||
do_check_eq(ChromeUtils.originAttributesToSuffix(mod), t[3]);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user