Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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);