Bug 1046554 - Part 2: update marionette tests. r=dimi

From d7dafea4dcff00edbe40ee0880ca71b804893622 Mon Sep 17 00:00:00 2001
---
 .../tests/marionette/test_nfc_error_messages.js    | 43 +---------------------
 dom/nfc/tests/marionette/test_nfc_peer.js          | 20 ++++++++--
 2 files changed, 17 insertions(+), 46 deletions(-)
This commit is contained in:
Yoshi Huang 2014-08-11 17:03:52 +08:00
parent 7694e3e977
commit ae558038c0
2 changed files with 17 additions and 46 deletions

View File

@ -16,7 +16,6 @@ const NDEF_MESSAGE = [new MozNDEFRecord(0x01,
new Uint8Array(0x20))];
let nfcPeers = [];
let sessionTokens = [];
/**
* Enables nfc and RE0 then registers onpeerready callback and once
@ -57,24 +56,6 @@ function testNfcBadSessionIdError() {
.catch(handleRejectedPromise);
}
/**
* Eables nfc and RE0, register onpeerready callback, once it's fired
* it stores sessionToken. Using sessionToken cretes mozNFCTag and fires
* mozNFCTag.connect('NDEF') which should result in NfcConnectError.
*/
function testNfcConnectError() {
log('testNfcConnectError');
toggleNFC(true)
.then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0))
.then(registerAndFireOnpeerready)
.then(() => connectToNFCTagExpectError(sessionTokens[0],
'NDEF',
'NfcConnectError'))
.then(() => toggleNFC(false))
.then(endTest)
.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
@ -103,7 +84,6 @@ function testNoErrorInTechMsg() {
function endTest() {
nfcPeers = [];
sessionTokens = [];
runNextTest();
}
@ -116,8 +96,7 @@ function registerAndFireOnpeerready() {
let deferred = Promise.defer();
nfc.onpeerready = function(event) {
sessionTokens.push(event.detail);
nfcPeers.push(nfc.getNFCPeer(event.detail));
nfcPeers.push(event.peer);
nfc.onpeerready = null;
deferred.resolve();
};
@ -161,25 +140,6 @@ function sendNDEFExpectError(peer, errorMsg) {
return deferred.promise;
}
function connectToNFCTagExpectError(sessionToken, tech, errorMsg) {
let deferred = Promise.defer();
let nfcTag = nfc.getNFCTag(sessionTokens[0]);
let req = nfcTag.connect(tech);
req.onsuccess = function() {
ok(false, 'we should not be able to connect to the tag');
deferred.reject();
};
req.onerror = function() {
ok(true, 'we should get an error');
is(req.error.name, errorMsg, 'Should have proper error name');
deferred.resolve();
};
return deferred.promise;
}
function setAndFireTechLostHandler() {
let deferred = Promise.defer();
@ -201,7 +161,6 @@ function setAndFireTechLostHandler() {
let tests = [
testNfcNotEnabledError,
testNfcBadSessionIdError,
testNfcConnectError,
testNoErrorInTechMsg
];

View File

@ -9,9 +9,7 @@ let INCORRECT_MANIFEST_URL = "app://xyz.gaiamobile.org/manifest.webapp";
function peerReadyCb(evt) {
log("peerReadyCb called");
let peer = nfc.getNFCPeer(evt.detail);
let peer1 = nfc.getNFCPeer(evt.detail);
ok(peer == peer1, "Should get the same NFCPeer object.");
let peer = evt.peer;
ok(peer instanceof MozNFCPeer, "Should get a NFCPeer object.");
NCI.deactivate();
@ -77,6 +75,19 @@ function testPeerReady() {
toggleNFC(true).then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0));
}
function testGetNFCPeer() {
sysMsgHelper.waitForTechDiscovered(function (msg) {
let peer = nfc.getNFCPeer(msg.sessionToken);
ok(peer instanceof MozNFCPeer, "Should get a NFCPeer object.");
let peer1 = nfc.getNFCPeer(msg.sessionToken);
ok(peer == peer1, "Should get the same MozNFCPeer object");
NCI.deactivate().then(() => toggleNFC(false)).then(runNextTest);
});
toggleNFC(true).then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0));
}
function testCheckP2PRegFailure() {
sysMsgHelper.waitForTechDiscovered(handleTechnologyDiscoveredRE0ForP2PRegFailure);
@ -120,7 +131,7 @@ function testPeerShouldThrow() {
nfc.onpeerready = function (evt) {
log("testPeerShouldThrow peerready");
peer = nfc.getNFCPeer(evt.detail);
peer = evt.peer;
NCI.deactivate();
};
@ -184,6 +195,7 @@ function testTagInvalidToken() {
let tests = [
testPeerReady,
testGetNFCPeer,
testCheckP2PRegFailure,
testPeerLostShouldNotBeCalled,
testPeerShouldThrow,