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 213344 52fc270e59adfec0362a023e8a272dd27c4aed74
parent 213343 7d30d8aee00fff0c34253fc1318ed011b7c00b16
child 213345 e595d976e965d777c845f6a4e0f4a81b7d9bbf7c
push id6741
push userraliiev@mozilla.com
push dateTue, 02 Sep 2014 16:57:58 +0000
treeherdermozilla-aurora@aed50d3edf33 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdimi
bugs1051754, 100644
milestone34.0a1
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);