Bug 1051754 - B2G NFC: Add marionette test for peer.sendFile. r=dimi
authorYoshi Huang <allstars.chh@mozilla.com>
Mon, 11 Aug 2014 18:26:52 +0800
changeset 213988 dbbb19ff95250e97b10c0e1bbb8f47056cb1817e
parent 213987 d1046e5b1f73037bbc002ded173abb1cf185af98
child 213989 da1c12e1832546ca5007b18bff739bb8e4a3d2e3
push id27770
push usercbook@mozilla.com
push dateWed, 05 Nov 2014 12:30:43 +0000
treeherdermozilla-central@72ae882fce1a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdimi
bugs1051754, 100644
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
dom/nfc/tests/marionette/head.js
dom/nfc/tests/marionette/manifest.ini
dom/nfc/tests/marionette/test_nfc_peer_sendFile.js
--- a/dom/nfc/tests/marionette/head.js
+++ b/dom/nfc/tests/marionette/head.js
@@ -55,29 +55,43 @@ let sysMsgHelper = (function() {
   function techLost(msg) {
     log("system message nfc-manager-tech-lost");
     let lost = mLost.shift();
     if (lost) {
       lost(msg);
     }
   }
 
-  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);
+    },
+
   };
 }());
 
 let NCI = (function() {
   function activateRE(re) {
     let deferred = Promise.defer();
     let cmd = 'nfc nci rf_intf_activated_ntf ' + re;
 
--- a/dom/nfc/tests/marionette/manifest.ini
+++ b/dom/nfc/tests/marionette/manifest.ini
@@ -5,11 +5,12 @@ qemu=true
 
 [test_ndef.js]
 [test_nfc_enabled.js]
 [test_nfc_manager_tech_discovered.js]
 [test_nfc_manager_tech_discovered_ndef.js]
 [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]
new file mode 100644
--- /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);