Bug 1165340 - Part 3: Update xpcshell tests. r=allstars.chh

This commit is contained in:
Krzysztof Mioduszewski 2015-06-03 05:06:00 -04:00
parent 98d95e6d27
commit acc666b88b

View File

@ -23,6 +23,7 @@ const MANIFEST = {
"*/a0*"
]
};
const APPID = 1111;
const PAGE_URL = "app://system.gaiamobile.org/index.html";
const TYPE = "nfc-hci-event-transaction";
@ -39,15 +40,29 @@ const TEST_MESSAGES = [
];
let HCIEvtTransactionConfigurator = null;
let aceAccessAllowed = true;
function setMockAppService(manifest) {
XPCOMUtils.defineLazyServiceGetter = (obj) => {
obj.appsService = {
getManifestFor: (manifestURL) => {
equal(manifestURL, MANIFEST_URL, "should pass proper manifestUrl");
return Promise.resolve(manifest);
}
};
function setMockServices(manifest) {
XPCOMUtils.defineLazyServiceGetter = (obj, service) => {
if (service === "appsService") {
obj.appsService = {
getManifestFor: (manifestURL) => {
equal(manifestURL, MANIFEST_URL, "should pass proper manifestUrl");
return Promise.resolve(manifest);
},
getAppLocalIdByManifestURL: (manifestURL) => {
equal(manifestURL, MANIFEST_URL, "should pass proper manifestUrl");
return APPID;
},
};
}
else if (service === "aceService") {
obj.aceService = {
isAccessAllowed: () => {
return Promise.resolve(aceAccessAllowed);
}
};
}
};
}
@ -62,7 +77,7 @@ function handleRejectedPromise() {
}
function run_test() {
setMockAppService(MANIFEST);
setMockServices(MANIFEST);
HCIEvtTransactionConfigurator = getSystemMessageConfigurator();
ok(!!HCIEvtTransactionConfigurator, "Configurator should be instantiated");
@ -96,3 +111,21 @@ add_test(function test_shouldDispatch_general_rule_validation() {
.catch(handleRejectedPromise)
.then(run_next_test);
});
add_test(function test_shouldDispatch_aceIsAccessAllowed() {
var testAccessAllowed = () => {
return HCIEvtTransactionConfigurator
.shouldDispatch(MANIFEST_URL, PAGE_URL, TYPE, TEST_MESSAGES[1])
.then((result) => {
ok(result === aceAccessAllowed, "Should be equal to ACE access decision");
});
};
aceAccessAllowed = false;
testAccessAllowed().then(() => {
aceAccessAllowed = true;
return testAccessAllowed();
})
.catch(handleRejectedPromise)
.then(run_next_test);
});