|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 MARIONETTE_TIMEOUT = 20000; |
|
5 |
|
6 SpecialPowers.addPermission("mobileconnection", true, document); |
|
7 |
|
8 // Permission changes can't change existing Navigator.prototype |
|
9 // objects, so grab our objects from a new Navigator |
|
10 let ifr = document.createElement("iframe"); |
|
11 let mobileConnection; |
|
12 ifr.onload = function() { |
|
13 mobileConnection = ifr.contentWindow.navigator.mozMobileConnections[0]; |
|
14 |
|
15 tasks.run(); |
|
16 }; |
|
17 document.body.appendChild(ifr); |
|
18 |
|
19 let tasks = { |
|
20 // List of test functions. Each of them should call |tasks.next()| when |
|
21 // completed or |tasks.abort()| to jump to the last one. |
|
22 _tasks: [], |
|
23 _nextTaskIndex: 0, |
|
24 |
|
25 push: function(func) { |
|
26 this._tasks.push(func); |
|
27 }, |
|
28 |
|
29 next: function() { |
|
30 let index = this._nextTaskIndex++; |
|
31 let task = this._tasks[index]; |
|
32 try { |
|
33 task(); |
|
34 } catch (ex) { |
|
35 ok(false, "test task[" + index + "] throws: " + ex); |
|
36 // Run last task as clean up if possible. |
|
37 if (index != this._tasks.length - 1) { |
|
38 this.abort(); |
|
39 } |
|
40 } |
|
41 }, |
|
42 |
|
43 abort: function() { |
|
44 this._tasks[this._tasks.length - 1](); |
|
45 }, |
|
46 |
|
47 run: function() { |
|
48 this.next(); |
|
49 } |
|
50 }; |
|
51 |
|
52 tasks.push(function verifyInitialState() { |
|
53 log("Verifying initial state."); |
|
54 |
|
55 ok(mobileConnection instanceof ifr.contentWindow.MozMobileConnection, |
|
56 "mobileConnection is instanceof " + mobileConnection.constructor); |
|
57 |
|
58 tasks.next(); |
|
59 }); |
|
60 |
|
61 tasks.push(function testGettingIMEI() { |
|
62 log("Test *#06# ..."); |
|
63 |
|
64 let request = mobileConnection.sendMMI("*#06#"); |
|
65 ok(request instanceof DOMRequest, |
|
66 "request is instanceof " + request.constructor); |
|
67 |
|
68 request.onsuccess = function onsuccess(event) { |
|
69 ok(true, "request success"); |
|
70 is(typeof event.target.result, "object", "typeof result object"); |
|
71 ok(event.target.result instanceof Object, "result instanceof Object"); |
|
72 is(event.target.result.statusMessage, "000000000000000", "Emulator IMEI"); |
|
73 is(event.target.result.serviceCode, "scImei", "Service code IMEI"); |
|
74 is(event.target.result.additionalInformation, undefined, |
|
75 "No additional information"); |
|
76 tasks.next(); |
|
77 } |
|
78 request.onerror = function onerror() { |
|
79 ok(false, "request should not error"); |
|
80 tasks.abort(); |
|
81 }; |
|
82 }); |
|
83 |
|
84 tasks.push(function testInvalidMMICode(){ |
|
85 log("Test invalid MMI code ..."); |
|
86 |
|
87 let request = mobileConnection.sendMMI("InvalidMMICode"); |
|
88 ok(request instanceof DOMRequest, |
|
89 "request is instanceof " + request.constructor); |
|
90 |
|
91 request.onsuccess = function onsuccess(event) { |
|
92 ok(false, "request should not success"); |
|
93 tasks.abort(); |
|
94 }; |
|
95 |
|
96 request.onerror = function onerror() { |
|
97 ok(true, "request error"); |
|
98 is(request.error.name, "emMmiError", "MMI error name"); |
|
99 tasks.next(); |
|
100 }; |
|
101 }); |
|
102 |
|
103 // WARNING: All tasks should be pushed before this!!! |
|
104 tasks.push(function cleanUp() { |
|
105 SpecialPowers.removePermission("mobileconnection", document); |
|
106 finish(); |
|
107 }); |