Bug 1035606 - [NFC] Testcase cleanup. r=tzimmermann

This commit is contained in:
Dimi Lee 2014-07-10 11:33:10 +08:00
Родитель 62107a3c05
Коммит b82961efc1
9 изменённых файлов: 75 добавлений и 77 удалений

Просмотреть файл

@ -33,11 +33,23 @@ let emulator = (function() {
});
};
return {
run: run,
P2P_RE_INDEX_0 : 0,
P2P_RE_INDEX_1 : 1,
T1T_RE_INDEX : 2,
T2T_RE_INDEX : 3,
T3T_RE_INDEX : 4,
T4T_RE_INDEX : 5
};
}());
let NCI = (function() {
function activateRE(re) {
let deferred = Promise.defer();
let cmd = 'nfc nci rf_intf_activated_ntf ' + re;
this.run(cmd, function(result) {
emulator.run(cmd, function(result) {
is(result.pop(), 'OK', 'check activation of RE' + re);
deferred.resolve();
});
@ -49,7 +61,7 @@ let emulator = (function() {
let deferred = Promise.defer();
let cmd = 'nfc nci rf_intf_deactivate_ntf';
this.run(cmd, function(result) {
emulator.run(cmd, function(result) {
is(result.pop(), 'OK', 'check deactivate');
deferred.resolve();
});
@ -61,7 +73,7 @@ let emulator = (function() {
let deferred = Promise.defer();
let cmd = 'nfc nci rf_discover_ntf ' + re + ' ' + type;
this.run(cmd, function(result) {
emulator.run(cmd, function(result) {
is(result.pop(), 'OK', 'check discovery of RE' + re);
deferred.resolve();
});
@ -69,12 +81,23 @@ let emulator = (function() {
return deferred.promise;
};
function setTagData(re, flag, tnf, type, payload) {
return {
activateRE: activateRE,
deactivate: deactivate,
notifyDiscoverRE: notifyDiscoverRE,
LAST_NOTIFICATION: 0,
LIMIT_NOTIFICATION: 1,
MORE_NOTIFICATIONS: 2
};
}());
let TAG = (function() {
function setData(re, flag, tnf, type, payload) {
let deferred = Promise.defer();
let cmd = "nfc tag set " + re +
" [" + flag + "," + tnf + "," + type + "," + payload + ",]";
this.run(cmd, function(result) {
emulator.run(cmd, function(result) {
is(result.pop(), "OK", "set NDEF data of tag" + re);
deferred.resolve();
});
@ -82,24 +105,31 @@ let emulator = (function() {
return deferred.promise;
};
function clearTagData(re) {
function clearData(re) {
let deferred = Promise.defer();
let cmd = "nfc tag clear " + re;
this.run(cmd, function(result) {
emulator.run(cmd, function(result) {
is(result.pop(), "OK", "clear tag" + re);
deferred.resolve();
});
}
function snepPutNdef(dsap, ssap, flags, tnf, type, payload, id) {
return {
setData: setData,
clearData: clearData
};
}());
let SNEP = (function() {
function put(dsap, ssap, flags, tnf, type, payload, id) {
let deferred = Promise.defer();
let cmd = "nfc snep put " + dsap + " " + ssap + " [" + flags + "," +
tnf + "," +
type + "," +
payload + "," +
id + "]";
this.run(cmd, function(result) {
emulator.run(cmd, function(result) {
is(result.pop(), "OK", "send SNEP PUT");
deferred.resolve();
});
@ -108,13 +138,8 @@ let emulator = (function() {
};
return {
run: run,
activateRE: activateRE,
deactivate: deactivate,
notifyDiscoverRE: notifyDiscoverRE,
setTagData: setTagData,
clearTagData: clearTagData,
snepPutNdef: snepPutNdef
put: put,
SAP_NDEF: 4
};
}());
@ -152,18 +177,6 @@ function clearPendingMessages(type) {
});
}
function enableRE0() {
let deferred = Promise.defer();
let cmd = 'nfc nci rf_intf_activated_ntf 0';
emulator.run(cmd, function(result) {
is(result.pop(), 'OK', 'check activation of RE0');
deferred.resolve();
});
return deferred.promise;
}
function cleanUp() {
log('Cleaning up');
waitFor(function() {

Просмотреть файл

@ -4,7 +4,7 @@
'use strict';
/* globals log, is, ok, runTests, toggleNFC, runNextTest,
SpecialPowers, nfc, enableRE0 */
SpecialPowers, nfc */
const MARIONETTE_TIMEOUT = 30000;
const MARIONETTE_HEAD_JS = 'head.js';
@ -50,7 +50,7 @@ function testWithTargetNoSessionToken() {
function testWithSessionTokenWithTarget() {
log('testWithSessionTokenWithTarget');
toggleNFC(true)
.then(enableRE0)
.then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0))
.then(registerOnpeerready)
.then(() => fireCheckP2PReg(MANIFEST_URL))
.then((result) => {
@ -69,7 +69,7 @@ function testWithSessionTokenWithTarget() {
function testWithSessionTokenNoTarget() {
log('testWithSessionTokenNoTarget');
toggleNFC(true)
.then(enableRE0)
.then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0))
.then(() => fireCheckP2PReg(MANIFEST_URL))
.then((result) => {
is(result, false,
@ -87,7 +87,7 @@ function testWithSessionTokenNoTarget() {
function testWithSessionTokenWrongTarget() {
log('testWithSessionTokenWrongTarget');
toggleNFC(true)
.then(enableRE0)
.then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0))
.then(registerOnpeerready)
.then(() => fireCheckP2PReg(FAKE_MANIFEST_URL))
.then((result) => {

Просмотреть файл

@ -27,7 +27,7 @@ let sessionTokens = [];
function testNfcNotEnabledError() {
log('testNfcNotEnabledError');
toggleNFC(true)
.then(() => emulator.activateRE(0))
.then(() => emulator.activateRE(emulator.P2P_RE_INDEX_0))
.then(registerAndFireOnpeerready)
.then(() => toggleNFC(false))
.then(() => sendNDEFExpectError(nfcPeers[0], 'NfcNotEnabledError'))
@ -45,10 +45,10 @@ function testNfcNotEnabledError() {
function testNfcBadSessionIdError() {
log('testNfcBadSessionIdError');
toggleNFC(true)
.then(() => emulator.activateRE(0))
.then(() => emulator.activateRE(emulator.P2P_RE_INDEX_0))
.then(registerAndFireOnpeerready)
.then(() => emulator.deactivate())
.then(() => emulator.activateRE(0))
.then(() => emulator.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'))
@ -65,7 +65,7 @@ function testNfcBadSessionIdError() {
function testNfcConnectError() {
log('testNfcConnectError');
toggleNFC(true)
.then(() => emulator.activateRE(0))
.then(() => emulator.activateRE(emulator.P2P_RE_INDEX_0))
.then(registerAndFireOnpeerready)
.then(() => connectToNFCTagExpectError(sessionTokens[0],
'NDEF',
@ -83,7 +83,7 @@ function testNfcConnectError() {
function testNoErrorInTechMsg() {
log('testNoErrorInTechMsg');
toggleNFC(true)
.then(() => emulator.activateRE(0))
.then(() => emulator.activateRE(emulator.P2P_RE_INDEX_0))
.then(setTechDiscoveredHandler)
.then(setAndFireTechLostHandler)
.then(() => toggleNFC(false))

Просмотреть файл

@ -4,11 +4,6 @@
MARIONETTE_TIMEOUT = 30000;
MARIONETTE_HEAD_JS = 'head.js';
// See nfc-nci.h.
const NCI_LAST_NOTIFICATION = 0;
const NCI_LIMIT_NOTIFICATION = 1;
const NCI_MORE_NOTIFICATIONS = 2;
function handleTechnologyDiscoveredRE0(msg) {
log('Received \'nfc-manager-tech-discovered\'');
is(msg.type, 'techDiscovered', 'check for correct message type');
@ -21,7 +16,7 @@ function testActivateRE0() {
window.navigator.mozSetMessageHandler(
'nfc-manager-tech-discovered', handleTechnologyDiscoveredRE0);
toggleNFC(true).then(() => emulator.activateRE(0));
toggleNFC(true).then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0));
}
// Check NCI Spec 5.2, this will change NCI state from
@ -32,9 +27,9 @@ function testRfDiscover() {
'nfc-manager-tech-discovered', handleTechnologyDiscoveredRE0);
toggleNFC(true)
.then(() => emulator.notifyDiscoverRE(0, NCI_MORE_NOTIFICATIONS))
.then(() => emulator.notifyDiscoverRE(1, NCI_LAST_NOTIFICATION))
.then(() => emulator.activateRE(0));
.then(() => NCI.notifyDiscoverRE(emulator.P2P_RE_INDEX_0, NCI.MORE_NOTIFICATIONS))
.then(() => NCI.notifyDiscoverRE(emulator.P2P_RE_INDEX_1, NCI.LAST_NOTIFICATION))
.then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0));
}
let tests = [

Просмотреть файл

@ -11,11 +11,6 @@ let id = "";
let ndef = null;
// See nfc-nci.h.
const NCI_LAST_NOTIFICATION = 0;
const NCI_LIMIT_NOTIFICATION = 1;
const NCI_MORE_NOTIFICATIONS = 2;
function handleTechnologyDiscoveredRE0(msg) {
log("Received 'nfc-manager-tech-discovered'");
is(msg.type, "techDiscovered", "check for correct message type");
@ -38,9 +33,9 @@ function testReceiveNDEF() {
window.navigator.mozSetMessageHandler(
"nfc-manager-tech-discovered", handleTechnologyDiscoveredRE0);
toggleNFC(true)
.then(() => emulator.activateRE(0))
.then(() => emulator.snepPutNdef(4, 4, 0, tnf, btoa(type),
btoa(payload), btoa(id)));
.then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0))
.then(() => SNEP.put(SNEP.SAP_NDEF, SNEP.SAP_NDEF, 0, tnf, btoa(type),
btoa(payload), btoa(id)));
}
let tests = [

Просмотреть файл

@ -16,7 +16,7 @@ function handleTechnologyDiscoveredRE0(msg) {
is(msg.type, 'techDiscovered', 'check for correct message type');
is(msg.techList[0], 'P2P', 'check for correct tech type');
emulator.deactivate();
NCI.deactivate();
}
function testTechLost() {
@ -26,7 +26,7 @@ function testTechLost() {
window.navigator.mozSetMessageHandler(
'nfc-manager-tech-lost', handleTechnologyLost);
toggleNFC(true).then(() => emulator.activateRE(0));
toggleNFC(true).then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0));
}
let tests = [

Просмотреть файл

@ -14,7 +14,7 @@ function peerReadyCb(evt) {
// reset callback.
nfc.onpeerready = null;
emulator.deactivate();
NCI.deactivate();
}
function peerLostCb() {
@ -71,14 +71,14 @@ function testPeerReady() {
window.navigator.mozSetMessageHandler(
"nfc-manager-tech-discovered", handleTechnologyDiscoveredRE0);
toggleNFC(true).then(() => emulator.activateRE(0));
toggleNFC(true).then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0));
}
function testCheckP2PRegFailure() {
window.navigator.mozSetMessageHandler(
"nfc-manager-tech-discovered", handleTechnologyDiscoveredRE0ForP2PRegFailure);
toggleNFC(true).then(() => emulator.activateRE(0));
toggleNFC(true).then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0));
}
function testCheckNfcPeerObjForInvalidToken() {

Просмотреть файл

@ -44,7 +44,7 @@ function testOnPeerReadyRE0() {
log("Running \'testOnPeerReadyRE0\'");
window.navigator.mozSetMessageHandler(
"nfc-manager-tech-discovered", handleTechnologyDiscoveredRE0);
toggleNFC(true).then(enableRE0);
toggleNFC(true).then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0));
}
let tests = [

Просмотреть файл

@ -6,11 +6,6 @@ MARIONETTE_HEAD_JS = "head.js";
let url = "http://www.mozilla.org";
const T1T_RE_INDEX = 2;
const T2T_RE_INDEX = 3;
const T3T_RE_INDEX = 4;
const T4T_RE_INDEX = 5;
function testUrlTagDiscover(re) {
log("Running \'testUrlTagDiscover\'");
// TODO : Make flag value readable.
@ -36,8 +31,8 @@ function testUrlTagDiscover(re) {
});
toggleNFC(true)
.then(() => emulator.setTagData(re, flag, tnf, btoa(type), btoa(payload)))
.then(() => emulator.activateRE(re));
.then(() => TAG.setData(re, flag, tnf, btoa(type), btoa(payload)))
.then(() => NCI.activateRE(re));
}
function testEmptyTagDiscover(re) {
@ -56,40 +51,40 @@ function testEmptyTagDiscover(re) {
});
toggleNFC(true)
.then(() => emulator.clearTagData(re))
.then(() => emulator.activateRE(re));
.then(() => TAG.clearData(re))
.then(() => NCI.activateRE(re));
}
function testUrlT1TDiscover() {
testUrlTagDiscover(T1T_RE_INDEX);
testUrlTagDiscover(emulator.T1T_RE_INDEX);
}
function testUrlT2TDiscover() {
testUrlTagDiscover(T2T_RE_INDEX);
testUrlTagDiscover(emulator.T2T_RE_INDEX);
}
function testUrlT3TDiscover() {
testUrlTagDiscover(T3T_RE_INDEX);
testUrlTagDiscover(emulator.T3T_RE_INDEX);
}
function testUrlT4TDiscover() {
testUrlTagDiscover(T4T_RE_INDEX);
testUrlTagDiscover(emulator.T4T_RE_INDEX);
}
function testEmptyT1TDiscover() {
testEmptyTagDiscover(T1T_RE_INDEX);
testEmptyTagDiscover(emulator.T1T_RE_INDEX);
}
function testEmptyT2TDiscover() {
testEmptyTagDiscover(T2T_RE_INDEX);
testEmptyTagDiscover(emulator.T2T_RE_INDEX);
}
function testEmptyT3TDiscover() {
testEmptyTagDiscover(T3T_RE_INDEX);
testEmptyTagDiscover(emulator.T3T_RE_INDEX);
}
function testEmptyT4TDiscover() {
testEmptyTagDiscover(T4T_RE_INDEX);
testEmptyTagDiscover(emulator.T4T_RE_INDEX);
}
let tests = [