Bug 1070944 - Part 4: Update and add test cases. r=albert

This commit is contained in:
Ethan Tseng 2015-02-09 10:30:57 +08:00
parent d1f9190bdb
commit 4a341c2065
2 changed files with 208 additions and 52 deletions

View File

@ -5,6 +5,7 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://gre/modules/NetworkStatsDB.jsm");
const STATS_STORE_NAME = "net_stats_store_v3";
const netStatsDb = new NetworkStatsDB();
function clearStore(store, callback) {
@ -26,7 +27,7 @@ function getNetworkId(aIccId, aNetworkType) {
add_test(function prepareDatabase() {
// Clear whole database to avoid starting tests with unknown state
// due to the previous tests.
clearStore('net_stats_store', function() {
clearStore(STATS_STORE_NAME, function() {
clearStore('net_alarm', function() {
run_next_test();
});
@ -151,6 +152,7 @@ add_test(function test_internalSaveStats_singleSample() {
var networks = getNetworks();
var stats = { appId: 0,
isInBrowser: 0,
serviceType: "",
network: [networks[0].id, networks[0].type],
timestamp: Date.now(),
@ -161,7 +163,7 @@ add_test(function test_internalSaveStats_singleSample() {
rxTotalBytes: 1234,
txTotalBytes: 1234 };
netStatsDb.dbNewTxn("net_stats_store", "readwrite", function(txn, store) {
netStatsDb.dbNewTxn(STATS_STORE_NAME, "readwrite", function(txn, store) {
netStatsDb._saveStats(txn, store, stats);
}, function(error, result) {
do_check_eq(error, null);
@ -170,6 +172,7 @@ add_test(function test_internalSaveStats_singleSample() {
do_check_eq(error, null);
do_check_eq(result.length, 1);
do_check_eq(result[0].appId, stats.appId);
do_check_eq(result[0].isInBrowser, stats.isInBrowser);
do_check_eq(result[0].serviceType, stats.serviceType);
do_check_true(compareNetworks(result[0].network, stats.network));
do_check_eq(result[0].timestamp, stats.timestamp);
@ -185,7 +188,7 @@ add_test(function test_internalSaveStats_singleSample() {
});
add_test(function test_internalSaveStats_arraySamples() {
clearStore('net_stats_store', function() {
clearStore(STATS_STORE_NAME, function() {
var networks = getNetworks();
var network = [networks[0].id, networks[0].type];
@ -193,6 +196,7 @@ add_test(function test_internalSaveStats_arraySamples() {
var stats = [];
for (var i = 0; i < samples; i++) {
stats.push({ appId: 0,
isInBrowser: 0,
serviceType: "",
network: network,
timestamp: Date.now() + (10 * i),
@ -204,7 +208,7 @@ add_test(function test_internalSaveStats_arraySamples() {
txTotalBytes: 1234 });
}
netStatsDb.dbNewTxn("net_stats_store", "readwrite", function(txn, store) {
netStatsDb.dbNewTxn(STATS_STORE_NAME, "readwrite", function(txn, store) {
netStatsDb._saveStats(txn, store, stats);
}, function(error, result) {
do_check_eq(error, null);
@ -216,6 +220,7 @@ add_test(function test_internalSaveStats_arraySamples() {
var success = true;
for (var i = 0; i < samples; i++) {
if (result[i].appId != stats[i].appId ||
result[i].isInBrowser != stats[i].isInBrowser ||
result[i].serviceType != stats[i].serviceType ||
!compareNetworks(result[i].network, stats[i].network) ||
result[i].timestamp != stats[i].timestamp ||
@ -237,30 +242,32 @@ add_test(function test_internalSaveStats_arraySamples() {
});
add_test(function test_internalRemoveOldStats() {
clearStore('net_stats_store', function() {
clearStore(STATS_STORE_NAME, function() {
var networks = getNetworks();
var network = [networks[0].id, networks[0].type];
var samples = 10;
var stats = [];
for (var i = 0; i < samples - 1; i++) {
stats.push({ appId: 0, serviceType: "",
stats.push({ appId: 0, isInBrowser: 0,
serviceType: "",
network: network, timestamp: Date.now() + (10 * i),
rxBytes: 0, txBytes: 0,
rxSystemBytes: 1234, txSystemBytes: 1234,
rxTotalBytes: 1234, txTotalBytes: 1234 });
}
stats.push({ appId: 0, serviceType: "",
stats.push({ appId: 0, isInBrowser: 0,
serviceType: "",
network: network, timestamp: Date.now() + (10 * samples),
rxBytes: 0, txBytes: 0,
rxSystemBytes: 1234, txSystemBytes: 1234,
rxTotalBytes: 1234, txTotalBytes: 1234 });
netStatsDb.dbNewTxn("net_stats_store", "readwrite", function(txn, store) {
netStatsDb.dbNewTxn(STATS_STORE_NAME, "readwrite", function(txn, store) {
netStatsDb._saveStats(txn, store, stats);
var date = stats[stats.length - 1].timestamp
+ (netStatsDb.sampleRate * netStatsDb.maxStorageSamples - 1) - 1;
netStatsDb._removeOldStats(txn, store, 0, "", network, date);
netStatsDb._removeOldStats(txn, store, 0, 0, "", network, date);
}, function(error, result) {
do_check_eq(error, null);
@ -275,11 +282,11 @@ add_test(function test_internalRemoveOldStats() {
});
function processSamplesDiff(networks, lastStat, newStat, callback) {
clearStore('net_stats_store', function() {
netStatsDb.dbNewTxn("net_stats_store", "readwrite", function(txn, store) {
clearStore(STATS_STORE_NAME, function() {
netStatsDb.dbNewTxn(STATS_STORE_NAME, "readwrite", function(txn, store) {
netStatsDb._saveStats(txn, store, lastStat);
}, function(error, result) {
netStatsDb.dbNewTxn("net_stats_store", "readwrite", function(txn, store) {
netStatsDb.dbNewTxn(STATS_STORE_NAME, "readwrite", function(txn, store) {
let request = store.index("network").openCursor(newStat.network, "prev");
request.onsuccess = function onsuccess(event) {
let cursor = event.target.result;
@ -304,13 +311,15 @@ add_test(function test_processSamplesDiffSameSample() {
var sampleRate = netStatsDb.sampleRate;
var date = filterTimestamp(new Date());
var lastStat = { appId: 0, serviceType: "",
var lastStat = { appId: 0, isInBrowser: 0,
serviceType: "",
network: network, timestamp: date,
rxBytes: 0, txBytes: 0,
rxSystemBytes: 1234, txSystemBytes: 1234,
rxTotalBytes: 2234, txTotalBytes: 2234 };
var newStat = { appId: 0, serviceType: "",
var newStat = { appId: 0, isInBrowser: 0,
serviceType: "",
network: network, timestamp: date,
rxBytes: 0, txBytes: 0,
rxSystemBytes: 2234, txSystemBytes: 2234,
@ -319,6 +328,7 @@ add_test(function test_processSamplesDiffSameSample() {
processSamplesDiff(networks, lastStat, newStat, function(result) {
do_check_eq(result.length, 1);
do_check_eq(result[0].appId, newStat.appId);
do_check_eq(result[0].isInBrowser, newStat.isInBrowser);
do_check_eq(result[0].serviceType, newStat.serviceType);
do_check_true(compareNetworks(result[0].network, newStat.network));
do_check_eq(result[0].timestamp, newStat.timestamp);
@ -339,13 +349,15 @@ add_test(function test_processSamplesDiffNextSample() {
var sampleRate = netStatsDb.sampleRate;
var date = filterTimestamp(new Date());
var lastStat = { appId: 0, serviceType: "",
var lastStat = { appId: 0, isInBrowser: 0,
serviceType: "",
network: network, timestamp: date,
rxBytes: 0, txBytes: 0,
rxSystemBytes: 1234, txSystemBytes: 1234,
rxTotalBytes: 2234, txTotalBytes: 2234 };
var newStat = { appId: 0, serviceType: "",
var newStat = { appId: 0, isInBrowser: 0,
serviceType: "",
network: network, timestamp: date + sampleRate,
rxBytes: 0, txBytes: 0,
rxSystemBytes: 1734, txSystemBytes: 1734,
@ -354,6 +366,7 @@ add_test(function test_processSamplesDiffNextSample() {
processSamplesDiff(networks, lastStat, newStat, function(result) {
do_check_eq(result.length, 2);
do_check_eq(result[1].appId, newStat.appId);
do_check_eq(result[1].isInBrowser, newStat.isInBrowser);
do_check_eq(result[1].serviceType, newStat.serviceType);
do_check_true(compareNetworks(result[1].network, newStat.network));
do_check_eq(result[1].timestamp, newStat.timestamp);
@ -373,13 +386,15 @@ add_test(function test_processSamplesDiffSamplesLost() {
var samples = 5;
var sampleRate = netStatsDb.sampleRate;
var date = filterTimestamp(new Date());
var lastStat = { appId: 0, serviceType: "",
var lastStat = { appId: 0, isInBrowser: 0,
serviceType: "",
network: network, timestamp: date,
rxBytes: 0, txBytes: 0,
rxSystemBytes: 1234, txSystemBytes: 1234,
rxTotalBytes: 2234, txTotalBytes: 2234};
var newStat = { appId: 0, serviceType: "",
var newStat = { appId: 0, isInBrowser: 0,
serviceType: "",
network: network, timestamp: date + (sampleRate * samples),
rxBytes: 0, txBytes: 0,
rxSystemBytes: 2234, txSystemBytes: 2234,
@ -388,6 +403,7 @@ add_test(function test_processSamplesDiffSamplesLost() {
processSamplesDiff(networks, lastStat, newStat, function(result) {
do_check_eq(result.length, samples + 1);
do_check_eq(result[0].appId, newStat.appId);
do_check_eq(result[0].isInBrowser, newStat.isInBrowser);
do_check_eq(result[0].serviceType, newStat.serviceType);
do_check_true(compareNetworks(result[samples].network, newStat.network));
do_check_eq(result[samples].timestamp, newStat.timestamp);
@ -406,6 +422,7 @@ add_test(function test_saveStats() {
var network = [networks[0].id, networks[0].type];
var stats = { appId: 0,
isInBrowser: false,
serviceType: "",
networkId: networks[0].id,
networkType: networks[0].type,
@ -414,13 +431,14 @@ add_test(function test_saveStats() {
txBytes: 2234,
isAccumulative: true };
clearStore('net_stats_store', function() {
clearStore(STATS_STORE_NAME, function() {
netStatsDb.saveStats(stats, function(error, result) {
do_check_eq(error, null);
netStatsDb.logAllRecords(function(error, result) {
do_check_eq(error, null);
do_check_eq(result.length, 1);
do_check_eq(result[0].appId, stats.appId);
do_check_eq(result[0].isInBrowser, stats.isInBrowser);
do_check_eq(result[0].serviceType, stats.serviceType);
do_check_true(compareNetworks(result[0].network, network));
let timestamp = filterTimestamp(stats.date);
@ -442,6 +460,7 @@ add_test(function test_saveAppStats() {
var network = [networks[0].id, networks[0].type];
var stats = { appId: 1,
isInBrowser: false,
serviceType: "",
networkId: networks[0].id,
networkType: networks[0].type,
@ -450,13 +469,14 @@ add_test(function test_saveAppStats() {
txBytes: 2234,
isAccumulative: false };
clearStore('net_stats_store', function() {
clearStore(STATS_STORE_NAME, function() {
netStatsDb.saveStats(stats, function(error, result) {
do_check_eq(error, null);
netStatsDb.logAllRecords(function(error, result) {
do_check_eq(error, null);
do_check_eq(result.length, 1);
do_check_eq(result[0].appId, stats.appId);
do_check_eq(result[0].isInBrowser, 0);
do_check_eq(result[0].serviceType, stats.serviceType);
do_check_true(compareNetworks(result[0].network, network));
let timestamp = filterTimestamp(stats.date);
@ -478,6 +498,7 @@ add_test(function test_saveServiceStats() {
var network = [networks[0].id, networks[0].type];
var stats = { appId: 0,
isInBrowser: false,
serviceType: "FakeType",
networkId: networks[0].id,
networkType: networks[0].type,
@ -486,13 +507,14 @@ add_test(function test_saveServiceStats() {
txBytes: 2234,
isAccumulative: false };
clearStore('net_stats_store', function() {
clearStore(STATS_STORE_NAME, function() {
netStatsDb.saveStats(stats, function(error, result) {
do_check_eq(error, null);
netStatsDb.logAllRecords(function(error, result) {
do_check_eq(error, null);
do_check_eq(result.length, 1);
do_check_eq(result[0].appId, stats.appId);
do_check_eq(result[0].isInBrowser, 0);
do_check_eq(result[0].serviceType, stats.serviceType);
do_check_true(compareNetworks(result[0].network, network));
let timestamp = filterTimestamp(stats.date);
@ -510,8 +532,8 @@ add_test(function test_saveServiceStats() {
});
function prepareFind(stats, callback) {
clearStore('net_stats_store', function() {
netStatsDb.dbNewTxn("net_stats_store", "readwrite", function(txn, store) {
clearStore(STATS_STORE_NAME, function() {
netStatsDb.dbNewTxn(STATS_STORE_NAME, "readwrite", function(txn, store) {
netStatsDb._saveStats(txn, store, stats);
}, function(error, result) {
callback(error, result);
@ -524,6 +546,7 @@ add_test(function test_find () {
var networkWifi = [networks[0].id, networks[0].type];
var networkMobile = [networks[1].id, networks[1].type]; // Fake mobile interface
var appId = 0;
var isInBrowser = 0;
var serviceType = "";
var samples = 5;
@ -534,14 +557,16 @@ add_test(function test_find () {
start = new Date(start - sampleRate);
var stats = [];
for (var i = 0; i < samples; i++) {
stats.push({ appId: appId, serviceType: serviceType,
stats.push({ appId: appId, isInBrowser: isInBrowser,
serviceType: serviceType,
network: networkWifi, timestamp: saveDate + (sampleRate * i),
rxBytes: 0, txBytes: 10,
rxSystemBytes: 0, txSystemBytes: 0,
rxTotalBytes: 0, txTotalBytes: 0 });
stats.push({ appId: appId, serviceType: serviceType,
stats.push({ appId: appId, isInBrowser: isInBrowser,
serviceType: serviceType,
network: networkMobile, timestamp: saveDate + (sampleRate * i),
rxBytes: 0, txBytes: 10,
rxSystemBytes: 0, txSystemBytes: 0,
@ -552,6 +577,7 @@ add_test(function test_find () {
do_check_eq(error, null);
netStatsDb.find(function (error, result) {
do_check_eq(error, null);
do_check_eq(result.browsingTrafficOnly, false);
do_check_eq(result.serviceType, serviceType);
do_check_eq(result.network.id, networks[0].id);
do_check_eq(result.network.type, networks[0].type);
@ -562,7 +588,7 @@ add_test(function test_find () {
do_check_eq(result.data[1].rxBytes, 0);
do_check_eq(result.data[samples].rxBytes, 0);
run_next_test();
}, appId, serviceType, networks[0], start, end);
}, appId, false, serviceType, networks[0], start, end);
});
});
@ -571,6 +597,7 @@ add_test(function test_findAppStats () {
var networkWifi = [networks[0].id, networks[0].type];
var networkMobile = [networks[1].id, networks[1].type]; // Fake mobile interface
var appId = 1;
var isInBrowser = 0;
var serviceType = "";
var samples = 5;
@ -581,12 +608,14 @@ add_test(function test_findAppStats () {
start = new Date(start - sampleRate);
var stats = [];
for (var i = 0; i < samples; i++) {
stats.push({ appId: appId, serviceType: serviceType,
stats.push({ appId: appId, isInBrowser: isInBrowser,
serviceType: serviceType,
network: networkWifi, timestamp: saveDate + (sampleRate * i),
rxBytes: 0, txBytes: 10,
rxTotalBytes: 0, txTotalBytes: 0 });
stats.push({ appId: appId, serviceType: serviceType,
stats.push({ appId: appId, isInBrowser: isInBrowser,
serviceType: serviceType,
network: networkMobile, timestamp: saveDate + (sampleRate * i),
rxBytes: 0, txBytes: 10,
rxTotalBytes: 0, txTotalBytes: 0 });
@ -596,6 +625,7 @@ add_test(function test_findAppStats () {
do_check_eq(error, null);
netStatsDb.find(function (error, result) {
do_check_eq(error, null);
do_check_eq(result.browsingTrafficOnly, false);
do_check_eq(result.serviceType, serviceType);
do_check_eq(result.network.id, networks[0].id);
do_check_eq(result.network.type, networks[0].type);
@ -606,7 +636,7 @@ add_test(function test_findAppStats () {
do_check_eq(result.data[1].rxBytes, 0);
do_check_eq(result.data[samples].rxBytes, 0);
run_next_test();
}, appId, serviceType, networks[0], start, end);
}, appId, false, serviceType, networks[0], start, end);
});
});
@ -615,6 +645,7 @@ add_test(function test_findServiceStats () {
var networkWifi = [networks[0].id, networks[0].type];
var networkMobile = [networks[1].id, networks[1].type]; // Fake mobile interface
var appId = 0;
var isInBrowser = 0;
var serviceType = "FakeType";
var samples = 5;
@ -625,12 +656,14 @@ add_test(function test_findServiceStats () {
start = new Date(start - sampleRate);
var stats = [];
for (var i = 0; i < samples; i++) {
stats.push({ appId: appId, serviceType: serviceType,
stats.push({ appId: appId, isInBrowser: isInBrowser,
serviceType: serviceType,
network: networkWifi, timestamp: saveDate + (sampleRate * i),
rxBytes: 0, txBytes: 10,
rxTotalBytes: 0, txTotalBytes: 0 });
stats.push({ appId: appId, serviceType: serviceType,
stats.push({ appId: appId, isInBrowser: isInBrowser,
serviceType: serviceType,
network: networkMobile, timestamp: saveDate + (sampleRate * i),
rxBytes: 0, txBytes: 10,
rxTotalBytes: 0, txTotalBytes: 0 });
@ -640,6 +673,7 @@ add_test(function test_findServiceStats () {
do_check_eq(error, null);
netStatsDb.find(function (error, result) {
do_check_eq(error, null);
do_check_eq(result.browsingTrafficOnly, false);
do_check_eq(result.serviceType, serviceType);
do_check_eq(result.network.id, networks[0].id);
do_check_eq(result.network.type, networks[0].type);
@ -650,7 +684,7 @@ add_test(function test_findServiceStats () {
do_check_eq(result.data[1].rxBytes, 0);
do_check_eq(result.data[samples].rxBytes, 0);
run_next_test();
}, appId, serviceType, networks[0], start, end);
}, appId, false, serviceType, networks[0], start, end);
});
});
@ -669,42 +703,48 @@ add_test(function test_saveMultipleAppStats () {
appId: 0, date: new Date(),
networkId: networkWifi.id, networkType: networkWifi.type,
rxBytes: 0, txBytes: 10,
serviceType: serviceType, isAccumulative: false
serviceType: serviceType, isAccumulative: false,
isInBrowser: false
};
cached[0 + '' + serviceType + mobileNetId] = {
appId: 0, date: new Date(),
networkId: networkMobile.id, networkType: networkMobile.type,
rxBytes: 0, txBytes: 10,
serviceType: serviceType, isAccumulative: false
serviceType: serviceType, isAccumulative: false,
isInBrowser: false
};
cached[1 + '' + wifiNetId] = {
appId: 1, date: new Date(),
networkId: networkWifi.id, networkType: networkWifi.type,
rxBytes: 0, txBytes: 10,
serviceType: "", isAccumulative: false
serviceType: "", isAccumulative: false,
isInBrowser: false
};
cached[1 + '' + mobileNetId] = {
appId: 1, date: new Date(),
networkId: networkMobile.id, networkType: networkMobile.type,
rxBytes: 0, txBytes: 10,
serviceType: "", isAccumulative: false
serviceType: "", isAccumulative: false,
isInBrowser: false
};
cached[2 + '' + wifiNetId] = {
appId: 2, date: new Date(),
networkId: networkWifi.id, networkType: networkWifi.type,
rxBytes: 0, txBytes: 10,
serviceType: "", isAccumulative: false
serviceType: "", isAccumulative: false,
isInBrowser: false
};
cached[2 + '' + mobileNetId] = {
appId: 2, date: new Date(),
networkId: networkMobile.id, networkType: networkMobile.type,
rxBytes: 0, txBytes: 10,
serviceType: "", isAccumulative: false
serviceType: "", isAccumulative: false,
isInBrowser: false
};
let keys = Object.keys(cached);
@ -712,7 +752,7 @@ add_test(function test_saveMultipleAppStats () {
networks.push(networkMobile);
clearStore('net_stats_store', function() {
clearStore(STATS_STORE_NAME, function() {
netStatsDb.saveStats(cached[keys[index]],
function callback(error, result) {
do_check_eq(error, null);
@ -721,6 +761,7 @@ add_test(function test_saveMultipleAppStats () {
netStatsDb.logAllRecords(function(error, result) {
do_check_eq(error, null);
do_check_eq(result.length, 6);
do_check_eq(result[0].isInBrowser, 0);
do_check_eq(result[0].serviceType, serviceType);
do_check_eq(result[3].appId, 1);
do_check_true(compareNetworks(result[0].network, [networkWifi.id, networkWifi.type]));
@ -737,6 +778,118 @@ add_test(function test_saveMultipleAppStats () {
});
});
// Test case for find samples with browsingTrafficOnly option.
add_test(function test_findBrowsingTrafficStats() {
var networks = getNetworks();
var networkWifi = [networks[0].id, networks[0].type];
var networkMobile = [networks[1].id, networks[1].type];
var serviceType = "";
var samples = 5;
var sampleRate = netStatsDb.sampleRate;
var start = Date.now();
var end = new Date(start + (sampleRate * (samples - 1)));
var saveDate = filterTimestamp(new Date());
start = new Date(start - sampleRate);
var stats = [];
for (var i = 0; i < samples; i++) {
// System app.
stats.push({ appId: 1008, isInBrowser: 0,
serviceType: serviceType, network: networkMobile,
timestamp: saveDate + (sampleRate * i),
rxBytes: 200, txBytes: 100});
// Browser of system app.
stats.push({ appId: 1008, isInBrowser: 1,
serviceType: serviceType, network: networkMobile,
timestamp: saveDate + (sampleRate * i),
rxBytes: 1000, txBytes: 500});
// Another app.
stats.push({ appId: 1021, isInBrowser: 0,
serviceType: serviceType, network: networkMobile,
timestamp: saveDate + (sampleRate * i),
rxBytes: 300, txBytes: 150});
// Browser of another app.
stats.push({ appId: 1021, isInBrowser: 1,
serviceType: serviceType, network: networkMobile,
timestamp: saveDate + (sampleRate * i),
rxBytes: 600, txBytes: 300});
}
prepareFind(stats, function(error, result) {
do_check_eq(error, null);
netStatsDb.find(function(error, result) {
do_check_eq(error, null);
do_check_eq(result.browsingTrafficOnly, true);
do_check_eq(result.serviceType, serviceType);
do_check_eq(result.network.id, networks[1].id);
do_check_eq(result.network.type, networks[1].type);
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].txBytes, 500);
do_check_eq(result.data[2].rxBytes, 1000);
run_next_test();
}, 1008, true, serviceType, networks[1], start, end);
});
});
// Test case for find samples with browsingTrafficOnly option.
add_test(function test_findAppTrafficStats() {
var networks = getNetworks();
var networkWifi = [networks[0].id, networks[0].type];
var networkMobile = [networks[1].id, networks[1].type];
var serviceType = "";
var samples = 5;
var sampleRate = netStatsDb.sampleRate;
var start = Date.now();
var end = new Date(start + (sampleRate * (samples - 1)));
var saveDate = filterTimestamp(new Date());
start = new Date(start - sampleRate);
var stats = [];
for (var i = 0; i < samples; i++) {
// System app.
stats.push({ appId: 1008, isInBrowser: 0,
serviceType: serviceType, network: networkMobile,
timestamp: saveDate + (sampleRate * i),
rxBytes: 200, txBytes: 100});
// Browser of system app.
stats.push({ appId: 1008, isInBrowser: 1,
serviceType: serviceType, network: networkMobile,
timestamp: saveDate + (sampleRate * i),
rxBytes: 1000, txBytes: 500});
// Another app.
stats.push({ appId: 1021, isInBrowser: 0,
serviceType: serviceType, network: networkMobile,
timestamp: saveDate + (sampleRate * i),
rxBytes: 300, txBytes: 150});
// Browser of another app.
stats.push({ appId: 1021, isInBrowser: 1,
serviceType: serviceType, network: networkMobile,
timestamp: saveDate + (sampleRate * i),
rxBytes: 600, txBytes: 300});
}
prepareFind(stats, function(error, result) {
do_check_eq(error, null);
netStatsDb.find(function(error, result) {
do_check_eq(error, null);
do_check_eq(result.browsingTrafficOnly, false);
do_check_eq(result.serviceType, serviceType);
do_check_eq(result.network.id, networks[1].id);
do_check_eq(result.network.type, networks[1].type);
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].txBytes, 600);
do_check_eq(result.data[2].rxBytes, 1200);
run_next_test();
}, 1008, false, serviceType, networks[1], start, end);
});
});
var networkWifi = '00';
var networkMobile = '11';

View File

@ -48,16 +48,17 @@ add_test(function test_saveAppStats() {
do_check_eq(Object.keys(cachedStats).length, 0);
nssProxy.saveAppStats(1, wifi, timestamp, 10, 20, false,
nssProxy.saveAppStats(1, false, wifi, timestamp, 10, 20, false,
function (success, message) {
do_check_eq(success, true);
nssProxy.saveAppStats(1, mobile, timestamp, 10, 20, false,
nssProxy.saveAppStats(1, false, mobile, timestamp, 10, 20, false,
function (success, message) {
var key1 = 1 + "" + NetworkStatsService.getNetworkId(wifi.id, wifi.type);
var key2 = 1 + "" + mobileNetId + "";
var key1 = 1 + "" + false + "" + NetworkStatsService.getNetworkId(wifi.id, wifi.type);
var key2 = 1 + "" + false + "" + mobileNetId + "";
do_check_eq(Object.keys(cachedStats).length, 2);
do_check_eq(cachedStats[key1].appId, 1);
do_check_eq(cachedStats[key1].isInBrowser, false);
do_check_eq(cachedStats[key1].serviceType.length, 0);
do_check_eq(cachedStats[key1].networkId, wifi.id);
do_check_eq(cachedStats[key1].networkType, wifi.type);
@ -104,12 +105,13 @@ add_test(function test_saveServiceStats() {
nssProxy.saveServiceStats(serviceType, mobile, timestamp, 10, 20, false,
function (success, message) {
do_check_eq(success, true);
var key1 = 0 + "" + serviceType +
var key1 = 0 + "" + false + "" + serviceType +
NetworkStatsService.getNetworkId(wifi.id, wifi.type);
var key2 = 0 + "" + serviceType + mobileNetId + "";
var key2 = 0 + "" + false + "" + serviceType + mobileNetId + "";
do_check_eq(Object.keys(cachedStats).length, 2);
do_check_eq(cachedStats[key1].appId, 0);
do_check_eq(cachedStats[key1].isInBrowser, false);
do_check_eq(cachedStats[key1].serviceType, serviceType);
do_check_eq(cachedStats[key1].networkId, wifi.id);
do_check_eq(cachedStats[key1].networkType, wifi.type);
@ -142,18 +144,19 @@ add_test(function test_saveStatsWithDifferentDates() {
do_check_eq(success, true);
do_check_eq(Object.keys(NetworkStatsService.cachedStats).length, 0);
nssProxy.saveAppStats(1, mobile, today.getTime(), 10, 20, false,
nssProxy.saveAppStats(1, false, mobile, today.getTime(), 10, 20, false,
function (success, message) {
do_check_eq(success, true);
nssProxy.saveAppStats(2, mobile, tomorrow.getTime(), 30, 40, false,
nssProxy.saveAppStats(2, false, mobile, tomorrow.getTime(), 30, 40, false,
function (success, message) {
do_check_eq(success, true);
var cachedStats = NetworkStatsService.cachedStats;
var key = 2 + "" +
var key = 2 + "" + false + "" +
NetworkStatsService.getNetworkId(mobile.id, mobile.type);
do_check_eq(Object.keys(cachedStats).length, 1);
do_check_eq(cachedStats[key].appId, 2);
do_check_eq(cachedStats[key].isInBrowser, false);
do_check_eq(cachedStats[key].networkId, mobile.id);
do_check_eq(cachedStats[key].networkType, mobile.type);
do_check_eq(new Date(cachedStats[key].date).getTime() / 1000,
@ -177,11 +180,11 @@ add_test(function test_saveStatsWithMaxCachedTraffic() {
var cachedStats = NetworkStatsService.cachedStats;
do_check_eq(Object.keys(cachedStats).length, 0);
nssProxy.saveAppStats(1, wifi, timestamp, 10, 20, false,
nssProxy.saveAppStats(1, false, wifi, timestamp, 10, 20, false,
function (success, message) {
do_check_eq(success, true);
do_check_eq(Object.keys(cachedStats).length, 1);
nssProxy.saveAppStats(1, wifi, timestamp, maxtraffic, 20, false,
nssProxy.saveAppStats(1, false, wifi, timestamp, maxtraffic, 20, false,
function (success, message) {
do_check_eq(success, true);
do_check_eq(Object.keys(cachedStats).length, 0);
@ -207,7 +210,7 @@ add_test(function test_saveAppStats() {
do_check_eq(Object.keys(cachedStats).length, 0);
nssProxy.saveAppStats(1, wifi, timestamp, 10, 20, false, { notify:
nssProxy.saveAppStats(1, false, wifi, timestamp, 10, 20, false, { notify:
function (success, message) {
do_check_eq(success, true);
var iterations = 10;
@ -219,7 +222,7 @@ add_test(function test_saveAppStats() {
};
for (var i = 0; i < iterations; i++) {
nssProxy.saveAppStats(1, mobile, timestamp, 10, 20, false, callback);
nssProxy.saveAppStats(1, false, mobile, timestamp, 10, 20, false, callback);
}
}});
});