Bug 1019668 - Part 1: Don't add errorMsg if the status property is undefined. r=allstars.chh

This commit is contained in:
Krzysztof Mioduszewski 2014-06-16 07:54:00 -04:00
parent 52939d78f9
commit 03aae793a2
2 changed files with 56 additions and 4 deletions

View File

@ -6,11 +6,11 @@
/* globals log, is, ok, runTests, toggleNFC, runNextTest,
SpecialPowers, nfc, enableRE0, MozNDEFRecord */
const MARIONETTE_TIMEOUT = 30000;
const MARIONETTE_TIMEOUT = 60000;
const MARIONETTE_HEAD_JS = 'head.js';
const MANIFEST_URL = 'app://system.gaiamobile.org/manifest.webapp';
const NDEF_MESSAGE = [new MozNDEFRecord(new Uint8Array(0x01),
const NDEF_MESSAGE = [new MozNDEFRecord(0x01,
new Uint8Array(0x84),
new Uint8Array(0),
new Uint8Array(0x20))];
@ -76,6 +76,21 @@ function testNfcConnectError() {
.catch(handleRejectedPromise);
}
/**
* Enables nfc and RE0, registers tech-discovered msg handler, once it's
* fired set tech-lost handler and disables nfc. In both handlers checks
* if error message is not present.
*/
function testNoErrorInTechMsg() {
log('testNoErrorInTechMsg');
toggleNFC(true)
.then(enableRE0)
.then(setTechDiscoveredHandler)
.then(setAndFireTechLostHandler)
.then(endTest)
.catch(handleRejectedPromise);
}
function endTest() {
nfcPeers = [];
sessionTokens = [];
@ -155,10 +170,47 @@ function connectToNFCTagExpectError(sessionToken, tech, errorMsg) {
return deferred.promise;
}
function setTechDiscoveredHandler() {
let deferred = Promise.defer();
let techDiscoveredHandler = function(msg) {
ok('Message handler for nfc-manager-tech-discovered');
is(msg.type, 'techDiscovered');
is(msg.errorMsg, undefined, 'Should not get error msg in tech discovered');
window.navigator.mozSetMessageHandler('nfc-manager-tech-discovered', null);
deferred.resolve();
};
window.navigator.mozSetMessageHandler('nfc-manager-tech-discovered',
techDiscoveredHandler);
return deferred.promise;
}
function setAndFireTechLostHandler() {
let deferred = Promise.defer();
let techLostHandler = function(msg) {
ok('Message handler for nfc-manager-tech-lost');
is(msg.type, 'techLost');
is(msg.errorMsg, undefined, 'Should not get error msg in tech lost');
window.navigator.mozSetMessageHandler('nfc-manager-tech-lost', null);
deferred.resolve();
};
window.navigator.mozSetMessageHandler('nfc-manager-tech-lost',
techLostHandler);
// TODO should be refactored once Bug 1023079 lands
toggleNFC(false);
return deferred.promise;
}
let tests = [
testNfcNotEnabledError,
testNfcBadSessionIdError,
testNfcConnectError
testNfcConnectError,
testNoErrorInTechMsg
];
/**

View File

@ -494,7 +494,7 @@ Nfc.prototype = {
debug("Received message from NFC worker: " + JSON.stringify(message));
// mapping error code to error message
if(message.status !== NFC.NFC_SUCCESS) {
if (message.status !== undefined && message.status !== NFC.NFC_SUCCESS) {
message.errorMsg = this.getErrorMessage(message.status);
}