diff --git a/dom/nfc/tests/marionette/head.js b/dom/nfc/tests/marionette/head.js index e4e3bf80eb9..9a3c8cf6592 100644 --- a/dom/nfc/tests/marionette/head.js +++ b/dom/nfc/tests/marionette/head.js @@ -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); + }, + }; }()); diff --git a/dom/nfc/tests/marionette/manifest.ini b/dom/nfc/tests/marionette/manifest.ini index da072c9ee14..d9c258f204a 100644 --- a/dom/nfc/tests/marionette/manifest.ini +++ b/dom/nfc/tests/marionette/manifest.ini @@ -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] diff --git a/dom/nfc/tests/marionette/test_nfc_peer_sendFile.js b/dom/nfc/tests/marionette/test_nfc_peer_sendFile.js new file mode 100644 index 00000000000..ee93cf99209 --- /dev/null +++ b/dom/nfc/tests/marionette/test_nfc_peer_sendFile.js @@ -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);