dom/mobileconnection/tests/marionette/test_mobile_icc_change.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial