Bug 1087928 - write marionette-webapi tests for ontagfound. r=yoshi

This commit is contained in:
Thomas Nguyen 2015-11-24 18:00:00 +01:00
parent 50beb391b6
commit 5d4e906c48
3 changed files with 84 additions and 0 deletions

View File

@ -14,3 +14,5 @@ qemu=true
[test_nfc_read_tag.js]
[test_nfc_checkP2PRegistration.js]
[test_nfc_error_messages.js]
[test_nfc_tag_found.js]
[test_nfc_tag_lost.js]

View File

@ -0,0 +1,46 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 30000;
MARIONETTE_HEAD_JS = 'head.js';
function handleTechnologyDiscoveredRE0(msg) {
log('Received \'nfc-manager-tech-discovered\'');
ok(msg.peer, 'check for correct tech type');
deactivateAndWaitForTechLost().then(() => toggleNFC(false)).then(runNextTest);
}
function tagFoundCb(evt) {
log("tagFoundCb called ");
ok(evt.tag instanceof MozNFCTag, "Should get a NFCTag object.");
nfc.ontagfound = null;
deactivateAndWaitForTechLost().then(() => toggleNFC(false)).then(runNextTest);
}
function tagFoundErrorCb(evt) {
ok(false, "ontagfound shouldn't be called");
}
function testTagFound() {
nfc.ontagfound = tagFoundCb;
toggleNFC(true).then(() => NCI.activateRE(emulator.T1T_RE_INDEX));
}
function testTagFoundShouldNotFired() {
nfc.ontagfound = tagFoundErrorCb;
sysMsgHelper.waitForTechDiscovered(handleTechnologyDiscoveredRE0);
toggleNFC(true).then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0));
}
var tests = [
testTagFound,
testTagFoundShouldNotFired
];
SpecialPowers.pushPermissions(
[{"type": "nfc", "allow": true, context: document},
{'type': 'nfc-manager', 'allow': true, context: document}], runTests);

View File

@ -0,0 +1,36 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 30000;
MARIONETTE_HEAD_JS = 'head.js';
function tagFoundCb(evt) {
log("tagFoundCb called ");
ok(evt.tag instanceof MozNFCTag, "Should get a NFCTag object.");
NCI.deactivate();
}
function tagLostCb(evt) {
log("tagLostCb called ");
ok(true);
nfc.ontagfound = null;
nfc.ontaglost = null;
toggleNFC(false).then(runNextTest);
}
function testTagLost() {
nfc.ontagfound = tagFoundCb;
nfc.ontaglost = tagLostCb;
toggleNFC(true).then(() => NCI.activateRE(emulator.T1T_RE_INDEX));
}
var tests = [
testTagLost
];
SpecialPowers.pushPermissions(
[{"type": "nfc", "allow": true, context: document},
{'type': 'nfc-manager', 'allow': true, context: document}], runTests);