|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 MARIONETTE_TIMEOUT = 30000; |
|
5 MARIONETTE_HEAD_JS = "icc_header.js"; |
|
6 |
|
7 function setRadioEnabled(enabled) { |
|
8 let connection = navigator.mozMobileConnections[0]; |
|
9 ok(connection); |
|
10 |
|
11 let request = connection.setRadioEnabled(enabled); |
|
12 |
|
13 request.onsuccess = function onsuccess() { |
|
14 log('setRadioEnabled: ' + enabled); |
|
15 }; |
|
16 |
|
17 request.onerror = function onerror() { |
|
18 ok(false, "setRadioEnabled should be ok"); |
|
19 }; |
|
20 } |
|
21 |
|
22 /* Basic test */ |
|
23 taskHelper.push(function basicTest() { |
|
24 is(icc.cardState, "ready", "card state is " + icc.cardState); |
|
25 taskHelper.runNext(); |
|
26 }); |
|
27 |
|
28 /* Test cardstatechange event by switching radio off */ |
|
29 taskHelper.push(function testCardStateChange() { |
|
30 // Turn off radio. |
|
31 setRadioEnabled(false); |
|
32 icc.addEventListener("cardstatechange", function oncardstatechange() { |
|
33 log("card state changes to " + icc.cardState); |
|
34 // Expect to get card state changing to null. |
|
35 if (icc.cardState === null) { |
|
36 icc.removeEventListener("cardstatechange", oncardstatechange); |
|
37 // We should restore radio status and expect to get iccdetected event. |
|
38 setRadioEnabled(true); |
|
39 iccManager.addEventListener("iccdetected", function oniccdetected(evt) { |
|
40 log("icc iccdetected: " + evt.iccId); |
|
41 iccManager.removeEventListener("iccdetected", oniccdetected); |
|
42 taskHelper.runNext(); |
|
43 }); |
|
44 } |
|
45 }); |
|
46 }); |
|
47 |
|
48 // Start test |
|
49 taskHelper.runNext(); |