michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: MARIONETTE_TIMEOUT = 30000; michael@0: michael@0: SpecialPowers.addPermission("mobileconnection", true, document); michael@0: michael@0: // Permission changes can't change existing Navigator.prototype michael@0: // objects, so grab our objects from a new Navigator michael@0: let ifr = document.createElement("iframe"); michael@0: let connection; michael@0: ifr.onload = function() { michael@0: connection = ifr.contentWindow.navigator.mozMobileConnections[0]; michael@0: ok(connection instanceof ifr.contentWindow.MozMobileConnection, michael@0: "connection is instanceof " + connection.constructor); michael@0: michael@0: // The emulator's hard coded iccid value. michael@0: // See it here {B2G_HOME}/external/qemu/telephony/sim_card.c. michael@0: is(connection.iccId, 89014103211118510720); michael@0: michael@0: runNextTest(); michael@0: }; michael@0: document.body.appendChild(ifr); michael@0: michael@0: function waitForIccChange(callback) { michael@0: connection.addEventListener("iccchange", function handler() { michael@0: connection.removeEventListener("iccchange", handler); michael@0: callback(); michael@0: }); michael@0: } michael@0: michael@0: function setRadioEnabled(enabled) { michael@0: let request = connection.setRadioEnabled(enabled); michael@0: michael@0: request.onsuccess = function onsuccess() { michael@0: log('setRadioEnabled: ' + enabled); michael@0: }; michael@0: michael@0: request.onerror = function onerror() { michael@0: ok(false, "setRadioEnabled should be ok"); michael@0: }; michael@0: } michael@0: michael@0: function testIccChangeOnRadioPowerOff() { michael@0: // Turn off radio michael@0: setRadioEnabled(false); michael@0: michael@0: waitForIccChange(function() { michael@0: is(connection.iccId, null); michael@0: runNextTest(); michael@0: }); michael@0: } michael@0: michael@0: function testIccChangeOnRadioPowerOn() { michael@0: // Turn on radio michael@0: setRadioEnabled(true); michael@0: michael@0: waitForIccChange(function() { michael@0: // The emulator's hard coded iccid value. michael@0: is(connection.iccId, 89014103211118510720); michael@0: runNextTest(); michael@0: }); michael@0: } michael@0: michael@0: let tests = [ michael@0: testIccChangeOnRadioPowerOff, michael@0: testIccChangeOnRadioPowerOn michael@0: ]; michael@0: michael@0: function runNextTest() { michael@0: let test = tests.shift(); michael@0: if (!test) { michael@0: cleanUp(); michael@0: return; michael@0: } michael@0: michael@0: test(); michael@0: } michael@0: michael@0: function cleanUp() { michael@0: SpecialPowers.removePermission("mobileconnection", document); michael@0: michael@0: finish(); michael@0: }