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 let pendingEmulatorCmdCount = 0;
6 SpecialPowers.addPermission("nfc-manager", true, document);
8 /**
9 * Emulator helper.
10 */
11 let emulator = (function() {
12 let pendingCmdCount = 0;
13 let originalRunEmulatorCmd = runEmulatorCmd;
15 // Overwritten it so people could not call this function directly.
16 runEmulatorCmd = function() {
17 throw "Use emulator.run(cmd, callback) instead of runEmulatorCmd";
18 };
20 function run(cmd, callback) {
21 pendingCmdCount++;
22 originalRunEmulatorCmd(cmd, function(result) {
23 pendingCmdCount--;
24 if (callback && typeof callback === "function") {
25 callback(result);
26 }
27 });
28 }
30 return {
31 run: run
32 };
33 }());
35 function toggleNFC(enabled, callback) {
36 isnot(callback, null);
38 let nfc = window.navigator.mozNfc;
39 let req;
40 if (enabled) {
41 req = nfc.startPoll();
42 } else {
43 req = nfc.powerOff();
44 }
46 req.onsuccess = function() {
47 callback();
48 };
50 req.onerror = function() {
51 ok(false, 'operation failed, error ' + req.error.name);
52 finish();
53 };
54 }
56 function cleanUp() {
57 log('Cleaning up');
58 waitFor(function() {
59 SpecialPowers.removePermission("nfc-manager", document);
60 finish()
61 },
62 function() {
63 return pendingEmulatorCmdCount === 0;
64 });
65 }
67 function runNextTest() {
68 let test = tests.shift();
69 if (!test) {
70 cleanUp();
71 return;
72 }
73 test();
74 }
76 // run this function to start tests
77 function runTests() {
78 if ('mozNfc' in window.navigator) {
79 runNextTest();
80 } else {
81 // succeed immediately on systems without NFC
82 log('Skipping test on system without NFC');
83 ok(true, 'Skipping test on system without NFC');
84 finish();
85 }
86 }