dom/nfc/tests/marionette/test_nfc_manager_tech_discovered.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 MARIONETTE_TIMEOUT = 30000;
     5 MARIONETTE_HEAD_JS = 'head.js';
     7 let Promise =
     8   SpecialPowers.Cu.import("resource://gre/modules/Promise.jsm").Promise;
    10 // See nfc-nci.h.
    11 const NCI_LAST_NOTIFICATION  = 0;
    12 const NCI_LIMIT_NOTIFICATION = 1;
    13 const NCI_MORE_NOTIFICATIONS = 2;
    15 function handleTechnologyDiscoveredRE0(msg) {
    16   log('Received \'nfc-manager-tech-discovered\'');
    17   is(msg.type, 'techDiscovered', 'check for correct message type');
    18   is(msg.techList[0], 'P2P', 'check for correct tech type');
    19   toggleNFC(false, runNextTest);
    20 }
    22 function activateRE(re) {
    23   let deferred = Promise.defer();
    24   let cmd = 'nfc ntf rf_intf_activated ' + re;
    26   emulator.run(cmd, function(result) {
    27     is(result.pop(), 'OK', 'check activation of RE0');
    28     deferred.resolve();
    29   });
    31   return deferred.promise;
    32 }
    34 function notifyDiscoverRE(re, type) {
    35   let deferred = Promise.defer();
    36   let cmd = 'nfc ntf rf_discover ' + re + ' ' + type;
    38   emulator.run(cmd, function(result) {
    39     is(result.pop(), 'OK', 'check discover of RE' + re);
    40     deferred.resolve();
    41   });
    43   return deferred.promise;
    44 }
    46 function testActivateRE0() {
    47   log('Running \'testActivateRE0\'');
    48   window.navigator.mozSetMessageHandler(
    49     'nfc-manager-tech-discovered', handleTechnologyDiscoveredRE0);
    51   toggleNFC(true, function() {
    52     activateRE(0);
    53   });
    54 }
    56 // Check NCI Spec 5.2, this will change NCI state from
    57 // DISCOVERY -> W4_ALL_DISCOVERIES -> W4_HOST_SELECT -> POLL_ACTIVE
    58 function testRfDiscover() {
    59   log('Running \'testRfDiscover\'');
    60   window.navigator.mozSetMessageHandler(
    61     'nfc-manager-tech-discovered', handleTechnologyDiscoveredRE0);
    63   toggleNFC(true, function() {
    64     notifyDiscoverRE(0, NCI_MORE_NOTIFICATIONS)
    65     .then(() => notifyDiscoverRE(1, NCI_LAST_NOTIFICATION))
    66     .then(() => activateRE(0));
    67   });
    68 }
    70 let tests = [
    71   testActivateRE0,
    72   testRfDiscover
    73 ];
    75 SpecialPowers.pushPermissions(
    76   [{'type': 'nfc-manager', 'allow': true, context: document}], runTests);

mercurial