|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 MARIONETTE_TIMEOUT = 60000; |
|
5 |
|
6 SpecialPowers.addPermission("mobileconnection", true, document); |
|
7 |
|
8 let connection = navigator.mozMobileConnections[0]; |
|
9 ok(connection instanceof MozMobileConnection, |
|
10 "connection is instanceof " + connection.constructor); |
|
11 |
|
12 function failedToSetRoamingPreference(mode, expectedErrorMessage, callback) { |
|
13 let request = connection.setRoamingPreference(mode); |
|
14 |
|
15 ok(request instanceof DOMRequest, |
|
16 "request instanceof " + request.constructor); |
|
17 |
|
18 request.onsuccess = function onsuccess() { |
|
19 ok(false, "Should not be here !!"); |
|
20 |
|
21 callback(); |
|
22 } |
|
23 |
|
24 request.onerror = function onerror() { |
|
25 is(request.error.name, expectedErrorMessage); |
|
26 |
|
27 callback(); |
|
28 } |
|
29 } |
|
30 |
|
31 function testSetRoamingPreferenceWithNullValue() { |
|
32 log("test setRoamingPreference(null)"); |
|
33 |
|
34 failedToSetRoamingPreference(null, "InvalidParameter", runNextTest); |
|
35 } |
|
36 |
|
37 function testSetRoamingPreferenceWithInvalidValue() { |
|
38 log("test setRoamingPreference(\"InvalidValue\")"); |
|
39 |
|
40 failedToSetRoamingPreference("InvalidValue", "InvalidParameter", runNextTest); |
|
41 } |
|
42 |
|
43 function testSetRoamingPreferenceToHome() { |
|
44 log("test setRoamingPreference(\"home\")"); |
|
45 |
|
46 // TODO: Bug 896394. |
|
47 // Currently emulator run as GSM mode by default. So we expect to get a |
|
48 // 'RequestNotSupported' error here. |
|
49 failedToSetRoamingPreference("home", "RequestNotSupported", runNextTest); |
|
50 } |
|
51 |
|
52 function testGetRoamingPreference() { |
|
53 log("test getRoamingPreference()"); |
|
54 |
|
55 // TODO: Bug 896394. |
|
56 // Currently emulator run as GSM mode by default. So we expect to get a |
|
57 // 'RequestNotSupported' error here. |
|
58 let request = connection.getRoamingPreference(); |
|
59 |
|
60 ok(request instanceof DOMRequest, |
|
61 "request instanceof " + request.constructor); |
|
62 |
|
63 request.onsuccess = function onsuccess() { |
|
64 ok(false, "Should not be here !!"); |
|
65 |
|
66 runNextTest(); |
|
67 } |
|
68 |
|
69 request.onerror = function onerror() { |
|
70 is(request.error.name, "RequestNotSupported"); |
|
71 |
|
72 runNextTest(); |
|
73 } |
|
74 } |
|
75 |
|
76 let tests = [ |
|
77 testSetRoamingPreferenceWithNullValue, |
|
78 testSetRoamingPreferenceWithInvalidValue, |
|
79 testSetRoamingPreferenceToHome, |
|
80 testGetRoamingPreference |
|
81 ]; |
|
82 |
|
83 function runNextTest() { |
|
84 let test = tests.shift(); |
|
85 if (!test) { |
|
86 cleanUp(); |
|
87 return; |
|
88 } |
|
89 |
|
90 test(); |
|
91 } |
|
92 |
|
93 function cleanUp() { |
|
94 SpecialPowers.removePermission("mobileconnection", document); |
|
95 finish(); |
|
96 } |
|
97 |
|
98 runNextTest(); |