1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/nfc/tests/marionette/test_nfc_manager_tech_discovered.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +MARIONETTE_TIMEOUT = 30000; 1.8 +MARIONETTE_HEAD_JS = 'head.js'; 1.9 + 1.10 +let Promise = 1.11 + SpecialPowers.Cu.import("resource://gre/modules/Promise.jsm").Promise; 1.12 + 1.13 +// See nfc-nci.h. 1.14 +const NCI_LAST_NOTIFICATION = 0; 1.15 +const NCI_LIMIT_NOTIFICATION = 1; 1.16 +const NCI_MORE_NOTIFICATIONS = 2; 1.17 + 1.18 +function handleTechnologyDiscoveredRE0(msg) { 1.19 + log('Received \'nfc-manager-tech-discovered\''); 1.20 + is(msg.type, 'techDiscovered', 'check for correct message type'); 1.21 + is(msg.techList[0], 'P2P', 'check for correct tech type'); 1.22 + toggleNFC(false, runNextTest); 1.23 +} 1.24 + 1.25 +function activateRE(re) { 1.26 + let deferred = Promise.defer(); 1.27 + let cmd = 'nfc ntf rf_intf_activated ' + re; 1.28 + 1.29 + emulator.run(cmd, function(result) { 1.30 + is(result.pop(), 'OK', 'check activation of RE0'); 1.31 + deferred.resolve(); 1.32 + }); 1.33 + 1.34 + return deferred.promise; 1.35 +} 1.36 + 1.37 +function notifyDiscoverRE(re, type) { 1.38 + let deferred = Promise.defer(); 1.39 + let cmd = 'nfc ntf rf_discover ' + re + ' ' + type; 1.40 + 1.41 + emulator.run(cmd, function(result) { 1.42 + is(result.pop(), 'OK', 'check discover of RE' + re); 1.43 + deferred.resolve(); 1.44 + }); 1.45 + 1.46 + return deferred.promise; 1.47 +} 1.48 + 1.49 +function testActivateRE0() { 1.50 + log('Running \'testActivateRE0\''); 1.51 + window.navigator.mozSetMessageHandler( 1.52 + 'nfc-manager-tech-discovered', handleTechnologyDiscoveredRE0); 1.53 + 1.54 + toggleNFC(true, function() { 1.55 + activateRE(0); 1.56 + }); 1.57 +} 1.58 + 1.59 +// Check NCI Spec 5.2, this will change NCI state from 1.60 +// DISCOVERY -> W4_ALL_DISCOVERIES -> W4_HOST_SELECT -> POLL_ACTIVE 1.61 +function testRfDiscover() { 1.62 + log('Running \'testRfDiscover\''); 1.63 + window.navigator.mozSetMessageHandler( 1.64 + 'nfc-manager-tech-discovered', handleTechnologyDiscoveredRE0); 1.65 + 1.66 + toggleNFC(true, function() { 1.67 + notifyDiscoverRE(0, NCI_MORE_NOTIFICATIONS) 1.68 + .then(() => notifyDiscoverRE(1, NCI_LAST_NOTIFICATION)) 1.69 + .then(() => activateRE(0)); 1.70 + }); 1.71 +} 1.72 + 1.73 +let tests = [ 1.74 + testActivateRE0, 1.75 + testRfDiscover 1.76 +]; 1.77 + 1.78 +SpecialPowers.pushPermissions( 1.79 + [{'type': 'nfc-manager', 'allow': true, context: document}], runTests);