bug 766382 - make mozApps mochitests stop modifying API call results; r=felipe

This commit is contained in:
Myk Melez 2012-06-20 09:53:30 -07:00
parent 49ad7f29d6
commit bf7a5fe54b
6 changed files with 35 additions and 39 deletions

View File

@ -17,11 +17,10 @@
if(event.data == "getSelf") {
var origin = getOrigin(appURL);
mozAppscb(navigator.mozApps.getSelf(),
[{ status: '== "success"',
installOrigin: '== "chrome://mochitests"',
[{ installOrigin: '== "chrome://mochitests"',
origin: "== " + origin.quote(),
manifestURL: "== " + appURL.quote()
}], check, next);
}], "success", check, next);
}
else if(event.data == "uninstall") {
var pending = navigator.mozApps.getSelf();
@ -51,21 +50,17 @@
getInstalled([appURL], check, next);
}
mozAppscb(navigator.mozApps.getInstalled(),
[{ status: '== "success"'}],
check, next);
[{}], "success", check, next);
}
else if(event.data == "mgmt.getAll") {
var hostname = window.location.hostname;
debug(hostname);
if (hostname != "http://example.com") {
mozAppscb(navigator.mozApps.mgmt.getAll(),
[{ status: '== "error"',
name: '== "DENIED"'
}], check, next);
[{ name: '== "DENIED"' }], "error", check, next);
} else {
mozAppscb(navigator.mozApps.mgmt.getAll(),
[{ status: '== "success"'}],
check, next);
[{}], "success", check, next);
}
}
else if(event.data == "mgmt.event_error") {
@ -89,8 +84,7 @@
} else {
mozAppscb(navigator.mozApps.mgmt.getAll(),
[{ status: '== "success"'}],
check, next);
[{}], "success", check, next);
}
}
}

View File

@ -150,7 +150,7 @@ function js_traverse(template, check, object) {
object = SpecialPowers.wrap(object);
if (type == "object") {
if (Object.keys(template).length == 1 && template["status"]) {
if (Object.keys(template).length == 0) {
check(!object || object.length == 0,"The return object from mozApps api was null as expected");
return;
}
@ -195,19 +195,18 @@ function js_traverse(template, check, object) {
* @check An abstraction over ok / todo to allow for that determination to be made by the invoking code
* @next The next operation to jump to
*/
function mozAppscb(pending, comparatorObj, check, next) {
function mozAppscb(pending, comparatorObj, expectedStatus, check, next) {
debug("inside mozAppscb");
pending.onsuccess = function () {
debug("success cb, called");
check(expectedStatus == "success", "the success callback was called");
if(pending.result) {
if(typeof pending.result.length !== 'undefined') {
for(i=0;i < pending.result.length;i++) {
SpecialPowers.wrap(pending).result[i].status= 'success';
js_traverse(comparatorObj[i], check, pending.result[i]);
}
} else {
debug("comparatorOBj in else");
SpecialPowers.wrap(pending).result.status = 'success';
js_traverse(comparatorObj[0], check, pending.result);
}
} else {
@ -220,8 +219,8 @@ function mozAppscb(pending, comparatorObj, check, next) {
};
pending.onerror = function () {
SpecialPowers.wrap(pending).error.status = 'error';
check(true, "failure cb called");
debug("failure cb called");
check(expectedStatus == "error", "the error callback was called");
js_traverse(comparatorObj[0], check, pending.error);
if(typeof next == 'function') {
debug("calling next");
@ -275,7 +274,6 @@ function install(appURL, check, next) {
mozAppscb(navigator.mozApps.install(
appURL, null),
[{
status: "== \"success\"",
installOrigin: "== " + installOrigin.quote(),
installTime: "!== undefined",
origin: "== " + origin.quote(),
@ -286,7 +284,7 @@ function install(appURL, check, next) {
name: "== " + unescape(manifest.name).quote(),
installs_allowed_from: manifest.installs_allowed_from
})
}], check,
}], "success", check,
next);
}
@ -311,7 +309,6 @@ function getInstalled(appURLs, check, next) {
}
checkInstalled[i] = {
status: "== " + "success".quote(),
installOrigin: "== " + "chrome://mochitests".quote(),
origin: "== " + origin.quote(),
manifestURL: "== " + appURL.quote(),
@ -325,7 +322,7 @@ function getInstalled(appURLs, check, next) {
};
}
debug(JSON.stringify(checkInstalled));
mozAppscb(navigator.mozApps.getInstalled(), checkInstalled, check, next);
mozAppscb(navigator.mozApps.getInstalled(), checkInstalled, "success", check, next);
}
/**

View File

@ -48,7 +48,8 @@ function setUp(next) {
function verify_no_apps(next) {
debug("in " + arguments.callee.name);
mozAppscb(navigator.mozApps.mgmt.getAll(),
[{ status: "== \"success\""}],
[{}],
"success",
ok,
next);
}
@ -56,7 +57,8 @@ function verify_no_apps(next) {
function get_installed_returns_nothing(next) {
debug("in " + arguments.callee.name);
mozAppscb(navigator.mozApps.getInstalled(),
[{ status: "== \"success\""}],
[{}],
"success",
ok,
next);
}
@ -73,7 +75,8 @@ function install_super_crazy(next) {
function get_self_returns_nothing(next) {
debug("in " + arguments.callee.name);
mozAppscb(navigator.mozApps.getSelf(),
[{ status: "== \"success\""}],
[{}],
"success",
ok,
next);
}

View File

@ -37,7 +37,8 @@ function setUp(next) {
function verify_no_apps(next) {
debug("in " + arguments.callee.name);
mozAppscb(navigator.mozApps.mgmt.getAll(),
[{ status: "== \"success\""}],
[{}],
"success",
ok,
next);
}
@ -45,7 +46,8 @@ function verify_no_apps(next) {
function get_installed_returns_nothing(next) {
debug("in " + arguments.callee.name);
mozAppscb(navigator.mozApps.getInstalled(),
[{ status: "== \"success\""}],
[{}],
"success",
ok,
next);
}
@ -61,7 +63,8 @@ function install_super_crazy(next) {
function get_self_returns_nothing(next) {
debug("in " + arguments.callee.name);
mozAppscb(navigator.mozApps.getSelf(),
[{ status: "== \"success\""}],
[{}],
"success",
ok,
next);
}
@ -80,7 +83,8 @@ function uninstall_wild_crazy(next) {
var appURL = SERVERS['wild_crazy'];
uninstall(appURL, ok, function() {
mozAppscb(navigator.mozApps.getInstalled(),
[{ status: "== \"success\""}],
[{}],
"success",
ok,
next);
});

View File

@ -47,29 +47,25 @@ function no_args(next) {
function parse_error(next) {
debug("in " + arguments.callee.name);
mozAppscb(navigator.mozApps.install(SERVERS['json_syntax_error'], null),
[{ status: "== \"error\"",
name: "== \"MANIFEST_PARSE_ERROR\""}], ok, next);
[{ name: "== \"MANIFEST_PARSE_ERROR\"" }], "error", ok, next);
}
function invalid_manifest(next) {
debug("in " + arguments.callee.name);
mozAppscb(navigator.mozApps.install(SERVERS['missing_required_field'], null),
[{ status: "== \"error\"",
name: "== \"INVALID_MANIFEST\""}], ok, next);
[{ name: "== \"INVALID_MANIFEST\"" }], "error", ok, next);
}
function permission_denied(next) {
debug("in " + arguments.callee.name);
mozAppscb(navigator.mozApps.install(SERVERS['no_delegated_install'], null),
[{ status: "== \"error\"",
name: "== \"DENIED\""}], todo, next);
[{ name: "== \"DENIED\"" }], "error", todo, next);
}
function invalid_content(next) {
debug("in " + arguments.callee.name);
mozAppscb(navigator.mozApps.install(SERVERS['bad_content_type'], null),
[{ status: "== \"error\"",
name: "== \"INVALID_MANIFEST\""}], todo, next);
[{ name: "== \"INVALID_MANIFEST\"" }], "error", todo, next);
}
function mgmt_api_errors(next) {

View File

@ -34,7 +34,8 @@ function setUp(next) {
function verify_no_apps(next) {
debug("in " + arguments.callee.name);
mozAppscb(navigator.mozApps.mgmt.getAll(),
[{ status: "== \"success\""}],
[{}],
"success",
ok,
next);
}
@ -42,7 +43,8 @@ function verify_no_apps(next) {
function get_installed_returns_nothing(next) {
debug("in " + arguments.callee.name);
mozAppscb(navigator.mozApps.getInstalled(),
[{ status: "== \"success\""}],
[{}],
"success",
ok,
next);
}