dom/nfc/tests/marionette/test_nfc_manager_tech_discovered.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial