Bug 879793 - Update tests. r=clian

This commit is contained in:
Albert Crespell 2013-06-07 18:57:07 +02:00
parent 81847104db
commit d8f63cf21c
2 changed files with 23 additions and 16 deletions

View File

@ -10,7 +10,7 @@ const netStatsDb = new NetworkStatsDB(this);
function filterTimestamp(date) {
var sampleRate = netStatsDb.sampleRate;
var offset = date.getTimezoneOffset() * 60 * 1000;
return Math.floor((date.getTime() - offset) / sampleRate) * sampleRate + offset;
return Math.floor((date.getTime() - offset) / sampleRate) * sampleRate;
}
add_test(function test_sampleRate() {
@ -335,8 +335,8 @@ add_test(function test_find () {
var sampleRate = netStatsDb.sampleRate;
var start = Date.now();
var saveDate = filterTimestamp(new Date());
var end = start + (sampleRate * (samples - 1));
start -= sampleRate;
var end = new Date(start + (sampleRate * (samples - 1)));
start = new Date(start - sampleRate);
var stats = [];
for (var i = 0; i < samples; i++) {i
stats.push({connectionType: "wifi", timestamp: saveDate + (sampleRate * i),
@ -353,8 +353,8 @@ add_test(function test_find () {
netStatsDb.find(function (error, result) {
do_check_eq(error, null);
do_check_eq(result.connectionType, "wifi");
do_check_eq(result.start.getTime(), start);
do_check_eq(result.end.getTime(), end);
do_check_eq(result.start.getTime(), start.getTime());
do_check_eq(result.end.getTime(), end.getTime());
do_check_eq(result.data.length, samples + 1);
do_check_eq(result.data[0].rxBytes, null);
do_check_eq(result.data[1].rxBytes, 0);
@ -363,8 +363,8 @@ add_test(function test_find () {
netStatsDb.findAll(function (error, result) {
do_check_eq(error, null);
do_check_eq(result.connectionType, null);
do_check_eq(result.start.getTime(), start);
do_check_eq(result.end.getTime(), end);
do_check_eq(result.start.getTime(), start.getTime());
do_check_eq(result.end.getTime(), end.getTime());
do_check_eq(result.data.length, samples + 1);
do_check_eq(result.data[0].rxBytes, null);
do_check_eq(result.data[1].rxBytes, 0);

View File

@ -15,14 +15,14 @@ add_test(function test_networkStatsAvailable_ok() {
NetworkStatsService.networkStatsAvailable(function (success, msg) {
do_check_eq(success, true);
run_next_test();
}, true, Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, 1234, 4321, new Date());
}, Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, true, 1234, 4321, new Date());
});
add_test(function test_networkStatsAvailable_failure() {
NetworkStatsService.networkStatsAvailable(function (success, msg) {
do_check_eq(success, false);
run_next_test();
}, false, Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, 1234, 4321, new Date());
}, Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, false, 1234, 4321, new Date());
});
add_test(function test_update_invalidConnection() {
@ -77,24 +77,31 @@ add_test(function test_updateStats_failure() {
});
add_test(function test_queue() {
// Fill connections with fake network interfaces (wlan0 and rmnet0)
// to enable netd async requests
NetworkStatsService._connectionTypes[Ci.nsINetworkInterface.NETWORK_TYPE_WIFI]
.network.name = 'wlan0';
NetworkStatsService._connectionTypes[Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE]
.network.name = 'rmnet0';
NetworkStatsService.updateStats(Ci.nsINetworkInterface.NETWORK_TYPE_WIFI);
NetworkStatsService.updateStats(Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE);
do_check_eq(NetworkStatsService.updateQueue.length, 2);
do_check_eq(NetworkStatsService.updateQueue[0].callbacks.length, 1);
NetworkStatsService.updateStats(Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, function(success, msg){
do_check_eq(NetworkStatsService.updateQueue.length, 1);
});
var callback = function(success, msg) {
return;
};
NetworkStatsService.updateStats(Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE, function(success, msg){
do_check_eq(NetworkStatsService.updateQueue.length, 0);
run_next_test();
});
NetworkStatsService.updateStats(Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, callback);
NetworkStatsService.updateStats(Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE, callback);
do_check_eq(NetworkStatsService.updateQueue.length, 2);
do_check_eq(NetworkStatsService.updateQueue[0].callbacks.length, 2);
do_check_eq(NetworkStatsService.updateQueue[0].callbacks[0], null);
do_check_neq(NetworkStatsService.updateQueue[0].callbacks[1], null);
run_next_test();
});
function run_test() {