Bug 1033218 - [NFC] use emulator command triggering tech-lost. r=allstars.chh
authorKrzysztof Mioduszewski <kmioduszewski@gmail.com>
Mon, 07 Jul 2014 20:40:01 +0200
changeset 192926 4526c544942ffe282513be5e103d3bf25d90f375
parent 192925 087dcd6f346ac9d7945f763805316d02fd4838e7
child 192927 cb4fb4caaac675f3eebd66f94cf5f1fd151c453d
push id8720
push useryhuang@mozilla.com
push dateWed, 09 Jul 2014 03:19:19 +0000
treeherderb2g-inbound@4526c544942f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersallstars.chh
bugs1033218
milestone33.0a1
Bug 1033218 - [NFC] use emulator command triggering tech-lost. r=allstars.chh
dom/nfc/tests/marionette/test_nfc_error_messages.js
--- a/dom/nfc/tests/marionette/test_nfc_error_messages.js
+++ b/dom/nfc/tests/marionette/test_nfc_error_messages.js
@@ -1,15 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 'use strict';
 
 /* globals log, is, ok, runTests, toggleNFC, runNextTest,
-   SpecialPowers, nfc, enableRE0, MozNDEFRecord */
+   SpecialPowers, nfc, MozNDEFRecord, emulator */
 
 const MARIONETTE_TIMEOUT = 60000;
 const MARIONETTE_HEAD_JS = 'head.js';
 
 const MANIFEST_URL = 'app://system.gaiamobile.org/manifest.webapp';
 const NDEF_MESSAGE = [new MozNDEFRecord(0x01,
                                         new Uint8Array(0x84),
                                         new Uint8Array(0),
@@ -22,17 +22,17 @@ let sessionTokens = [];
  * Enables nfc and RE0 then registers onpeerready callback and once
  * it's fired it creates mozNFCPeer and stores it for later.
  * After disabling nfc tries to do mozNFCPeer.sendNDEF which should
  * fail with NfcNotEnabledError.
  */
 function testNfcNotEnabledError() {
   log('testNfcNotEnabledError');
   toggleNFC(true)
-  .then(enableRE0)
+  .then(() => emulator.activateRE(0))
   .then(registerAndFireOnpeerready)
   .then(() => toggleNFC(false))
   .then(() => sendNDEFExpectError(nfcPeers[0], 'NfcNotEnabledError'))
   .then(endTest)
   .catch(handleRejectedPromise);
 }
 
 /**
@@ -40,38 +40,37 @@ function testNfcNotEnabledError() {
  * it creates and stores mozNFCPeer. Disables nfc, enables nfc and
  * once again registers and fires new onpeerready callback and stores
  * mozNfcPeer. Than fires sendNDEF on the first stored peer which
  * should have invalid session token and we should get NfcBadSessionIdError
  */
 function testNfcBadSessionIdError() {
   log('testNfcBadSessionIdError');
   toggleNFC(true)
-  .then(enableRE0)
+  .then(() => emulator.activateRE(0))
   .then(registerAndFireOnpeerready)
-  .then(() => toggleNFC(false))
-  .then(() => toggleNFC(true))
-  .then(enableRE0)
+  .then(() => emulator.deactivate())
+  .then(() => emulator.activateRE(0))
   .then(registerAndFireOnpeerready)
   // we have 2 peers in nfcPeers array, peer0 has old/invalid session token
   .then(() => sendNDEFExpectError(nfcPeers[0], 'NfcBadSessionIdError'))
   .then(() => toggleNFC(false))
   .then(endTest)
   .catch(handleRejectedPromise);
 }
 
 /**
  * Eables nfc and RE0, register onpeerready callback, once it's fired
  * it stores sessionToken. Using sessionToken cretes mozNFCTag and fires
  * mozNFCTag.connect('NDEF') which should result in NfcConnectError.
  */
 function testNfcConnectError() {
   log('testNfcConnectError');
   toggleNFC(true)
-  .then(enableRE0)
+  .then(() => emulator.activateRE(0))
   .then(registerAndFireOnpeerready)
   .then(() => connectToNFCTagExpectError(sessionTokens[0],
                                          'NDEF',
                                          'NfcConnectError'))
   .then(() => toggleNFC(false))
   .then(endTest)
   .catch(handleRejectedPromise);
 }
@@ -79,19 +78,20 @@ function testNfcConnectError() {
 /**
  * Enables nfc and RE0, registers tech-discovered msg handler, once it's
  * fired set tech-lost handler and disables nfc. In both handlers checks
  * if error message is not present.
  */
 function testNoErrorInTechMsg() {
   log('testNoErrorInTechMsg');
   toggleNFC(true)
-  .then(enableRE0)
+  .then(() => emulator.activateRE(0))
   .then(setTechDiscoveredHandler)
   .then(setAndFireTechLostHandler)
+  .then(() => toggleNFC(false))
   .then(endTest)
   .catch(handleRejectedPromise);
 }
 
 function endTest() {
   nfcPeers = [];
   sessionTokens = [];
   runNextTest();
@@ -196,18 +196,19 @@ function setAndFireTechLostHandler() {
     is(msg.errorMsg, undefined, 'Should not get error msg in tech lost');
 
     window.navigator.mozSetMessageHandler('nfc-manager-tech-lost', null);
     deferred.resolve();
   };
 
   window.navigator.mozSetMessageHandler('nfc-manager-tech-lost',
                                         techLostHandler);
-  // TODO should be refactored once Bug 1023079 lands
-  toggleNFC(false);
+
+  // triggers tech-lost
+  emulator.deactivate();
   return deferred.promise;
 }
 
 let tests = [
   testNfcNotEnabledError,
   testNfcBadSessionIdError,
   testNfcConnectError,
   testNoErrorInTechMsg