From c5083a9447c9f692d0c9add6f867c7569d2b37c1 Mon Sep 17 00:00:00 2001 From: Albert Crespell Date: Fri, 7 Jun 2013 18:57:07 +0200 Subject: [PATCH] Bug 879793 - Update tests. r=clian --- .../tests/unit_stats/test_networkstats_db.js | 14 +++++------ .../unit_stats/test_networkstats_service.js | 25 ++++++++++++------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/dom/network/tests/unit_stats/test_networkstats_db.js b/dom/network/tests/unit_stats/test_networkstats_db.js index 834a7b419ec2..5ea440b86737 100644 --- a/dom/network/tests/unit_stats/test_networkstats_db.js +++ b/dom/network/tests/unit_stats/test_networkstats_db.js @@ -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); diff --git a/dom/network/tests/unit_stats/test_networkstats_service.js b/dom/network/tests/unit_stats/test_networkstats_service.js index 2037cd8a8796..569b2f7ba0d1 100644 --- a/dom/network/tests/unit_stats/test_networkstats_service.js +++ b/dom/network/tests/unit_stats/test_networkstats_service.js @@ -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() {