Bug 959059 - B2G NFC: Marionette test to check P2P registration for an incorrect manifest Url. r=allstars.chh
authorSiddartha Pothapragada <Siddartha.Pothapragada@telekom.com>
Wed, 30 Apr 2014 10:17:00 +0200
changeset 181734 574ed4c4e3ddc73ade3716df844b089b70f7d33f
parent 181733 53188cff457ff8f6a03410bd4818717fd1f25035
child 181735 e21efd8655aba1ed691d3b456193109b35ea4f7d
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersallstars
bugs959059
milestone32.0a1
Bug 959059 - B2G NFC: Marionette test to check P2P registration for an incorrect manifest Url. r=allstars.chh
dom/nfc/tests/marionette/test_nfc_peer.js
--- a/dom/nfc/tests/marionette/test_nfc_peer.js
+++ b/dom/nfc/tests/marionette/test_nfc_peer.js
@@ -1,15 +1,16 @@
 /* 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";
+let INCORRECT_MANIFEST_URL = "app://xyz.gaiamobile.org/manifest.webapp";
 
 function peerReadyCb(evt) {
   log("peerReadyCb called");
   let peer = nfc.getNFCPeer(evt.detail);
   ok(peer instanceof MozNFCPeer, "Should get a NFCPeer object.");
 
   // reset callback and NFC Hardware.
   nfc.onpeerready = null;
@@ -20,25 +21,49 @@ function handleTechnologyDiscoveredRE0(m
   log("Received \'nfc-manager-tech-discovered\'");
   is(msg.type, "techDiscovered", "check for correct message type");
   is(msg.techList[0], "P2P", "check for correct tech type");
 
   nfc.onpeerready = peerReadyCb;
 
   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, runNextTest);
   }
 }
 
+function handleTechnologyDiscoveredRE0ForP2PRegFailure(msg) {
+  log("Received \'nfc-manager-tech-discovered\'");
+  is(msg.type, "techDiscovered", "check for correct message type");
+  is(msg.techList[0], "P2P", "check for correct tech type");
+
+  nfc.onpeerready = peerReadyCb;
+
+  let request = nfc.checkP2PRegistration(INCORRECT_MANIFEST_URL);
+  request.onsuccess = function (evt) {
+    is(request.result, false, "check for P2P registration result");
+
+    nfc.onpeerready = null;
+    toggleNFC(false, runNextTest);
+  }
+
+  request.onerror = function () {
+    ok(false, "checkP2PRegistration failed.");
+
+    nfc.onpeerready = null;
+    toggleNFC(false, runNextTest);
+  }
+}
+
 function activateRE(re) {
   let deferred = Promise.defer();
   let cmd = "nfc ntf rf_intf_activated " + re;
 
   emulator.run(cmd, function(result) {
     is(result.pop(), "OK", "check activation of RE" + re);
     deferred.resolve();
   });
@@ -50,15 +75,25 @@ function testPeerReady() {
   window.navigator.mozSetMessageHandler(
     "nfc-manager-tech-discovered", handleTechnologyDiscoveredRE0);
 
   toggleNFC(true, function() {
     activateRE(0);
   });
 }
 
+function testCheckP2PRegFailure() {
+  window.navigator.mozSetMessageHandler(
+    "nfc-manager-tech-discovered", handleTechnologyDiscoveredRE0ForP2PRegFailure);
+
+  toggleNFC(true, function() {
+    activateRE(0);
+  });
+}
+
 let tests = [
-  testPeerReady
+  testPeerReady,
+  testCheckP2PRegFailure
 ];
 
 SpecialPowers.pushPermissions(
   [{"type": "nfc-manager", "allow": true, context: document},
    {"type": "nfc-write", "allow": true, context: document}], runTests);