gecko/dom/nfc/tests/marionette/test_nfc_manager_tech_discovered.js
Thomas Zimmermann 9bdfc43b80 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.
2014-06-10 02:21:00 -04:00

47 lines
1.4 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
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');
is(msg.techList[0], 'P2P', 'check for correct tech type');
toggleNFC(false).then(runNextTest);
}
function testActivateRE0() {
log('Running \'testActivateRE0\'');
window.navigator.mozSetMessageHandler(
'nfc-manager-tech-discovered', handleTechnologyDiscoveredRE0);
toggleNFC(true).then(() => emulator.activateRE(0));
}
// Check NCI Spec 5.2, this will change NCI state from
// DISCOVERY -> W4_ALL_DISCOVERIES -> W4_HOST_SELECT -> POLL_ACTIVE
function testRfDiscover() {
log('Running \'testRfDiscover\'');
window.navigator.mozSetMessageHandler(
'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));
}
let tests = [
testActivateRE0,
testRfDiscover
];
SpecialPowers.pushPermissions(
[{'type': 'nfc-manager', 'allow': true, context: document}], runTests);