зеркало из https://github.com/mozilla/gecko-dev.git
Bug 879793 - Update tests. r=clian
This commit is contained in:
Родитель
60c8fa8f91
Коммит
c5083a9447
|
@ -10,7 +10,7 @@ const netStatsDb = new NetworkStatsDB(this);
|
||||||
function filterTimestamp(date) {
|
function filterTimestamp(date) {
|
||||||
var sampleRate = netStatsDb.sampleRate;
|
var sampleRate = netStatsDb.sampleRate;
|
||||||
var offset = date.getTimezoneOffset() * 60 * 1000;
|
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() {
|
add_test(function test_sampleRate() {
|
||||||
|
@ -335,8 +335,8 @@ add_test(function test_find () {
|
||||||
var sampleRate = netStatsDb.sampleRate;
|
var sampleRate = netStatsDb.sampleRate;
|
||||||
var start = Date.now();
|
var start = Date.now();
|
||||||
var saveDate = filterTimestamp(new Date());
|
var saveDate = filterTimestamp(new Date());
|
||||||
var end = start + (sampleRate * (samples - 1));
|
var end = new Date(start + (sampleRate * (samples - 1)));
|
||||||
start -= sampleRate;
|
start = new Date(start - sampleRate);
|
||||||
var stats = [];
|
var stats = [];
|
||||||
for (var i = 0; i < samples; i++) {i
|
for (var i = 0; i < samples; i++) {i
|
||||||
stats.push({connectionType: "wifi", timestamp: saveDate + (sampleRate * i),
|
stats.push({connectionType: "wifi", timestamp: saveDate + (sampleRate * i),
|
||||||
|
@ -353,8 +353,8 @@ add_test(function test_find () {
|
||||||
netStatsDb.find(function (error, result) {
|
netStatsDb.find(function (error, result) {
|
||||||
do_check_eq(error, null);
|
do_check_eq(error, null);
|
||||||
do_check_eq(result.connectionType, "wifi");
|
do_check_eq(result.connectionType, "wifi");
|
||||||
do_check_eq(result.start.getTime(), start);
|
do_check_eq(result.start.getTime(), start.getTime());
|
||||||
do_check_eq(result.end.getTime(), end);
|
do_check_eq(result.end.getTime(), end.getTime());
|
||||||
do_check_eq(result.data.length, samples + 1);
|
do_check_eq(result.data.length, samples + 1);
|
||||||
do_check_eq(result.data[0].rxBytes, null);
|
do_check_eq(result.data[0].rxBytes, null);
|
||||||
do_check_eq(result.data[1].rxBytes, 0);
|
do_check_eq(result.data[1].rxBytes, 0);
|
||||||
|
@ -363,8 +363,8 @@ add_test(function test_find () {
|
||||||
netStatsDb.findAll(function (error, result) {
|
netStatsDb.findAll(function (error, result) {
|
||||||
do_check_eq(error, null);
|
do_check_eq(error, null);
|
||||||
do_check_eq(result.connectionType, null);
|
do_check_eq(result.connectionType, null);
|
||||||
do_check_eq(result.start.getTime(), start);
|
do_check_eq(result.start.getTime(), start.getTime());
|
||||||
do_check_eq(result.end.getTime(), end);
|
do_check_eq(result.end.getTime(), end.getTime());
|
||||||
do_check_eq(result.data.length, samples + 1);
|
do_check_eq(result.data.length, samples + 1);
|
||||||
do_check_eq(result.data[0].rxBytes, null);
|
do_check_eq(result.data[0].rxBytes, null);
|
||||||
do_check_eq(result.data[1].rxBytes, 0);
|
do_check_eq(result.data[1].rxBytes, 0);
|
||||||
|
|
|
@ -15,14 +15,14 @@ add_test(function test_networkStatsAvailable_ok() {
|
||||||
NetworkStatsService.networkStatsAvailable(function (success, msg) {
|
NetworkStatsService.networkStatsAvailable(function (success, msg) {
|
||||||
do_check_eq(success, true);
|
do_check_eq(success, true);
|
||||||
run_next_test();
|
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() {
|
add_test(function test_networkStatsAvailable_failure() {
|
||||||
NetworkStatsService.networkStatsAvailable(function (success, msg) {
|
NetworkStatsService.networkStatsAvailable(function (success, msg) {
|
||||||
do_check_eq(success, false);
|
do_check_eq(success, false);
|
||||||
run_next_test();
|
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() {
|
add_test(function test_update_invalidConnection() {
|
||||||
|
@ -77,24 +77,31 @@ add_test(function test_updateStats_failure() {
|
||||||
});
|
});
|
||||||
|
|
||||||
add_test(function test_queue() {
|
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_WIFI);
|
||||||
NetworkStatsService.updateStats(Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE);
|
NetworkStatsService.updateStats(Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE);
|
||||||
do_check_eq(NetworkStatsService.updateQueue.length, 2);
|
do_check_eq(NetworkStatsService.updateQueue.length, 2);
|
||||||
do_check_eq(NetworkStatsService.updateQueue[0].callbacks.length, 1);
|
do_check_eq(NetworkStatsService.updateQueue[0].callbacks.length, 1);
|
||||||
|
|
||||||
NetworkStatsService.updateStats(Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, function(success, msg){
|
var callback = function(success, msg) {
|
||||||
do_check_eq(NetworkStatsService.updateQueue.length, 1);
|
return;
|
||||||
});
|
};
|
||||||
|
|
||||||
NetworkStatsService.updateStats(Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE, function(success, msg){
|
NetworkStatsService.updateStats(Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, callback);
|
||||||
do_check_eq(NetworkStatsService.updateQueue.length, 0);
|
NetworkStatsService.updateStats(Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE, callback);
|
||||||
run_next_test();
|
|
||||||
});
|
|
||||||
|
|
||||||
do_check_eq(NetworkStatsService.updateQueue.length, 2);
|
do_check_eq(NetworkStatsService.updateQueue.length, 2);
|
||||||
do_check_eq(NetworkStatsService.updateQueue[0].callbacks.length, 2);
|
do_check_eq(NetworkStatsService.updateQueue[0].callbacks.length, 2);
|
||||||
do_check_eq(NetworkStatsService.updateQueue[0].callbacks[0], null);
|
do_check_eq(NetworkStatsService.updateQueue[0].callbacks[0], null);
|
||||||
do_check_neq(NetworkStatsService.updateQueue[0].callbacks[1], null);
|
do_check_neq(NetworkStatsService.updateQueue[0].callbacks[1], null);
|
||||||
|
|
||||||
|
run_next_test();
|
||||||
});
|
});
|
||||||
|
|
||||||
function run_test() {
|
function run_test() {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче