dom/mobileconnection/tests/marionette/test_mobile_networks.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 // getNetworks() can take some time..
michael@0 5 MARIONETTE_TIMEOUT = 60000;
michael@0 6 MARIONETTE_HEAD_JS = "head.js";
michael@0 7
michael@0 8 function isHomeNetwork(network) {
michael@0 9 is(network.longName, "Android");
michael@0 10 is(network.shortName, "Android");
michael@0 11 is(network.mcc, "310");
michael@0 12 is(network.mnc, "260");
michael@0 13 }
michael@0 14
michael@0 15 function isRoamingNetwork(network) {
michael@0 16 is(network.longName, "TelKila");
michael@0 17 is(network.shortName, "TelKila");
michael@0 18 is(network.mcc, "310");
michael@0 19 is(network.mnc, "295");
michael@0 20 }
michael@0 21
michael@0 22 function testConnectionInfo() {
michael@0 23 log("Validate initial states");
michael@0 24 let voice = mobileConnection.voice;
michael@0 25 is(voice.connected, true);
michael@0 26 is(voice.state, "registered");
michael@0 27 is(voice.emergencyCallsOnly, false);
michael@0 28 is(voice.roaming, false);
michael@0 29 isHomeNetwork(voice.network);
michael@0 30
michael@0 31 let data = mobileConnection.data;
michael@0 32 // data.connected = true means there's an active data call which we
michael@0 33 // can't predict here.
michael@0 34 is(data.state, "registered");
michael@0 35 is(data.emergencyCallsOnly, false);
michael@0 36 is(data.roaming, false);
michael@0 37 isHomeNetwork(data.network);
michael@0 38 }
michael@0 39
michael@0 40 function testGetNetworks() {
michael@0 41 log("Enumerating available networks");
michael@0 42 return getNetworks()
michael@0 43 .then(function resolve(aNetworks) {
michael@0 44 // The emulator RIL server should always return 2 networks:
michael@0 45 // {"longName":"Android","shortName":"Android","mcc":310,"mnc":260,"state":"available"}
michael@0 46 // {"longName":"TelKila","shortName":"TelKila","mcc":310,"mnc":295,"state":"available"}
michael@0 47 is(aNetworks.length, 2);
michael@0 48
michael@0 49 let network1 = aNetworks[0];
michael@0 50 isHomeNetwork(network1);
michael@0 51 is(network1.state, "available");
michael@0 52
michael@0 53 let network2 = aNetworks[1];
michael@0 54 isRoamingNetwork(network2);
michael@0 55 is(network2.state, "available");
michael@0 56
michael@0 57 return aNetworks;
michael@0 58 });
michael@0 59 }
michael@0 60
michael@0 61 function testSelectNetwork(aNetwork, aValidator) {
michael@0 62 log("Selecting network '" + aNetwork.longName + "' manually");
michael@0 63 isnot(aNetwork.longName, mobileConnection.voice.network.longName,
michael@0 64 "aNetwork.longName");
michael@0 65
michael@0 66 return selectNetworkAndWait(aNetwork)
michael@0 67 .then(function() {
michael@0 68 is(mobileConnection.networkSelectionMode, "manual",
michael@0 69 "mobileConnection.networkSelectionMode");
michael@0 70 is(mobileConnection.voice.network.longName, aNetwork.longName,
michael@0 71 "mobileConnection.voice.network.longName");
michael@0 72
michael@0 73 aValidator(mobileConnection.voice.network);
michael@0 74 });
michael@0 75 }
michael@0 76
michael@0 77 function testSelectNetworkAutomatically(aHomeNetwork, aValidator) {
michael@0 78 log("Selecting network '" + aHomeNetwork.longName + "' automatically");
michael@0 79 isnot(aHomeNetwork.longName, mobileConnection.voice.network.longName,
michael@0 80 "aHomeNetwork.longName");
michael@0 81
michael@0 82 return selectNetworkAutomaticallyAndWait()
michael@0 83 .then(function() {
michael@0 84 is(mobileConnection.networkSelectionMode, "automatic",
michael@0 85 "mobileConnection.networkSelectionMode");
michael@0 86 is(mobileConnection.voice.network.longName, aHomeNetwork.longName,
michael@0 87 "mobileConnection.voice.network.longName");
michael@0 88
michael@0 89 aValidator(mobileConnection.voice.network);
michael@0 90 });
michael@0 91 }
michael@0 92
michael@0 93 function throwsException(fn) {
michael@0 94 try {
michael@0 95 fn();
michael@0 96 ok(false, "function did not throw an exception: " + fn);
michael@0 97 } catch (e) {
michael@0 98 ok(true, "function successfully caught exception: " + e);
michael@0 99 }
michael@0 100 }
michael@0 101
michael@0 102 function testSelectNetworkErrors(aNetworkToSelect, aAnotherNetwork) {
michael@0 103 throwsException(() => mobileConnection.selectNetwork(null));
michael@0 104 throwsException(() => mobileConnection.selectNetwork({}));
michael@0 105
michael@0 106 isnot(aNetworkToSelect.longName, mobileConnection.voice.network.longName,
michael@0 107 "aNetworkToSelect.longName");
michael@0 108 let promise = selectNetworkAndWait(aNetworkToSelect);
michael@0 109
michael@0 110 // attempt to selectNetwork while one request has already been sent
michael@0 111 throwsException(() => mobileConnection.selectNetwork(aAnotherNetwork));
michael@0 112
michael@0 113 return promise;
michael@0 114 }
michael@0 115
michael@0 116 function testSelectExistingNetworkManual(aNetwork) {
michael@0 117 // When the current network is selected again, the DOMRequest's onsuccess
michael@0 118 // should be called, but the network shouldn't actually change
michael@0 119
michael@0 120 log("Selecting '" + aNetwork.longName + "' manually (should already be selected)");
michael@0 121 is(aNetwork.longName, mobileConnection.voice.network.longName,
michael@0 122 "aNetwork.longName");
michael@0 123
michael@0 124 function voiceChange() {
michael@0 125 let network = mobileConnection.voice.network;
michael@0 126 if (network.longName !== aNetwork.longName) {
michael@0 127 ok(false, "voicechange event emitted while selecting existing '" +
michael@0 128 aNetwork.longName + "' manually");
michael@0 129 }
michael@0 130 }
michael@0 131
michael@0 132 mobileConnection.addEventListener("voicechange", voiceChange);
michael@0 133
michael@0 134 return selectNetwork(aNetwork)
michael@0 135 .then(function resolve() {
michael@0 136 let deferred = Promise.defer();
michael@0 137
michael@0 138 // Give the voicechange event another opportunity to fire
michael@0 139 setTimeout(function() {
michael@0 140 mobileConnection.removeEventListener("voicechange", voiceChange);
michael@0 141 deferred.resolve();
michael@0 142 }, 3000);
michael@0 143
michael@0 144 return deferred.promise;
michael@0 145 }, function reject() {
michael@0 146 mobileConnection.removeEventListener("voicechange", voiceChange);
michael@0 147 ok(false, "selectNetwork fails");
michael@0 148 });
michael@0 149 }
michael@0 150
michael@0 151 function testSelectExistingNetworkAuto(aHomeNetwork) {
michael@0 152 // Now try the same thing but using automatic selection
michael@0 153 log("Selecting '" + aHomeNetwork.longName + "' automatically (should already be selected)");
michael@0 154 is(aHomeNetwork.longName, mobileConnection.voice.network.longName,
michael@0 155 "aHomeNetwork.longName");
michael@0 156
michael@0 157 function voiceChange() {
michael@0 158 let network = mobileConnection.voice.network;
michael@0 159 if (network.longName !== aHomeNetwork.longName) {
michael@0 160 ok(false, "voicechange event emitted while selecting existing '" +
michael@0 161 aHomeNetwork.longName + "' automatically");
michael@0 162 }
michael@0 163 }
michael@0 164
michael@0 165 mobileConnection.addEventListener("voicechange", voiceChange);
michael@0 166
michael@0 167 return selectNetworkAutomatically()
michael@0 168 .then(function resolve() {
michael@0 169 let deferred = Promise.defer();
michael@0 170
michael@0 171 // Give the voicechange event another opportunity to fire
michael@0 172 setTimeout(function() {
michael@0 173 mobileConnection.removeEventListener("voicechange", voiceChange);
michael@0 174 deferred.resolve();
michael@0 175 }, 3000);
michael@0 176
michael@0 177 return deferred.promise;
michael@0 178 }, function reject() {
michael@0 179 mobileConnection.removeEventListener("voicechange", voiceChange);
michael@0 180 ok(false, "selectNetwork fails");
michael@0 181 });
michael@0 182 }
michael@0 183
michael@0 184 startTestCommon(function() {
michael@0 185 let promise = Promise.resolve();
michael@0 186 if (mobileConnection.networkSelectionMode != "automatic") {
michael@0 187 promise = promise.then(selectNetworkAutomatically);
michael@0 188 }
michael@0 189
michael@0 190 return promise
michael@0 191 .then(() => testConnectionInfo())
michael@0 192 .then(() => testGetNetworks())
michael@0 193 .then(function(aNetworks) {
michael@0 194 let homeNetwork = aNetworks[0],
michael@0 195 roamingNetwork = aNetworks[1];
michael@0 196
michael@0 197 // We're initially connected to home network, so let's connect to roaming
michael@0 198 // network first.
michael@0 199 return testSelectNetwork(roamingNetwork, isRoamingNetwork)
michael@0 200
michael@0 201 // Then connect back to home network automatically.
michael@0 202 .then(() => testSelectNetworkAutomatically(homeNetwork, isHomeNetwork))
michael@0 203
michael@0 204 // Then try connect to roaming network again.
michael@0 205 .then(() => testSelectNetworkErrors(roamingNetwork, homeNetwork))
michael@0 206
michael@0 207 // Roaming network should has been selected, try select it again.
michael@0 208 .then(() => testSelectExistingNetworkManual(roamingNetwork))
michael@0 209
michael@0 210 // Switch back to home network and try selecte it again.
michael@0 211 .then(() => selectNetworkAutomaticallyAndWait())
michael@0 212 .then(() => testSelectExistingNetworkAuto(homeNetwork));
michael@0 213 });
michael@0 214 });

mercurial