Bug 1042651 - B2G NFC: getNFCPeer and getNFCTag should not throw error. r=smaug, r=allstars.chh, a=me

This commit is contained in:
Krzysztof Mioduszewski 2014-08-05 05:06:00 -04:00
parent c73bcff6d6
commit 919659bc81
3 changed files with 32 additions and 22 deletions

View File

@ -204,14 +204,12 @@ mozNfc.prototype = {
if (this._nfcContentHelper.setSessionToken(sessionToken)) {
return this._window.MozNFCTag._create(this._window, obj);
}
throw new Error("Unable to create NFCTag object, Reason: Bad SessionToken " +
sessionToken);
return null;
},
getNFCPeer: function getNFCPeer(sessionToken) {
if (!sessionToken || !this._nfcContentHelper.setSessionToken(sessionToken)) {
throw new Error("Unable to create NFCPeer object, Reason: Bad SessionToken " +
sessionToken);
return null;
}
if (!this.nfcObject) {

View File

@ -85,18 +85,6 @@ function testCheckP2PRegFailure() {
toggleNFC(true).then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0));
}
function testCheckNfcPeerObjForInvalidToken() {
try {
// Use a'fakeSessionToken'
let peer = nfc.getNFCPeer("fakeSessionToken");
ok(false, "Should not get a NFCPeer object.");
} catch (ex) {
ok(true, "Exception expected");
}
toggleNFC(false).then(runNextTest);
}
function testPeerLostShouldNotBeCalled() {
nfc.onpeerlost = function () {
ok(false, "onpeerlost shouldn't be called");
@ -151,12 +139,31 @@ function testPeerShouldThrow() {
toggleNFC(false).then(runNextTest);
}
function testPeerInvalidToken() {
let peer = nfc.getNFCPeer("fakeSessionToken");
is(peer, null, "NFCPeer should be null on wrong session token");
runNextTest();
}
/**
* Added for completeness in Bug 1042651,
* TODO: remove once Bug 963531 lands
*/
function testTagInvalidToken() {
let tag = nfc.getNFCTag("fakeSessionToken");
is(tag, null, "NFCTag should be null on wrong session token");
runNextTest();
}
let tests = [
testPeerReady,
testCheckP2PRegFailure,
testCheckNfcPeerObjForInvalidToken,
testPeerLostShouldNotBeCalled,
testPeerShouldThrow
testPeerShouldThrow,
testPeerInvalidToken,
testTagInvalidToken
];
SpecialPowers.pushPermissions(

View File

@ -46,10 +46,15 @@ interface MozNFCManager {
NavigatorProperty="mozNfc",
Func="Navigator::HasNFCSupport"]
interface MozNFC : EventTarget {
[Throws]
MozNFCTag getNFCTag(DOMString sessionId);
[Throws]
MozNFCPeer getNFCPeer(DOMString sessionId);
/**
* Returns MozNFCTag object or null in case of invalid sessionToken
*/
MozNFCTag? getNFCTag(DOMString sessionToken);
/**
* Returns MozNFCPeer object or null in case of invalid sessionToken
*/
MozNFCPeer? getNFCPeer(DOMString sessionToken);
[CheckPermissions="nfc-write"]
attribute EventHandler onpeerready;