|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 MARIONETTE_TIMEOUT = 30000; |
|
5 MARIONETTE_HEAD_JS = 'head.js'; |
|
6 |
|
7 let Promise = |
|
8 SpecialPowers.Cu.import("resource://gre/modules/Promise.jsm").Promise; |
|
9 |
|
10 // See nfc-nci.h. |
|
11 const NCI_LAST_NOTIFICATION = 0; |
|
12 const NCI_LIMIT_NOTIFICATION = 1; |
|
13 const NCI_MORE_NOTIFICATIONS = 2; |
|
14 |
|
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 } |
|
21 |
|
22 function activateRE(re) { |
|
23 let deferred = Promise.defer(); |
|
24 let cmd = 'nfc ntf rf_intf_activated ' + re; |
|
25 |
|
26 emulator.run(cmd, function(result) { |
|
27 is(result.pop(), 'OK', 'check activation of RE0'); |
|
28 deferred.resolve(); |
|
29 }); |
|
30 |
|
31 return deferred.promise; |
|
32 } |
|
33 |
|
34 function notifyDiscoverRE(re, type) { |
|
35 let deferred = Promise.defer(); |
|
36 let cmd = 'nfc ntf rf_discover ' + re + ' ' + type; |
|
37 |
|
38 emulator.run(cmd, function(result) { |
|
39 is(result.pop(), 'OK', 'check discover of RE' + re); |
|
40 deferred.resolve(); |
|
41 }); |
|
42 |
|
43 return deferred.promise; |
|
44 } |
|
45 |
|
46 function testActivateRE0() { |
|
47 log('Running \'testActivateRE0\''); |
|
48 window.navigator.mozSetMessageHandler( |
|
49 'nfc-manager-tech-discovered', handleTechnologyDiscoveredRE0); |
|
50 |
|
51 toggleNFC(true, function() { |
|
52 activateRE(0); |
|
53 }); |
|
54 } |
|
55 |
|
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); |
|
62 |
|
63 toggleNFC(true, function() { |
|
64 notifyDiscoverRE(0, NCI_MORE_NOTIFICATIONS) |
|
65 .then(() => notifyDiscoverRE(1, NCI_LAST_NOTIFICATION)) |
|
66 .then(() => activateRE(0)); |
|
67 }); |
|
68 } |
|
69 |
|
70 let tests = [ |
|
71 testActivateRE0, |
|
72 testRfDiscover |
|
73 ]; |
|
74 |
|
75 SpecialPowers.pushPermissions( |
|
76 [{'type': 'nfc-manager', 'allow': true, context: document}], runTests); |