From 6c73e17aa4a619300a393df7007f24aa05d45cd6 Mon Sep 17 00:00:00 2001 From: Vicamo Yang Date: Fri, 19 Oct 2012 00:55:41 +0800 Subject: [PATCH] Bug 797972 - Part 2/2: test cases, r=marshall_law --- .../marionette/test_mobile_operator_names.js | 116 ++++++++++++++++-- 1 file changed, 105 insertions(+), 11 deletions(-) diff --git a/dom/network/tests/marionette/test_mobile_operator_names.js b/dom/network/tests/marionette/test_mobile_operator_names.js index d1e810ad7d54..62c4075188b0 100644 --- a/dom/network/tests/marionette/test_mobile_operator_names.js +++ b/dom/network/tests/marionette/test_mobile_operator_names.js @@ -5,6 +5,9 @@ MARIONETTE_TIMEOUT = 60000; SpecialPowers.addPermission("mobileconnection", true, document); +const OPERATOR_HOME = 0; +const OPERATOR_ROAMING = 1; + let connection = navigator.mozMobileConnection; ok(connection instanceof MozMobileConnection, "connection is instanceof " + connection.constructor); @@ -16,15 +19,37 @@ let network = voice.network; ok(network, "voice network info valid"); let emulatorCmdPendingCount = 0; -function setEmulatorOperatorNames(longName, shortName) { +function sendEmulatorCommand(cmd, callback) { emulatorCmdPendingCount++; - - let cmd = "operator set 0 " + longName + "," + shortName; runEmulatorCmd(cmd, function (result) { emulatorCmdPendingCount--; + is(result[result.length - 1], "OK"); + + callback(result); + }); +} + +function setEmulatorOperatorNames(which, longName, shortName, callback) { + let cmd = "operator set " + which + " " + longName + "," + shortName; + sendEmulatorCommand(cmd, function (result) { let re = new RegExp("^" + longName + "," + shortName + ","); - ok(result[0].match(re), "Long/short name should be changed."); + ok(result[which].match(re), "Long/short name should be changed."); + + if (callback) { + window.setTimeout(callback, 0); + } + }); +} + +function setEmulatorRoaming(roaming, callback) { + let cmd = "gsm voice " + (roaming ? "roaming" : "home"); + sendEmulatorCommand(cmd, function (result) { + is(result[0], "OK"); + + if (callback) { + window.setTimeout(callback, 0); + } }); } @@ -33,23 +58,28 @@ function checkValidMccMnc() { is(network.mnc, 260, "network.mnc"); } +function waitForVoiceChange(callback) { + connection.addEventListener("voicechange", function onvoicechange() { + connection.removeEventListener("voicechange", onvoicechange); + callback(); + }); +} + function doTestMobileOperatorNames(longName, shortName, callback) { log("Testing '" + longName + "', '" + shortName + "':"); checkValidMccMnc(); - connection.addEventListener("voicechange", function onvoicechange() { - connection.removeEventListener("voicechange", onvoicechange); - + waitForVoiceChange(function () { is(network.longName, longName, "network.longName"); is(network.shortName, shortName, "network.shortName"); checkValidMccMnc(); - setTimeout(callback, 0); + window.setTimeout(callback, 0); }); - setEmulatorOperatorNames(longName, shortName); + setEmulatorOperatorNames(OPERATOR_HOME, longName, shortName); } function testMobileOperatorNames() { @@ -57,7 +87,69 @@ function testMobileOperatorNames() { doTestMobileOperatorNames("Mozilla", "", function () { doTestMobileOperatorNames("", "B2G", function () { doTestMobileOperatorNames("", "", function () { - doTestMobileOperatorNames("Android", "Android", cleanUp); + doTestMobileOperatorNames("Android", "Android", testRoamingCheck); + }); + }); + }); + }); +} + +// See bug 797972 - B2G RIL: False roaming situation +// +// Steps to test: +// 1. set roaming operator names +// 2. set emulator roaming +// 3. wait for onvoicechange event and test passing conditions +// 4. set emulator roaming back to false +// 5. wait for onvoicechange event again and callback +function doTestRoamingCheck(longName, shortName, callback) { + log("Testing roaming check '" + longName + "', '" + shortName + "':"); + + setEmulatorOperatorNames(OPERATOR_ROAMING, longName, shortName, + window.setTimeout.bind(window, function () { + let done = false; + function resetRoaming() { + if (!done) { + window.setTimeout(resetRoaming, 100); + return; + } + + waitForVoiceChange(callback); + setEmulatorRoaming(false); + } + + waitForVoiceChange(function () { + is(network.longName, longName, "network.longName"); + is(network.shortName, shortName, "network.shortName"); + is(voice.roaming, false, "voice.roaming"); + + resetRoaming(); + }); + + setEmulatorRoaming(true, function () { + done = true; + }); + }, 3000) // window.setTimeout.bind + ); // setEmulatorOperatorNames +} + +function testRoamingCheck() { + // If Either long name or short name of current registered operator matches + // SPN("Android"), then the `roaming` attribute should be set to false. + doTestRoamingCheck("Android", "Android", function () { + doTestRoamingCheck("Android", "android", function () { + doTestRoamingCheck("Android", "Xxx", function () { + doTestRoamingCheck("android", "Android", function () { + doTestRoamingCheck("android", "android", function () { + doTestRoamingCheck("android", "Xxx", function () { + doTestRoamingCheck("Xxx", "Android", function () { + doTestRoamingCheck("Xxx", "android", function () { + setEmulatorOperatorNames(OPERATOR_ROAMING, "TelKila", "TelKila", + window.setTimeout.bind(window, cleanUp, 3000)); + }); + }); + }); + }); }); }); }); @@ -74,4 +166,6 @@ function cleanUp() { finish(); } -testMobileOperatorNames(); +waitFor(testMobileOperatorNames, function () { + return voice.connected; +});