|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 SpecialPowers.addPermission("mobileconnection", true, document); |
|
5 |
|
6 // In single sim scenario, there is only one mobileConnection, we can always use |
|
7 // the first instance. |
|
8 let mobileConnection = window.navigator.mozMobileConnections[0]; |
|
9 ok(mobileConnection instanceof MozMobileConnection, |
|
10 "mobileConnection is instanceof " + mobileConnection.constructor); |
|
11 |
|
12 let _pendingEmulatorCmdCount = 0; |
|
13 |
|
14 /* Remove permission and execute finish() */ |
|
15 let cleanUp = function() { |
|
16 waitFor(function() { |
|
17 SpecialPowers.removePermission("mobileconnection", document); |
|
18 finish(); |
|
19 }, function() { |
|
20 return _pendingEmulatorCmdCount === 0; |
|
21 }); |
|
22 }; |
|
23 |
|
24 /* Helper for tasks */ |
|
25 let taskHelper = { |
|
26 tasks: [], |
|
27 |
|
28 push: function(task) { |
|
29 this.tasks.push(task); |
|
30 }, |
|
31 |
|
32 runNext: function() { |
|
33 let task = this.tasks.shift(); |
|
34 if (!task) { |
|
35 cleanUp(); |
|
36 return; |
|
37 } |
|
38 |
|
39 if (typeof task === "function") { |
|
40 task(); |
|
41 } |
|
42 }, |
|
43 }; |
|
44 |
|
45 /* Helper for emulator console command */ |
|
46 let emulatorHelper = { |
|
47 sendCommand: function(cmd, callback) { |
|
48 _pendingEmulatorCmdCount++; |
|
49 runEmulatorCmd(cmd, function(results) { |
|
50 _pendingEmulatorCmdCount--; |
|
51 |
|
52 let result = results[results.length - 1]; |
|
53 is(result, "OK", "'"+ cmd +"' returns '" + result + "'"); |
|
54 |
|
55 if (callback && typeof callback === "function") { |
|
56 callback(results); |
|
57 } |
|
58 }); |
|
59 }, |
|
60 }; |