mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 980851 - Move NFC emulator helpers to head.js. r=dlee
The functions |activateRE|, |notifyDiscoverRE|, and |setTagData| are of general usefulness. They are now defined in the object |emulator|. Callers have been adapted.
This commit is contained in:
parent
7484b7bcdd
commit
640a3e3230
@ -22,6 +22,7 @@ let emulator = (function() {
|
||||
};
|
||||
|
||||
function run(cmd, callback) {
|
||||
log("Executing emulator command '" + cmd + "'");
|
||||
pendingCmdCount++;
|
||||
originalRunEmulatorCmd(cmd, function(result) {
|
||||
pendingCmdCount--;
|
||||
@ -29,10 +30,50 @@ let emulator = (function() {
|
||||
callback(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function activateRE(re) {
|
||||
let deferred = Promise.defer();
|
||||
let cmd = 'nfc nci rf_intf_activated_ntf ' + re;
|
||||
|
||||
this.run(cmd, function(result) {
|
||||
is(result.pop(), 'OK', 'check activation of RE' + re);
|
||||
deferred.resolve();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
function notifyDiscoverRE(re, type) {
|
||||
let deferred = Promise.defer();
|
||||
let cmd = 'nfc nci rf_discover_ntf ' + re + ' ' + type;
|
||||
|
||||
this.run(cmd, function(result) {
|
||||
is(result.pop(), 'OK', 'check discovery of RE' + re);
|
||||
deferred.resolve();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
function setTagData(re, flag, tnf, type, payload) {
|
||||
let deferred = Promise.defer();
|
||||
let cmd = "nfc tag set " + re +
|
||||
" [" + flag + "," + tnf + "," + type + "," + payload + ",]";
|
||||
|
||||
this.run(cmd, function(result) {
|
||||
is(result.pop(), "OK", "set NDEF data of tag" + re);
|
||||
deferred.resolve();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
return {
|
||||
run: run
|
||||
run: run,
|
||||
activateRE: activateRE,
|
||||
notifyDiscoverRE: notifyDiscoverRE,
|
||||
setTagData: setTagData,
|
||||
};
|
||||
}());
|
||||
|
||||
|
@ -16,36 +16,12 @@ function handleTechnologyDiscoveredRE0(msg) {
|
||||
toggleNFC(false).then(runNextTest);
|
||||
}
|
||||
|
||||
function activateRE(re) {
|
||||
let deferred = Promise.defer();
|
||||
let cmd = 'nfc nci rf_intf_activated_ntf ' + re;
|
||||
|
||||
emulator.run(cmd, function(result) {
|
||||
is(result.pop(), 'OK', 'check activation of RE' + re);
|
||||
deferred.resolve();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function notifyDiscoverRE(re, type) {
|
||||
let deferred = Promise.defer();
|
||||
let cmd = 'nfc nci rf_discover_ntf ' + re + ' ' + type;
|
||||
|
||||
emulator.run(cmd, function(result) {
|
||||
is(result.pop(), 'OK', 'check discover of RE' + re);
|
||||
deferred.resolve();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function testActivateRE0() {
|
||||
log('Running \'testActivateRE0\'');
|
||||
window.navigator.mozSetMessageHandler(
|
||||
'nfc-manager-tech-discovered', handleTechnologyDiscoveredRE0);
|
||||
|
||||
toggleNFC(true).then(() => activateRE(0));
|
||||
toggleNFC(true).then(() => emulator.activateRE(0));
|
||||
}
|
||||
|
||||
// Check NCI Spec 5.2, this will change NCI state from
|
||||
@ -56,9 +32,9 @@ function testRfDiscover() {
|
||||
'nfc-manager-tech-discovered', handleTechnologyDiscoveredRE0);
|
||||
|
||||
toggleNFC(true)
|
||||
.then(() => notifyDiscoverRE(0, NCI_MORE_NOTIFICATIONS))
|
||||
.then(() => notifyDiscoverRE(1, NCI_LAST_NOTIFICATION))
|
||||
.then(() => activateRE(0));
|
||||
.then(() => emulator.notifyDiscoverRE(0, NCI_MORE_NOTIFICATIONS))
|
||||
.then(() => emulator.notifyDiscoverRE(1, NCI_LAST_NOTIFICATION))
|
||||
.then(() => emulator.activateRE(0));
|
||||
}
|
||||
|
||||
let tests = [
|
||||
|
@ -10,32 +10,6 @@ let url = "http://www.mozilla.org";
|
||||
const T1T_RE_INDEX = 2;
|
||||
const T2T_RE_INDEX = 3;
|
||||
|
||||
function activateRE(re) {
|
||||
let deferred = Promise.defer();
|
||||
let cmd = "nfc nci rf_intf_activated_ntf " + re;
|
||||
|
||||
emulator.run(cmd, function(result) {
|
||||
is(result.pop(), "OK", "check activation of RE" + re);
|
||||
deferred.resolve();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function setTagData(re, flag, tnf, type, payload) {
|
||||
let deferred = Promise.defer();
|
||||
let cmd = "nfc tag set " + re +
|
||||
" [" + flag + "," + tnf + "," + type + "," + payload + ",]";
|
||||
|
||||
log("Executing \'" + cmd + "\'");
|
||||
emulator.run(cmd, function(result) {
|
||||
is(result.pop(), "OK", "set NDEF data of tag" + re);
|
||||
deferred.resolve();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function testUrlTagDiscover(re) {
|
||||
log("Running \'testUrlTagDiscover\'");
|
||||
// TODO : Make flag value readable.
|
||||
|
Loading…
Reference in New Issue
Block a user