|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 MARIONETTE_TIMEOUT = 30000; |
|
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 ok(connection instanceof ifr.contentWindow.MozMobileConnection, |
|
15 "connection is instanceof " + connection.constructor); |
|
16 |
|
17 // The emulator's hard coded iccid value. |
|
18 // See it here {B2G_HOME}/external/qemu/telephony/sim_card.c. |
|
19 is(connection.iccId, 89014103211118510720); |
|
20 |
|
21 runNextTest(); |
|
22 }; |
|
23 document.body.appendChild(ifr); |
|
24 |
|
25 function waitForIccChange(callback) { |
|
26 connection.addEventListener("iccchange", function handler() { |
|
27 connection.removeEventListener("iccchange", handler); |
|
28 callback(); |
|
29 }); |
|
30 } |
|
31 |
|
32 function setRadioEnabled(enabled) { |
|
33 let request = connection.setRadioEnabled(enabled); |
|
34 |
|
35 request.onsuccess = function onsuccess() { |
|
36 log('setRadioEnabled: ' + enabled); |
|
37 }; |
|
38 |
|
39 request.onerror = function onerror() { |
|
40 ok(false, "setRadioEnabled should be ok"); |
|
41 }; |
|
42 } |
|
43 |
|
44 function testIccChangeOnRadioPowerOff() { |
|
45 // Turn off radio |
|
46 setRadioEnabled(false); |
|
47 |
|
48 waitForIccChange(function() { |
|
49 is(connection.iccId, null); |
|
50 runNextTest(); |
|
51 }); |
|
52 } |
|
53 |
|
54 function testIccChangeOnRadioPowerOn() { |
|
55 // Turn on radio |
|
56 setRadioEnabled(true); |
|
57 |
|
58 waitForIccChange(function() { |
|
59 // The emulator's hard coded iccid value. |
|
60 is(connection.iccId, 89014103211118510720); |
|
61 runNextTest(); |
|
62 }); |
|
63 } |
|
64 |
|
65 let tests = [ |
|
66 testIccChangeOnRadioPowerOff, |
|
67 testIccChangeOnRadioPowerOn |
|
68 ]; |
|
69 |
|
70 function runNextTest() { |
|
71 let test = tests.shift(); |
|
72 if (!test) { |
|
73 cleanUp(); |
|
74 return; |
|
75 } |
|
76 |
|
77 test(); |
|
78 } |
|
79 |
|
80 function cleanUp() { |
|
81 SpecialPowers.removePermission("mobileconnection", document); |
|
82 |
|
83 finish(); |
|
84 } |