|
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 // 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 connection; |
|
12 ifr.onload = function() { |
|
13 connection = ifr.contentWindow.navigator.mozMobileConnections[0]; |
|
14 |
|
15 ok(connection instanceof ifr.contentWindow.MozMobileConnection, |
|
16 "connection is instanceof " + connection.constructor); |
|
17 |
|
18 nextTest(); |
|
19 }; |
|
20 document.body.appendChild(ifr); |
|
21 |
|
22 let caseId = 0; |
|
23 let options = [ |
|
24 buildOption(5, true, '0000', 0), // invalid program. |
|
25 |
|
26 // test null. |
|
27 buildOption(null, true, '0000', 0), |
|
28 buildOption(0, null, '0000', 0), |
|
29 buildOption(0, true, null, 0), |
|
30 buildOption(0, true, '0000', null), |
|
31 |
|
32 // test undefined. |
|
33 {'enabled': true, 'password': '0000', 'serviceClass': 0}, |
|
34 {'program': 0, 'password': '0000', 'serviceClass': 0}, |
|
35 {'program': 0, 'enabled': true, 'serviceClass': 0}, |
|
36 {'program': 0, 'enabled': true, 'password': '0000'}, |
|
37 ]; |
|
38 |
|
39 function buildOption(program, enabled, password, serviceClass) { |
|
40 return { |
|
41 'program': program, |
|
42 'enabled': enabled, |
|
43 'password': password, |
|
44 'serviceClass': serviceClass |
|
45 }; |
|
46 } |
|
47 |
|
48 function testSetCallBarringOptionError(option) { |
|
49 let request = connection.setCallBarringOption(option); |
|
50 request.onsuccess = function() { |
|
51 ok(false, |
|
52 'should not fire onsuccess for invaild call barring option: ' |
|
53 + JSON.stringify(option)); |
|
54 }; |
|
55 request.onerror = function(event) { |
|
56 is(event.target.error.name, 'InvalidParameter', JSON.stringify(option)); |
|
57 nextTest(); |
|
58 }; |
|
59 } |
|
60 |
|
61 function nextTest() { |
|
62 if (caseId >= options.length) { |
|
63 cleanUp(); |
|
64 } else { |
|
65 let option = options[caseId++]; |
|
66 log('test for ' + JSON.stringify(option)); |
|
67 testSetCallBarringOptionError(option); |
|
68 } |
|
69 } |
|
70 |
|
71 function cleanUp() { |
|
72 SpecialPowers.removePermission("mobileconnection", document); |
|
73 finish(); |
|
74 } |