Bug 1055960 - Part 3: fix tests cases. r=dimi

From d6d188a78006b291f7cdd8b4a910a9b5a39b7da2 Mon Sep 17 00:00:00 2001
---
 .../tests/marionette/test_nfc_error_messages.js    | 36 +++++-----------------
 1 file changed, 8 insertions(+), 28 deletions(-)
This commit is contained in:
Yoshi Huang 2014-09-02 19:27:56 +08:00
parent 1ce606ee6f
commit 53fc19e907

View File

@ -29,7 +29,7 @@ function testNfcNotEnabledError() {
.then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0))
.then(registerAndFireOnpeerready)
.then(() => toggleNFC(false))
.then(() => sendNDEFExpectError(nfcPeers[0], 'NfcNotEnabledError'))
.then(() => sendNDEFExpectError(nfcPeers[0]))
.then(endTest)
.catch(handleRejectedPromise);
}
@ -50,7 +50,7 @@ function testNfcBadSessionIdError() {
.then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0))
.then(registerAndFireOnpeerready)
// we have 2 peers in nfcPeers array, peer0 has old/invalid session token
.then(() => sendNDEFExpectError(nfcPeers[0], 'NfcBadSessionIdError'))
.then(() => sendNDEFExpectError(nfcPeers[0]))
.then(() => toggleNFC(false))
.then(endTest)
.catch(handleRejectedPromise);
@ -96,46 +96,26 @@ function registerAndFireOnpeerready() {
let deferred = Promise.defer();
nfc.onpeerready = function(event) {
log("onpeerready called");
nfcPeers.push(event.peer);
nfc.onpeerready = null;
deferred.resolve();
};
let req = nfc.checkP2PRegistration(MANIFEST_URL);
req.onsuccess = function() {
is(req.result, true, 'P2P registration result');
if(req.result) {
nfc.notifyUserAcceptedP2P(MANIFEST_URL);
} else {
ok(false, 'this should not happen');
nfc.onpeerready = null;
deferred.reject();
}
};
req.onerror = function() {
ok(false, 'not possible');
nfc.onpeerready = null;
deferred.reject();
};
nfc.notifyUserAcceptedP2P(MANIFEST_URL);
return deferred.promise;
}
function sendNDEFExpectError(peer, errorMsg) {
function sendNDEFExpectError(peer) {
let deferred = Promise.defer();
let req = peer.sendNDEF(NDEF_MESSAGE);
req.onsuccess = function() {
ok(false, 'success on sending ndef not possible shoudl get: ' + errorMsg);
try {
peer.sendNDEF(NDEF_MESSAGE);
deferred.reject();
};
req.onerror = function() {
ok(true, 'this should happen');
is(req.error.name, errorMsg, 'Should have proper error name');
} catch (e) {
ok(true, 'this should happen ' + e);
deferred.resolve();
};
}
return deferred.promise;
}