2012-08-07 12:11:48 -07:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
2012-06-01 14:10:39 -07:00
|
|
|
|
|
|
|
// getNetworks() can take some time..
|
2012-06-19 15:52:06 -07:00
|
|
|
MARIONETTE_TIMEOUT = 60000;
|
2012-06-01 14:10:39 -07:00
|
|
|
|
2012-08-16 17:42:26 -07:00
|
|
|
SpecialPowers.addPermission("mobileconnection", true, document);
|
2012-06-01 14:10:39 -07:00
|
|
|
|
2012-06-12 14:05:50 -07:00
|
|
|
let connection = navigator.mozMobileConnection;
|
|
|
|
ok(connection instanceof MozMobileConnection,
|
|
|
|
"connection is instanceof " + connection.constructor);
|
|
|
|
|
2012-06-19 15:52:06 -07:00
|
|
|
is(connection.networkSelectionMode, "automatic");
|
|
|
|
|
|
|
|
let androidNetwork = null;
|
|
|
|
let telkilaNetwork = null;
|
|
|
|
|
2012-06-12 14:05:50 -07:00
|
|
|
function isAndroidNetwork(network) {
|
|
|
|
is(network.longName, "Android");
|
|
|
|
is(network.shortName, "Android");
|
|
|
|
is(network.mcc, 310);
|
|
|
|
is(network.mnc, 260);
|
|
|
|
}
|
|
|
|
|
2012-06-19 15:52:06 -07:00
|
|
|
function isTelkilaNetwork(network) {
|
|
|
|
is(network.longName, "TelKila");
|
|
|
|
is(network.shortName, "TelKila");
|
|
|
|
is(network.mcc, 310);
|
|
|
|
is(network.mnc, 295);
|
|
|
|
}
|
|
|
|
|
2012-06-12 14:05:50 -07:00
|
|
|
function testConnectionInfo() {
|
|
|
|
let voice = connection.voice;
|
|
|
|
is(voice.connected, true);
|
2012-08-07 12:11:48 -07:00
|
|
|
is(voice.state, "registered");
|
2012-06-12 14:05:50 -07:00
|
|
|
is(voice.emergencyCallsOnly, false);
|
|
|
|
is(voice.roaming, false);
|
|
|
|
isAndroidNetwork(voice.network);
|
|
|
|
|
|
|
|
let data = connection.data;
|
2012-08-07 12:11:48 -07:00
|
|
|
// data.connected = true means there's an active data call which we
|
|
|
|
// can't predict here.
|
|
|
|
is(data.state, "registered");
|
|
|
|
is(data.emergencyCallsOnly, false);
|
|
|
|
is(data.roaming, false);
|
2012-06-12 14:05:50 -07:00
|
|
|
isAndroidNetwork(data.network);
|
|
|
|
|
|
|
|
testGetNetworks();
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetNetworks() {
|
|
|
|
let request = connection.getNetworks();
|
|
|
|
ok(request instanceof DOMRequest,
|
2012-06-19 15:52:06 -07:00
|
|
|
"request is instanceof " + request.constructor);
|
2012-06-12 14:05:50 -07:00
|
|
|
|
|
|
|
request.onerror = function() {
|
|
|
|
ok(false, request.error);
|
2012-06-19 15:52:06 -07:00
|
|
|
setTimeout(testSelectNetwork, 0);
|
2012-06-12 14:05:50 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
request.onsuccess = function() {
|
|
|
|
ok('result' in request, "Request did not contain a result");
|
|
|
|
let networks = request.result;
|
|
|
|
|
|
|
|
// The emulator RIL server should always return 2 networks:
|
|
|
|
// {"longName":"Android","shortName":"Android","mcc":310,"mnc":260,"state":"available"}
|
|
|
|
// {"longName":"TelKila","shortName":"TelKila","mcc":310,"mnc":295,"state":"available"}
|
|
|
|
is(networks.length, 2);
|
|
|
|
|
2012-06-19 15:52:06 -07:00
|
|
|
let network1 = androidNetwork = networks[0];
|
2012-06-12 14:05:50 -07:00
|
|
|
isAndroidNetwork(network1);
|
|
|
|
is(network1.state, "available");
|
|
|
|
|
2012-06-19 15:52:06 -07:00
|
|
|
let network2 = telkilaNetwork = networks[1];
|
|
|
|
isTelkilaNetwork(network2);
|
2012-06-12 14:05:50 -07:00
|
|
|
is(network2.state, "available");
|
2012-06-19 15:52:06 -07:00
|
|
|
|
|
|
|
setTimeout(testSelectNetwork, 0);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSelectNetwork() {
|
|
|
|
let request = connection.selectNetwork(telkilaNetwork);
|
|
|
|
ok(request instanceof DOMRequest,
|
|
|
|
"request instanceof " + request.constructor);
|
|
|
|
|
|
|
|
connection.addEventListener("voicechange", function voiceChange() {
|
|
|
|
connection.removeEventListener("voicechange", voiceChange);
|
|
|
|
|
|
|
|
isTelkilaNetwork(connection.voice.network);
|
|
|
|
setTimeout(testSelectNetworkAutomatically, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
request.onsuccess = function() {
|
|
|
|
is(connection.networkSelectionMode, "manual",
|
|
|
|
"selectNetwork sets mode to: " + connection.networkSelectionMode);
|
|
|
|
};
|
|
|
|
|
|
|
|
request.onerror = function() {
|
|
|
|
ok(false, request.error);
|
|
|
|
setTimeout(testSelectNetworkAutomatically, 0);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSelectNetworkAutomatically() {
|
|
|
|
let request = connection.selectNetworkAutomatically();
|
|
|
|
ok(request instanceof DOMRequest,
|
|
|
|
"request instanceof " + request.constructor);
|
|
|
|
|
|
|
|
connection.addEventListener("voicechange", function voiceChange() {
|
|
|
|
connection.removeEventListener("voicechange", voiceChange);
|
|
|
|
|
|
|
|
isAndroidNetwork(connection.voice.network);
|
|
|
|
setTimeout(testSelectNetworkErrors, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
request.onsuccess = function() {
|
|
|
|
is(connection.networkSelectionMode, "automatic",
|
|
|
|
"selectNetworkAutomatically sets mode to: " +
|
|
|
|
connection.networkSelectionMode);
|
|
|
|
};
|
|
|
|
|
|
|
|
request.onerror = function() {
|
|
|
|
ok(false, request.error);
|
|
|
|
setTimeout(testSelectNetworkErrors, 0);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function throwsException(fn) {
|
|
|
|
try {
|
|
|
|
fn();
|
|
|
|
ok(false, "function did not throw an exception: " + fn);
|
|
|
|
} catch (e) {
|
|
|
|
ok(true, "function succesfully caught exception: " + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSelectNetworkErrors() {
|
|
|
|
throwsException(function() {
|
|
|
|
connection.selectNetwork(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
throwsException(function() {
|
|
|
|
connection.selectNetwork({});
|
|
|
|
});
|
|
|
|
|
|
|
|
connection.addEventListener("voicechange", function voiceChange() {
|
|
|
|
connection.removeEventListener("voicechange", voiceChange);
|
|
|
|
setTimeout(testSelectExistingNetworkManual, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
let request1 = connection.selectNetwork(telkilaNetwork);
|
|
|
|
request1.onerror = function() {
|
|
|
|
ok(false, request.error);
|
|
|
|
setTimeout(testSelectExistingNetworkManual, 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
// attempt to selectNetwork while one request has already been sent
|
|
|
|
throwsException(function() {
|
|
|
|
connection.selectNetwork(androidNetwork);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSelectExistingNetworkManual() {
|
|
|
|
// When the current network is selected again, the DOMRequest's onsuccess
|
|
|
|
// should be called, but the network shouldn't actually change
|
|
|
|
|
|
|
|
// Telkila should be the currently selected network
|
|
|
|
log("Selecting TelKila (should already be selected");
|
|
|
|
let request = connection.selectNetwork(telkilaNetwork);
|
|
|
|
|
|
|
|
let voiceChanged = false;
|
|
|
|
connection.addEventListener("voicechange", function voiceChange() {
|
|
|
|
connection.removeEventListener("voicechange", voiceChange);
|
|
|
|
voiceChanged = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
function nextTest() {
|
|
|
|
// Switch back to automatic selection to setup the next test
|
|
|
|
let autoRequest = connection.selectNetworkAutomatically();
|
|
|
|
autoRequest.onsuccess = function() {
|
|
|
|
setTimeout(testSelectExistingNetworkAuto, 0);
|
|
|
|
};
|
|
|
|
autoRequest.onerror = function() {
|
|
|
|
ok(false, autoRequest.error);
|
|
|
|
cleanUp();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
request.onsuccess = function() {
|
|
|
|
// Give the voicechange event another opportunity to fire
|
|
|
|
setTimeout(function() {
|
|
|
|
is(voiceChanged, false,
|
|
|
|
"voiceNetwork changed while manually selecting Telkila network? " +
|
|
|
|
voiceChanged);
|
|
|
|
nextTest();
|
|
|
|
}, 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
request.onerror = function() {
|
|
|
|
ok(false, request.error);
|
|
|
|
nextTest();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSelectExistingNetworkAuto() {
|
|
|
|
// Now try the same thing but using automatic selection
|
|
|
|
log("Selecting automatically (should already be auto)");
|
|
|
|
let request = connection.selectNetworkAutomatically();
|
|
|
|
|
|
|
|
let voiceChanged = false;
|
|
|
|
connection.addEventListener("voicechange", function voiceChange() {
|
|
|
|
connection.removeEventListener("voicechange", voiceChange);
|
|
|
|
voiceChanged = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
request.onsuccess = function() {
|
|
|
|
// Give the voicechange event another opportunity to fire
|
|
|
|
setTimeout(function() {
|
|
|
|
is(voiceChanged, false,
|
|
|
|
"voiceNetwork changed while automatically selecting network? " +
|
|
|
|
voiceChanged);
|
|
|
|
cleanUp();
|
|
|
|
}, 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
request.onerror = function() {
|
|
|
|
ok(false, request.error);
|
2012-06-12 14:05:50 -07:00
|
|
|
cleanUp();
|
|
|
|
};
|
|
|
|
}
|
2012-06-01 14:10:39 -07:00
|
|
|
|
|
|
|
function cleanUp() {
|
2012-08-16 17:42:26 -07:00
|
|
|
SpecialPowers.removePermission("mobileconnection", document);
|
2012-06-01 14:10:39 -07:00
|
|
|
finish();
|
|
|
|
}
|
2012-06-12 14:05:50 -07:00
|
|
|
|
|
|
|
testConnectionInfo();
|