Bug 1051754 - B2G NFC: Add marionette test for peer.sendFile. r=dimi

From 3cfb06874b6e838ad76e1817c7b69df81e0f802b Mon Sep 17 00:00:00 2001
---
 dom/nfc/tests/marionette/head.js                   | 20 +++++++--
 dom/nfc/tests/marionette/manifest.ini              |  1 +
 dom/nfc/tests/marionette/test_nfc_peer_sendFile.js | 49 ++++++++++++++++++++++
 3 files changed, 67 insertions(+), 3 deletions(-)
 create mode 100644 dom/nfc/tests/marionette/test_nfc_peer_sendFile.js
This commit is contained in:
Yoshi Huang 2014-08-11 18:26:52 +08:00
parent cfab2af42f
commit 1f36877080
3 changed files with 67 additions and 3 deletions

View File

@ -60,19 +60,33 @@ let sysMsgHelper = (function() {
}
}
let mDiscovered = [], mLost = [];
function sendFile(msg) {
log("system message nfc-manager-send-file");
let send = mSendFile.shift();
if (send) {
send(msg);
}
}
let mDiscovered = [], mLost = [], mSendFile = [];
window.navigator.mozSetMessageHandler("nfc-manager-tech-discovered",
techDiscovered);
window.navigator.mozSetMessageHandler("nfc-manager-tech-lost", techLost);
window.navigator.mozSetMessageHandler("nfc-manager-send-file", sendFile);
return {
waitForTechDiscovered: function (discovered) {
waitForTechDiscovered: function(discovered) {
mDiscovered.push(discovered);
},
waitForTechLost: function (lost) {
waitForTechLost: function(lost) {
mLost.push(lost);
},
waitForSendFile: function(sendFile) {
mSendFile.push(sendFile);
},
};
}());

View File

@ -10,6 +10,7 @@ qemu=true
[test_nfc_manager_tech_lost.js]
[test_nfc_peer.js]
[test_nfc_peer_sendndef.js]
[test_nfc_peer_sendFile.js]
[test_nfc_read_tag.js]
[test_nfc_checkP2PRegistration.js]
[test_nfc_error_messages.js]

View File

@ -0,0 +1,49 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 30000;
MARIONETTE_HEAD_JS = "head.js";
let MANIFEST_URL = "app://system.gaiamobile.org/manifest.webapp";
function sendFile(msg) {
log("sendFile msg="+JSON.stringify(msg));
let peer = nfc.getNFCPeer(msg.sessionToken);
ok(peer instanceof MozNFCPeer, "should get a MozNFCPeer");
ok(msg.blob instanceof Blob, "should get a Blob");
nfc.peerready = null;
NCI.deactivate().then(() => toggleNFC(false)).then(runNextTest);
}
function testSendFile() {
nfc.onpeerready = function(evt) {
let peer = evt.peer;
peer.sendFile(new Blob());
sysMsgHelper.waitForSendFile(sendFile);
};
sysMsgHelper.waitForTechDiscovered(function(msg) {
let request = nfc.checkP2PRegistration(MANIFEST_URL);
request.onsuccess = function(evt) {
is(request.result, true, "check for P2P registration result");
nfc.notifyUserAcceptedP2P(MANIFEST_URL);
}
request.onerror = function() {
ok(false, "checkP2PRegistration failed.");
toggleNFC(false).then(runNextTest);
}
});
toggleNFC(true).then(() => NCI.activateRE(emulator.P2P_RE_INDEX_0));
}
let tests = [
testSendFile
];
SpecialPowers.pushPermissions(
[{"type": "nfc", "allow": true,
"read": true, 'write': true, context: document},
{"type": "nfc-manager", 'allow': true, context: document}], runTests);