1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/icc/tests/marionette/test_icc_card_state.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,49 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +MARIONETTE_TIMEOUT = 30000; 1.8 +MARIONETTE_HEAD_JS = "icc_header.js"; 1.9 + 1.10 +function setRadioEnabled(enabled) { 1.11 + let connection = navigator.mozMobileConnections[0]; 1.12 + ok(connection); 1.13 + 1.14 + let request = connection.setRadioEnabled(enabled); 1.15 + 1.16 + request.onsuccess = function onsuccess() { 1.17 + log('setRadioEnabled: ' + enabled); 1.18 + }; 1.19 + 1.20 + request.onerror = function onerror() { 1.21 + ok(false, "setRadioEnabled should be ok"); 1.22 + }; 1.23 +} 1.24 + 1.25 +/* Basic test */ 1.26 +taskHelper.push(function basicTest() { 1.27 + is(icc.cardState, "ready", "card state is " + icc.cardState); 1.28 + taskHelper.runNext(); 1.29 +}); 1.30 + 1.31 +/* Test cardstatechange event by switching radio off */ 1.32 +taskHelper.push(function testCardStateChange() { 1.33 + // Turn off radio. 1.34 + setRadioEnabled(false); 1.35 + icc.addEventListener("cardstatechange", function oncardstatechange() { 1.36 + log("card state changes to " + icc.cardState); 1.37 + // Expect to get card state changing to null. 1.38 + if (icc.cardState === null) { 1.39 + icc.removeEventListener("cardstatechange", oncardstatechange); 1.40 + // We should restore radio status and expect to get iccdetected event. 1.41 + setRadioEnabled(true); 1.42 + iccManager.addEventListener("iccdetected", function oniccdetected(evt) { 1.43 + log("icc iccdetected: " + evt.iccId); 1.44 + iccManager.removeEventListener("iccdetected", oniccdetected); 1.45 + taskHelper.runNext(); 1.46 + }); 1.47 + } 1.48 + }); 1.49 +}); 1.50 + 1.51 +// Start test 1.52 +taskHelper.runNext();