dom/network/tests/unit_stats/test_networkstats_db.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/network/tests/unit_stats/test_networkstats_db.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,932 @@
     1.4 +/* Any: copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
     1.8 +
     1.9 +Cu.import("resource://gre/modules/NetworkStatsDB.jsm");
    1.10 +
    1.11 +const netStatsDb = new NetworkStatsDB();
    1.12 +
    1.13 +function clearStore(store, callback) {
    1.14 +  netStatsDb.dbNewTxn(store, "readwrite", function(aTxn, aStore) {
    1.15 +    aStore.openCursor().onsuccess = function (event) {
    1.16 +      let cursor = event.target.result;
    1.17 +      if (cursor){
    1.18 +        cursor.delete();
    1.19 +        cursor.continue();
    1.20 +      }
    1.21 +    };
    1.22 +  }, callback);
    1.23 +}
    1.24 +
    1.25 +function getNetworkId(aIccId, aNetworkType) {
    1.26 +  return aIccId + '' + aNetworkType;
    1.27 +}
    1.28 +
    1.29 +add_test(function prepareDatabase() {
    1.30 +  // Clear whole database to avoid starting tests with unknown state
    1.31 +  // due to the previous tests.
    1.32 +  clearStore('net_stats_store', function() {
    1.33 +    clearStore('net_alarm', function() {
    1.34 +      run_next_test();
    1.35 +    });
    1.36 +  });
    1.37 +});
    1.38 +
    1.39 +function filterTimestamp(date) {
    1.40 +  var sampleRate = netStatsDb.sampleRate;
    1.41 +  var offset = date.getTimezoneOffset() * 60 * 1000;
    1.42 +  return Math.floor((date.getTime() - offset) / sampleRate) * sampleRate;
    1.43 +}
    1.44 +
    1.45 +function getNetworks() {
    1.46 +  return [{ id: '0', type: Ci.nsIDOMMozNetworkStatsManager.WIFI },
    1.47 +          { id: '1234', type: Ci.nsIDOMMozNetworkStatsManager.MOBILE }];
    1.48 +}
    1.49 +
    1.50 +function compareNetworks(networkA, networkB) {
    1.51 +  return (networkA[0] == networkB[0] && networkA[1] == networkB[1]);
    1.52 +}
    1.53 +
    1.54 +add_test(function test_sampleRate() {
    1.55 +  var sampleRate = netStatsDb.sampleRate;
    1.56 +  do_check_true(sampleRate > 0);
    1.57 +  netStatsDb.sampleRate = 0;
    1.58 +  sampleRate = netStatsDb.sampleRate;
    1.59 +  do_check_true(sampleRate > 0);
    1.60 +
    1.61 +  run_next_test();
    1.62 +});
    1.63 +
    1.64 +add_test(function test_maxStorageSamples() {
    1.65 +  var maxStorageSamples = netStatsDb.maxStorageSamples;
    1.66 +  do_check_true(maxStorageSamples > 0);
    1.67 +  netStatsDb.maxStorageSamples = 0;
    1.68 +  maxStorageSamples = netStatsDb.maxStorageSamples;
    1.69 +  do_check_true(maxStorageSamples > 0);
    1.70 +
    1.71 +  run_next_test();
    1.72 +});
    1.73 +
    1.74 +add_test(function test_fillResultSamples_emptyData() {
    1.75 +  var samples = 3;
    1.76 +  var data = [];
    1.77 +  var start = filterTimestamp(new Date());
    1.78 +  var sampleRate = netStatsDb.sampleRate;
    1.79 +  var end = start + (sampleRate * samples);
    1.80 +  netStatsDb.fillResultSamples(start, end, data);
    1.81 +  do_check_eq(data.length, samples + 1);
    1.82 +
    1.83 +  var aux = start;
    1.84 +  var success = true;
    1.85 +  for (var i = 0; i <= samples; i++) {
    1.86 +    if (data[i].date.getTime() != aux || data[i].rxBytes != undefined || data[i].txBytes != undefined) {
    1.87 +      success = false;
    1.88 +      break;
    1.89 +    }
    1.90 +    aux += sampleRate;
    1.91 +  }
    1.92 +  do_check_true(success);
    1.93 +
    1.94 +  run_next_test();
    1.95 +});
    1.96 +
    1.97 +add_test(function test_fillResultSamples_noEmptyData() {
    1.98 +  var samples = 3;
    1.99 +  var sampleRate = netStatsDb.sampleRate;
   1.100 +  var start = filterTimestamp(new Date());
   1.101 +  var end = start + (sampleRate * samples);
   1.102 +  var data = [{date: new Date(start + sampleRate),
   1.103 +               rxBytes: 0,
   1.104 +               txBytes: 0}];
   1.105 +  netStatsDb.fillResultSamples(start, end, data);
   1.106 +  do_check_eq(data.length, samples + 1);
   1.107 +
   1.108 +  var aux = start;
   1.109 +  var success = true;
   1.110 +  for (var i = 0; i <= samples; i++) {
   1.111 +    if (i == 1) {
   1.112 +      if (data[i].date.getTime() != aux || data[i].rxBytes != 0 || data[i].txBytes != 0) {
   1.113 +        success = false;
   1.114 +        break;
   1.115 +      }
   1.116 +    } else {
   1.117 +      if (data[i].date.getTime() != aux || data[i].rxBytes != undefined || data[i].txBytes != undefined) {
   1.118 +        success = false;
   1.119 +        break;
   1.120 +      }
   1.121 +    }
   1.122 +    aux += sampleRate;
   1.123 +  }
   1.124 +  do_check_true(success);
   1.125 +
   1.126 +  run_next_test();
   1.127 +});
   1.128 +
   1.129 +add_test(function test_clear() {
   1.130 +  var networks = getNetworks();
   1.131 +  networks.forEach(function(network, index) {
   1.132 +    networks[index] = {network: network, networkId: getNetworkId(network.id, network.type)};
   1.133 +  }, this);
   1.134 +
   1.135 +  netStatsDb.clearStats(networks, function (error, result) {
   1.136 +    do_check_eq(error, null);
   1.137 +    run_next_test();
   1.138 +  });
   1.139 +});
   1.140 +
   1.141 +add_test(function test_clear_interface() {
   1.142 +  var networks = getNetworks();
   1.143 +  networks.forEach(function(network, index) {
   1.144 +    networks[index] = {network: network, networkId: getNetworkId(network.id, network.type)};
   1.145 +  }, this);
   1.146 +
   1.147 +  netStatsDb.clearInterfaceStats(networks[0], function (error, result) {
   1.148 +    do_check_eq(error, null);
   1.149 +    run_next_test();
   1.150 +  });
   1.151 +});
   1.152 +
   1.153 +add_test(function test_internalSaveStats_singleSample() {
   1.154 +  var networks = getNetworks();
   1.155 +
   1.156 +  var stats = { appId:         0,
   1.157 +                serviceType:   "",
   1.158 +                network:       [networks[0].id, networks[0].type],
   1.159 +                timestamp:     Date.now(),
   1.160 +                rxBytes:       0,
   1.161 +                txBytes:       0,
   1.162 +                rxSystemBytes: 1234,
   1.163 +                txSystemBytes: 1234,
   1.164 +                rxTotalBytes:  1234,
   1.165 +                txTotalBytes:  1234 };
   1.166 +
   1.167 +  netStatsDb.dbNewTxn("net_stats_store", "readwrite", function(txn, store) {
   1.168 +    netStatsDb._saveStats(txn, store, stats);
   1.169 +  }, function(error, result) {
   1.170 +    do_check_eq(error, null);
   1.171 +
   1.172 +    netStatsDb.logAllRecords(function(error, result) {
   1.173 +      do_check_eq(error, null);
   1.174 +      do_check_eq(result.length, 1);
   1.175 +      do_check_eq(result[0].appId, stats.appId);
   1.176 +      do_check_eq(result[0].serviceType, stats.serviceType);
   1.177 +      do_check_true(compareNetworks(result[0].network, stats.network));
   1.178 +      do_check_eq(result[0].timestamp, stats.timestamp);
   1.179 +      do_check_eq(result[0].rxBytes, stats.rxBytes);
   1.180 +      do_check_eq(result[0].txBytes, stats.txBytes);
   1.181 +      do_check_eq(result[0].rxSystemBytes, stats.rxSystemBytes);
   1.182 +      do_check_eq(result[0].txSystemBytes, stats.txSystemBytes);
   1.183 +      do_check_eq(result[0].rxTotalBytes, stats.rxTotalBytes);
   1.184 +      do_check_eq(result[0].txTotalBytes, stats.txTotalBytes);
   1.185 +      run_next_test();
   1.186 +    });
   1.187 +  });
   1.188 +});
   1.189 +
   1.190 +add_test(function test_internalSaveStats_arraySamples() {
   1.191 +  clearStore('net_stats_store', function() {
   1.192 +    var networks = getNetworks();
   1.193 +    var network = [networks[0].id, networks[0].type];
   1.194 +
   1.195 +    var samples = 2;
   1.196 +    var stats = [];
   1.197 +    for (var i = 0; i < samples; i++) {
   1.198 +      stats.push({ appId:         0,
   1.199 +                   serviceType:   "",
   1.200 +                   network:       network,
   1.201 +                   timestamp:     Date.now() + (10 * i),
   1.202 +                   rxBytes:       0,
   1.203 +                   txBytes:       0,
   1.204 +                   rxSystemBytes: 1234,
   1.205 +                   txSystemBytes: 1234,
   1.206 +                   rxTotalBytes:  1234,
   1.207 +                   txTotalBytes:  1234 });
   1.208 +    }
   1.209 +
   1.210 +    netStatsDb.dbNewTxn("net_stats_store", "readwrite", function(txn, store) {
   1.211 +      netStatsDb._saveStats(txn, store, stats);
   1.212 +    }, function(error, result) {
   1.213 +      do_check_eq(error, null);
   1.214 +
   1.215 +      netStatsDb.logAllRecords(function(error, result) {
   1.216 +        do_check_eq(error, null);
   1.217 +
   1.218 +        do_check_eq(result.length, samples);
   1.219 +        var success = true;
   1.220 +        for (var i = 0; i < samples; i++) {
   1.221 +          if (result[i].appId != stats[i].appId ||
   1.222 +              result[i].serviceType != stats[i].serviceType ||
   1.223 +              !compareNetworks(result[i].network, stats[i].network) ||
   1.224 +              result[i].timestamp != stats[i].timestamp ||
   1.225 +              result[i].rxBytes != stats[i].rxBytes ||
   1.226 +              result[i].txBytes != stats[i].txBytes ||
   1.227 +              result[i].rxSystemBytes != stats[i].rxSystemBytes ||
   1.228 +              result[i].txSystemBytes != stats[i].txSystemBytes ||
   1.229 +              result[i].rxTotalBytes != stats[i].rxTotalBytes ||
   1.230 +              result[i].txTotalBytes != stats[i].txTotalBytes) {
   1.231 +            success = false;
   1.232 +            break;
   1.233 +          }
   1.234 +        }
   1.235 +        do_check_true(success);
   1.236 +        run_next_test();
   1.237 +      });
   1.238 +    });
   1.239 +  });
   1.240 +});
   1.241 +
   1.242 +add_test(function test_internalRemoveOldStats() {
   1.243 +  clearStore('net_stats_store', function() {
   1.244 +    var networks = getNetworks();
   1.245 +    var network = [networks[0].id, networks[0].type];
   1.246 +    var samples = 10;
   1.247 +    var stats = [];
   1.248 +    for (var i = 0; i < samples - 1; i++) {
   1.249 +      stats.push({ appId:               0, serviceType: "",
   1.250 +                   network:       network, timestamp:     Date.now() + (10 * i),
   1.251 +                   rxBytes:             0, txBytes:       0,
   1.252 +                   rxSystemBytes:    1234, txSystemBytes: 1234,
   1.253 +                   rxTotalBytes:     1234, txTotalBytes:  1234 });
   1.254 +    }
   1.255 +
   1.256 +    stats.push({ appId:               0, serviceType: "",
   1.257 +                 network:       network, timestamp:     Date.now() + (10 * samples),
   1.258 +                 rxBytes:             0, txBytes:       0,
   1.259 +                 rxSystemBytes:    1234, txSystemBytes: 1234,
   1.260 +                 rxTotalBytes:     1234, txTotalBytes:  1234 });
   1.261 +
   1.262 +    netStatsDb.dbNewTxn("net_stats_store", "readwrite", function(txn, store) {
   1.263 +      netStatsDb._saveStats(txn, store, stats);
   1.264 +      var date = stats[stats.length - 1].timestamp
   1.265 +                 + (netStatsDb.sampleRate * netStatsDb.maxStorageSamples - 1) - 1;
   1.266 +      netStatsDb._removeOldStats(txn, store, 0, "", network, date);
   1.267 +    }, function(error, result) {
   1.268 +      do_check_eq(error, null);
   1.269 +
   1.270 +      netStatsDb.logAllRecords(function(error, result) {
   1.271 +        do_check_eq(error, null);
   1.272 +        do_check_eq(result.length, 1);
   1.273 +
   1.274 +        run_next_test();
   1.275 +      });
   1.276 +    });
   1.277 +  });
   1.278 +});
   1.279 +
   1.280 +function processSamplesDiff(networks, lastStat, newStat, callback) {
   1.281 +  clearStore('net_stats_store', function() {
   1.282 +    netStatsDb.dbNewTxn("net_stats_store", "readwrite", function(txn, store) {
   1.283 +      netStatsDb._saveStats(txn, store, lastStat);
   1.284 +    }, function(error, result) {
   1.285 +      netStatsDb.dbNewTxn("net_stats_store", "readwrite", function(txn, store) {
   1.286 +        let request = store.index("network").openCursor(newStat.network, "prev");
   1.287 +        request.onsuccess = function onsuccess(event) {
   1.288 +          let cursor = event.target.result;
   1.289 +          do_check_neq(cursor, null);
   1.290 +          netStatsDb._processSamplesDiff(txn, store, cursor, newStat, true);
   1.291 +        };
   1.292 +      }, function(error, result) {
   1.293 +        do_check_eq(error, null);
   1.294 +        netStatsDb.logAllRecords(function(error, result) {
   1.295 +          do_check_eq(error, null);
   1.296 +          callback(result);
   1.297 +        });
   1.298 +      });
   1.299 +    });
   1.300 +  });
   1.301 +}
   1.302 +
   1.303 +add_test(function test_processSamplesDiffSameSample() {
   1.304 +  var networks = getNetworks();
   1.305 +  var network = [networks[0].id, networks[0].type];
   1.306 +
   1.307 +  var sampleRate = netStatsDb.sampleRate;
   1.308 +  var date = filterTimestamp(new Date());
   1.309 +
   1.310 +  var lastStat = { appId:               0, serviceType:   "",
   1.311 +                   network:       network, timestamp:     date,
   1.312 +                   rxBytes:             0, txBytes:       0,
   1.313 +                   rxSystemBytes:    1234, txSystemBytes: 1234,
   1.314 +                   rxTotalBytes:     2234, txTotalBytes:  2234 };
   1.315 +
   1.316 +  var newStat = { appId:               0, serviceType:   "",
   1.317 +                  network:       network, timestamp:     date,
   1.318 +                  rxBytes:             0, txBytes:       0,
   1.319 +                  rxSystemBytes:    2234, txSystemBytes: 2234,
   1.320 +                  rxTotalBytes:     2234, txTotalBytes:  2234 };
   1.321 +
   1.322 +  processSamplesDiff(networks, lastStat, newStat, function(result) {
   1.323 +    do_check_eq(result.length, 1);
   1.324 +    do_check_eq(result[0].appId, newStat.appId);
   1.325 +    do_check_eq(result[0].serviceType, newStat.serviceType);
   1.326 +    do_check_true(compareNetworks(result[0].network, newStat.network));
   1.327 +    do_check_eq(result[0].timestamp, newStat.timestamp);
   1.328 +    do_check_eq(result[0].rxBytes, newStat.rxSystemBytes - lastStat.rxSystemBytes);
   1.329 +    do_check_eq(result[0].txBytes, newStat.txSystemBytes - lastStat.txSystemBytes);
   1.330 +    do_check_eq(result[0].rxTotalBytes, lastStat.rxTotalBytes + newStat.rxSystemBytes - lastStat.rxSystemBytes);
   1.331 +    do_check_eq(result[0].txTotalBytes, lastStat.txTotalBytes + newStat.txSystemBytes - lastStat.txSystemBytes);
   1.332 +    do_check_eq(result[0].rxSystemBytes, newStat.rxSystemBytes);
   1.333 +    do_check_eq(result[0].txSystemBytes, newStat.txSystemBytes);
   1.334 +    run_next_test();
   1.335 +  });
   1.336 +});
   1.337 +
   1.338 +add_test(function test_processSamplesDiffNextSample() {
   1.339 +  var networks = getNetworks();
   1.340 +  var network = [networks[0].id, networks[0].type];
   1.341 +
   1.342 +  var sampleRate = netStatsDb.sampleRate;
   1.343 +  var date = filterTimestamp(new Date());
   1.344 +
   1.345 +  var lastStat = { appId:               0, serviceType:  "",
   1.346 +                   network:       network, timestamp:     date,
   1.347 +                   rxBytes:             0, txBytes:       0,
   1.348 +                   rxSystemBytes:    1234, txSystemBytes: 1234,
   1.349 +                   rxTotalBytes:     2234, txTotalBytes:  2234 };
   1.350 +
   1.351 +  var newStat = { appId:               0, serviceType:  "",
   1.352 +                  network:       network, timestamp:     date + sampleRate,
   1.353 +                  rxBytes:             0, txBytes:       0,
   1.354 +                  rxSystemBytes:    1734, txSystemBytes: 1734,
   1.355 +                  rxTotalBytes:        0, txTotalBytes:  0 };
   1.356 +
   1.357 +  processSamplesDiff(networks, lastStat, newStat, function(result) {
   1.358 +    do_check_eq(result.length, 2);
   1.359 +    do_check_eq(result[1].appId, newStat.appId);
   1.360 +    do_check_eq(result[1].serviceType, newStat.serviceType);
   1.361 +    do_check_true(compareNetworks(result[1].network, newStat.network));
   1.362 +    do_check_eq(result[1].timestamp, newStat.timestamp);
   1.363 +    do_check_eq(result[1].rxBytes, newStat.rxSystemBytes - lastStat.rxSystemBytes);
   1.364 +    do_check_eq(result[1].txBytes, newStat.txSystemBytes - lastStat.txSystemBytes);
   1.365 +    do_check_eq(result[1].rxSystemBytes, newStat.rxSystemBytes);
   1.366 +    do_check_eq(result[1].txSystemBytes, newStat.txSystemBytes);
   1.367 +    do_check_eq(result[1].rxTotalBytes, lastStat.rxTotalBytes + newStat.rxSystemBytes - lastStat.rxSystemBytes);
   1.368 +    do_check_eq(result[1].txTotalBytes, lastStat.txTotalBytes + newStat.txSystemBytes - lastStat.txSystemBytes);
   1.369 +    run_next_test();
   1.370 +  });
   1.371 +});
   1.372 +
   1.373 +add_test(function test_processSamplesDiffSamplesLost() {
   1.374 +  var networks = getNetworks();
   1.375 +  var network = [networks[0].id, networks[0].type];
   1.376 +  var samples = 5;
   1.377 +  var sampleRate = netStatsDb.sampleRate;
   1.378 +  var date = filterTimestamp(new Date());
   1.379 +  var lastStat = { appId:              0, serviceType:  "",
   1.380 +                   network:      network, timestamp:     date,
   1.381 +                   rxBytes:            0, txBytes:       0,
   1.382 +                   rxSystemBytes:   1234, txSystemBytes: 1234,
   1.383 +                   rxTotalBytes:    2234, txTotalBytes:  2234};
   1.384 +
   1.385 +  var newStat = { appId:               0, serviceType:  "",
   1.386 +                  network:       network, timestamp:     date + (sampleRate * samples),
   1.387 +                  rxBytes:             0, txBytes:       0,
   1.388 +                  rxSystemBytes:    2234, txSystemBytes: 2234,
   1.389 +                  rxTotalBytes:        0, txTotalBytes:  0 };
   1.390 +
   1.391 +  processSamplesDiff(networks, lastStat, newStat, function(result) {
   1.392 +    do_check_eq(result.length, samples + 1);
   1.393 +    do_check_eq(result[0].appId, newStat.appId);
   1.394 +    do_check_eq(result[0].serviceType, newStat.serviceType);
   1.395 +    do_check_true(compareNetworks(result[samples].network, newStat.network));
   1.396 +    do_check_eq(result[samples].timestamp, newStat.timestamp);
   1.397 +    do_check_eq(result[samples].rxBytes, newStat.rxTotalBytes - lastStat.rxTotalBytes);
   1.398 +    do_check_eq(result[samples].txBytes, newStat.txTotalBytes - lastStat.txTotalBytes);
   1.399 +    do_check_eq(result[samples].rxSystemBytes, newStat.rxSystemBytes);
   1.400 +    do_check_eq(result[samples].txSystemBytes, newStat.txSystemBytes);
   1.401 +    do_check_eq(result[samples].rxTotalBytes, lastStat.rxTotalBytes + newStat.rxSystemBytes - lastStat.rxSystemBytes);
   1.402 +    do_check_eq(result[samples].txTotalBytes, lastStat.txTotalBytes + newStat.txSystemBytes - lastStat.txSystemBytes);
   1.403 +    run_next_test();
   1.404 +  });
   1.405 +});
   1.406 +
   1.407 +add_test(function test_saveStats() {
   1.408 +  var networks = getNetworks();
   1.409 +  var network = [networks[0].id, networks[0].type];
   1.410 +
   1.411 +  var stats = { appId:          0,
   1.412 +                serviceType:    "",
   1.413 +                networkId:      networks[0].id,
   1.414 +                networkType:    networks[0].type,
   1.415 +                date:           new Date(),
   1.416 +                rxBytes:        2234,
   1.417 +                txBytes:        2234,
   1.418 +                isAccumulative: true };
   1.419 +
   1.420 +  clearStore('net_stats_store', function() {
   1.421 +    netStatsDb.saveStats(stats, function(error, result) {
   1.422 +      do_check_eq(error, null);
   1.423 +      netStatsDb.logAllRecords(function(error, result) {
   1.424 +        do_check_eq(error, null);
   1.425 +        do_check_eq(result.length, 1);
   1.426 +        do_check_eq(result[0].appId, stats.appId);
   1.427 +        do_check_eq(result[0].serviceType, stats.serviceType);
   1.428 +        do_check_true(compareNetworks(result[0].network, network));
   1.429 +        let timestamp = filterTimestamp(stats.date);
   1.430 +        do_check_eq(result[0].timestamp, timestamp);
   1.431 +        do_check_eq(result[0].rxBytes, stats.rxBytes);
   1.432 +        do_check_eq(result[0].txBytes, stats.txBytes);
   1.433 +        do_check_eq(result[0].rxSystemBytes, stats.rxBytes);
   1.434 +        do_check_eq(result[0].txSystemBytes, stats.txBytes);
   1.435 +        do_check_eq(result[0].rxTotalBytes, stats.rxBytes);
   1.436 +        do_check_eq(result[0].txTotalBytes, stats.txBytes);
   1.437 +        run_next_test();
   1.438 +      });
   1.439 +    });
   1.440 +  });
   1.441 +});
   1.442 +
   1.443 +add_test(function test_saveAppStats() {
   1.444 +  var networks = getNetworks();
   1.445 +  var network = [networks[0].id, networks[0].type];
   1.446 +
   1.447 +  var stats = { appId:          1,
   1.448 +                serviceType:    "",
   1.449 +                networkId:      networks[0].id,
   1.450 +                networkType:    networks[0].type,
   1.451 +                date:           new Date(),
   1.452 +                rxBytes:        2234,
   1.453 +                txBytes:        2234,
   1.454 +                isAccumulative: false };
   1.455 +
   1.456 +  clearStore('net_stats_store', function() {
   1.457 +    netStatsDb.saveStats(stats, function(error, result) {
   1.458 +      do_check_eq(error, null);
   1.459 +      netStatsDb.logAllRecords(function(error, result) {
   1.460 +        do_check_eq(error, null);
   1.461 +        do_check_eq(result.length, 1);
   1.462 +        do_check_eq(result[0].appId, stats.appId);
   1.463 +        do_check_eq(result[0].serviceType, stats.serviceType);
   1.464 +        do_check_true(compareNetworks(result[0].network, network));
   1.465 +        let timestamp = filterTimestamp(stats.date);
   1.466 +        do_check_eq(result[0].timestamp, timestamp);
   1.467 +        do_check_eq(result[0].rxBytes, stats.rxBytes);
   1.468 +        do_check_eq(result[0].txBytes, stats.txBytes);
   1.469 +        do_check_eq(result[0].rxSystemBytes, 0);
   1.470 +        do_check_eq(result[0].txSystemBytes, 0);
   1.471 +        do_check_eq(result[0].rxTotalBytes, 0);
   1.472 +        do_check_eq(result[0].txTotalBytes, 0);
   1.473 +        run_next_test();
   1.474 +      });
   1.475 +    });
   1.476 +  });
   1.477 +});
   1.478 +
   1.479 +add_test(function test_saveServiceStats() {
   1.480 +  var networks = getNetworks();
   1.481 +  var network = [networks[0].id, networks[0].type];
   1.482 +
   1.483 +  var stats = { appId:          0,
   1.484 +                serviceType:    "FakeType",
   1.485 +                networkId:      networks[0].id,
   1.486 +                networkType:    networks[0].type,
   1.487 +                date:           new Date(),
   1.488 +                rxBytes:        2234,
   1.489 +                txBytes:        2234,
   1.490 +                isAccumulative: false };
   1.491 +
   1.492 +  clearStore('net_stats_store', function() {
   1.493 +    netStatsDb.saveStats(stats, function(error, result) {
   1.494 +      do_check_eq(error, null);
   1.495 +      netStatsDb.logAllRecords(function(error, result) {
   1.496 +        do_check_eq(error, null);
   1.497 +        do_check_eq(result.length, 1);
   1.498 +        do_check_eq(result[0].appId, stats.appId);
   1.499 +        do_check_eq(result[0].serviceType, stats.serviceType);
   1.500 +        do_check_true(compareNetworks(result[0].network, network));
   1.501 +        let timestamp = filterTimestamp(stats.date);
   1.502 +        do_check_eq(result[0].timestamp, timestamp);
   1.503 +        do_check_eq(result[0].rxBytes, stats.rxBytes);
   1.504 +        do_check_eq(result[0].txBytes, stats.txBytes);
   1.505 +        do_check_eq(result[0].rxSystemBytes, 0);
   1.506 +        do_check_eq(result[0].txSystemBytes, 0);
   1.507 +        do_check_eq(result[0].rxTotalBytes, 0);
   1.508 +        do_check_eq(result[0].txTotalBytes, 0);
   1.509 +        run_next_test();
   1.510 +      });
   1.511 +    });
   1.512 +  });
   1.513 +});
   1.514 +
   1.515 +function prepareFind(stats, callback) {
   1.516 +  clearStore('net_stats_store', function() {
   1.517 +    netStatsDb.dbNewTxn("net_stats_store", "readwrite", function(txn, store) {
   1.518 +      netStatsDb._saveStats(txn, store, stats);
   1.519 +    }, function(error, result) {
   1.520 +        callback(error, result);
   1.521 +    });
   1.522 +  });
   1.523 +}
   1.524 +
   1.525 +add_test(function test_find () {
   1.526 +  var networks = getNetworks();
   1.527 +  var networkWifi = [networks[0].id, networks[0].type];
   1.528 +  var networkMobile = [networks[1].id, networks[1].type]; // Fake mobile interface
   1.529 +  var appId = 0;
   1.530 +  var serviceType = "";
   1.531 +
   1.532 +  var samples = 5;
   1.533 +  var sampleRate = netStatsDb.sampleRate;
   1.534 +  var start = Date.now();
   1.535 +  var saveDate = filterTimestamp(new Date());
   1.536 +  var end = new Date(start + (sampleRate * (samples - 1)));
   1.537 +  start = new Date(start - sampleRate);
   1.538 +  var stats = [];
   1.539 +  for (var i = 0; i < samples; i++) {
   1.540 +    stats.push({ appId:               appId, serviceType:   serviceType,
   1.541 +                 network:       networkWifi, timestamp:     saveDate + (sampleRate * i),
   1.542 +                 rxBytes:                 0, txBytes:       10,
   1.543 +                 rxSystemBytes:           0, txSystemBytes: 0,
   1.544 +                 rxTotalBytes:            0, txTotalBytes:  0 });
   1.545 +
   1.546 +
   1.547 +    stats.push({ appId:                 appId, serviceType:   serviceType,
   1.548 +                 network:       networkMobile, timestamp:     saveDate + (sampleRate * i),
   1.549 +                 rxBytes:                   0, txBytes:       10,
   1.550 +                 rxSystemBytes:             0, txSystemBytes: 0,
   1.551 +                 rxTotalBytes:              0, txTotalBytes:  0 });
   1.552 +  }
   1.553 +
   1.554 +  prepareFind(stats, function(error, result) {
   1.555 +    do_check_eq(error, null);
   1.556 +    netStatsDb.find(function (error, result) {
   1.557 +      do_check_eq(error, null);
   1.558 +      do_check_eq(result.serviceType, serviceType);
   1.559 +      do_check_eq(result.network.id, networks[0].id);
   1.560 +      do_check_eq(result.network.type, networks[0].type);
   1.561 +      do_check_eq(result.start.getTime(), start.getTime());
   1.562 +      do_check_eq(result.end.getTime(), end.getTime());
   1.563 +      do_check_eq(result.data.length, samples + 1);
   1.564 +      do_check_eq(result.data[0].rxBytes, null);
   1.565 +      do_check_eq(result.data[1].rxBytes, 0);
   1.566 +      do_check_eq(result.data[samples].rxBytes, 0);
   1.567 +      run_next_test();
   1.568 +    }, appId, serviceType, networks[0], start, end);
   1.569 +  });
   1.570 +});
   1.571 +
   1.572 +add_test(function test_findAppStats () {
   1.573 +  var networks = getNetworks();
   1.574 +  var networkWifi = [networks[0].id, networks[0].type];
   1.575 +  var networkMobile = [networks[1].id, networks[1].type]; // Fake mobile interface
   1.576 +  var appId = 1;
   1.577 +  var serviceType = "";
   1.578 +
   1.579 +  var samples = 5;
   1.580 +  var sampleRate = netStatsDb.sampleRate;
   1.581 +  var start = Date.now();
   1.582 +  var saveDate = filterTimestamp(new Date());
   1.583 +  var end = new Date(start + (sampleRate * (samples - 1)));
   1.584 +  start = new Date(start - sampleRate);
   1.585 +  var stats = [];
   1.586 +  for (var i = 0; i < samples; i++) {
   1.587 +    stats.push({ appId:              appId, serviceType:  serviceType,
   1.588 +                 network:      networkWifi, timestamp:    saveDate + (sampleRate * i),
   1.589 +                 rxBytes:                0, txBytes:      10,
   1.590 +                 rxTotalBytes:           0, txTotalBytes: 0 });
   1.591 +
   1.592 +    stats.push({ appId:                appId, serviceType:  serviceType,
   1.593 +                 network:      networkMobile, timestamp:    saveDate + (sampleRate * i),
   1.594 +                 rxBytes:                  0, txBytes:      10,
   1.595 +                 rxTotalBytes:             0, txTotalBytes: 0 });
   1.596 +  }
   1.597 +
   1.598 +  prepareFind(stats, function(error, result) {
   1.599 +    do_check_eq(error, null);
   1.600 +    netStatsDb.find(function (error, result) {
   1.601 +      do_check_eq(error, null);
   1.602 +      do_check_eq(result.serviceType, serviceType);
   1.603 +      do_check_eq(result.network.id, networks[0].id);
   1.604 +      do_check_eq(result.network.type, networks[0].type);
   1.605 +      do_check_eq(result.start.getTime(), start.getTime());
   1.606 +      do_check_eq(result.end.getTime(), end.getTime());
   1.607 +      do_check_eq(result.data.length, samples + 1);
   1.608 +      do_check_eq(result.data[0].rxBytes, null);
   1.609 +      do_check_eq(result.data[1].rxBytes, 0);
   1.610 +      do_check_eq(result.data[samples].rxBytes, 0);
   1.611 +      run_next_test();
   1.612 +    }, appId, serviceType, networks[0], start, end);
   1.613 +  });
   1.614 +});
   1.615 +
   1.616 +add_test(function test_findServiceStats () {
   1.617 +  var networks = getNetworks();
   1.618 +  var networkWifi = [networks[0].id, networks[0].type];
   1.619 +  var networkMobile = [networks[1].id, networks[1].type]; // Fake mobile interface
   1.620 +  var appId = 0;
   1.621 +  var serviceType = "FakeType";
   1.622 +
   1.623 +  var samples = 5;
   1.624 +  var sampleRate = netStatsDb.sampleRate;
   1.625 +  var start = Date.now();
   1.626 +  var saveDate = filterTimestamp(new Date());
   1.627 +  var end = new Date(start + (sampleRate * (samples - 1)));
   1.628 +  start = new Date(start - sampleRate);
   1.629 +  var stats = [];
   1.630 +  for (var i = 0; i < samples; i++) {
   1.631 +    stats.push({ appId:              appId, serviceType:  serviceType,
   1.632 +                 network:      networkWifi, timestamp:    saveDate + (sampleRate * i),
   1.633 +                 rxBytes:                0, txBytes:      10,
   1.634 +                 rxTotalBytes:           0, txTotalBytes: 0 });
   1.635 +
   1.636 +    stats.push({ appId:                appId, serviceType:  serviceType,
   1.637 +                 network:      networkMobile, timestamp:    saveDate + (sampleRate * i),
   1.638 +                 rxBytes:                  0, txBytes:      10,
   1.639 +                 rxTotalBytes:             0, txTotalBytes: 0 });
   1.640 +  }
   1.641 +
   1.642 +  prepareFind(stats, function(error, result) {
   1.643 +    do_check_eq(error, null);
   1.644 +    netStatsDb.find(function (error, result) {
   1.645 +      do_check_eq(error, null);
   1.646 +      do_check_eq(result.serviceType, serviceType);
   1.647 +      do_check_eq(result.network.id, networks[0].id);
   1.648 +      do_check_eq(result.network.type, networks[0].type);
   1.649 +      do_check_eq(result.start.getTime(), start.getTime());
   1.650 +      do_check_eq(result.end.getTime(), end.getTime());
   1.651 +      do_check_eq(result.data.length, samples + 1);
   1.652 +      do_check_eq(result.data[0].rxBytes, null);
   1.653 +      do_check_eq(result.data[1].rxBytes, 0);
   1.654 +      do_check_eq(result.data[samples].rxBytes, 0);
   1.655 +      run_next_test();
   1.656 +    }, appId, serviceType, networks[0], start, end);
   1.657 +  });
   1.658 +});
   1.659 +
   1.660 +add_test(function test_saveMultipleAppStats () {
   1.661 +  var networks = getNetworks();
   1.662 +  var networkWifi = networks[0];
   1.663 +  var networkMobile = networks[1]; // Fake mobile interface
   1.664 +
   1.665 +  var saveDate = filterTimestamp(new Date());
   1.666 +  var cached = Object.create(null);
   1.667 +  var serviceType = "FakeType";
   1.668 +  var wifiNetId = networkWifi.id + '' + networkWifi.type;
   1.669 +  var mobileNetId = networkMobile.id + '' + networkMobile.type;
   1.670 +
   1.671 +  cached[0 + '' + serviceType + wifiNetId] = {
   1.672 +    appId:                    0, date:           new Date(),
   1.673 +    networkId:   networkWifi.id, networkType:    networkWifi.type,
   1.674 +    rxBytes:                  0, txBytes:        10,
   1.675 +    serviceType:    serviceType, isAccumulative: false
   1.676 +  };
   1.677 +
   1.678 +  cached[0 + '' + serviceType + mobileNetId] = {
   1.679 +    appId:                    0, date:           new Date(),
   1.680 +    networkId: networkMobile.id, networkType:    networkMobile.type,
   1.681 +    rxBytes:                  0, txBytes:        10,
   1.682 +    serviceType:    serviceType, isAccumulative: false
   1.683 +  };
   1.684 +
   1.685 +  cached[1 + '' + wifiNetId] = {
   1.686 +    appId:                    1, date:           new Date(),
   1.687 +    networkId:   networkWifi.id, networkType:    networkWifi.type,
   1.688 +    rxBytes:                  0, txBytes:        10,
   1.689 +    serviceType:             "", isAccumulative: false
   1.690 +  };
   1.691 +
   1.692 +  cached[1 + '' + mobileNetId] = {
   1.693 +    appId:                    1, date:           new Date(),
   1.694 +    networkId: networkMobile.id, networkType:    networkMobile.type,
   1.695 +    rxBytes:                  0, txBytes:        10,
   1.696 +    serviceType:             "", isAccumulative: false
   1.697 +  };
   1.698 +
   1.699 +  cached[2 + '' + wifiNetId] = {
   1.700 +    appId:                    2, date:           new Date(),
   1.701 +    networkId:   networkWifi.id, networkType:    networkWifi.type,
   1.702 +    rxBytes:                  0, txBytes:        10,
   1.703 +    serviceType:             "", isAccumulative: false
   1.704 +  };
   1.705 +
   1.706 +  cached[2 + '' + mobileNetId] = {
   1.707 +    appId:                    2, date:           new Date(),
   1.708 +    networkId: networkMobile.id, networkType:    networkMobile.type,
   1.709 +    rxBytes:                  0, txBytes:        10,
   1.710 +    serviceType:             "", isAccumulative: false
   1.711 +  };
   1.712 +
   1.713 +  let keys = Object.keys(cached);
   1.714 +  let index = 0;
   1.715 +
   1.716 +  networks.push(networkMobile);
   1.717 +
   1.718 +  clearStore('net_stats_store', function() {
   1.719 +    netStatsDb.saveStats(cached[keys[index]],
   1.720 +      function callback(error, result) {
   1.721 +        do_check_eq(error, null);
   1.722 +
   1.723 +        if (index == keys.length - 1) {
   1.724 +          netStatsDb.logAllRecords(function(error, result) {
   1.725 +            do_check_eq(error, null);
   1.726 +            do_check_eq(result.length, 6);
   1.727 +            do_check_eq(result[0].serviceType, serviceType);
   1.728 +            do_check_eq(result[3].appId, 1);
   1.729 +            do_check_true(compareNetworks(result[0].network, [networkWifi.id, networkWifi.type]));
   1.730 +            do_check_eq(result[0].rxBytes, 0);
   1.731 +            do_check_eq(result[0].txBytes, 10);
   1.732 +            run_next_test();
   1.733 +          });
   1.734 +         return;
   1.735 +        }
   1.736 +
   1.737 +        index += 1;
   1.738 +        netStatsDb.saveStats(cached[keys[index]], callback);
   1.739 +    });
   1.740 +  });
   1.741 +});
   1.742 +
   1.743 +var networkWifi = '00';
   1.744 +var networkMobile = '11';
   1.745 +
   1.746 +var examplePageURL = "http://example.com/index.html";
   1.747 +var exampleManifestURL = "http://example.com/manifest.webapp";
   1.748 +
   1.749 +var testPageURL = "http://test.com/index.html";
   1.750 +var testManifestURL = "http://test.com/manifest.webapp";
   1.751 +
   1.752 +var alarms = [{ id:                null,
   1.753 +                networkId:         networkWifi,
   1.754 +                absoluteThreshold: 10000,
   1.755 +                relativeThreshold: 10000,
   1.756 +                data:              {foo: "something"},
   1.757 +                pageURL:           examplePageURL,
   1.758 +                manifestURL:       exampleManifestURL },
   1.759 +              { id:                null,
   1.760 +                networkId:         networkWifi,
   1.761 +                absoluteThreshold: 1000,
   1.762 +                relativeThreshold: 1000,
   1.763 +                data:              {foo: "else"},
   1.764 +                pageURL:           examplePageURL,
   1.765 +                manifestURL:       exampleManifestURL },
   1.766 +              { id:                null,
   1.767 +                networkId:         networkMobile,
   1.768 +                absoluteThreshold: 100,
   1.769 +                relativeThreshold: 100,
   1.770 +                data:              {foo: "to"},
   1.771 +                pageURL:           examplePageURL,
   1.772 +                manifestURL:       exampleManifestURL },
   1.773 +              { id:                null,
   1.774 +                networkId:         networkMobile,
   1.775 +                absoluteThreshold: 10,
   1.776 +                relativeThreshold: 10,
   1.777 +                data:              {foo: "test"},
   1.778 +                pageURL:           testPageURL,
   1.779 +                manifestURL:       testManifestURL }];
   1.780 +
   1.781 +var alarmsDbId = 1;
   1.782 +
   1.783 +add_test(function test_addAlarm() {
   1.784 +  // Add alarms[0] -> DB: [ alarms[0] (id: 1) ]
   1.785 +  // Check the insertion is OK.
   1.786 +  netStatsDb.addAlarm(alarms[0], function(error, result) {
   1.787 +    do_check_eq(error, null);
   1.788 +    alarmsDbId = result;
   1.789 +    netStatsDb.getAlarms(Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, exampleManifestURL, function(error, result) {
   1.790 +      do_check_eq(error, null);
   1.791 +      do_check_eq(result.length, 1);
   1.792 +      do_check_eq(result[0].id, alarmsDbId);
   1.793 +      do_check_eq(result[0].networkId, alarms[0].networkId);
   1.794 +      do_check_eq(result[0].absoluteThreshold, alarms[0].absoluteThreshold);
   1.795 +      do_check_eq(result[0].relativeThreshold, alarms[0].relativeThreshold);
   1.796 +      do_check_eq(result[0].data.foo, alarms[0].data.foo);
   1.797 +      run_next_test();
   1.798 +    });
   1.799 +  });
   1.800 +});
   1.801 +
   1.802 +add_test(function test_getFirstAlarm() {
   1.803 +  // Add alarms[1] -> DB: [ alarms[0] (id: 1), alarms[1] (id: 2) ]
   1.804 +  // Check first alarm is alarms[1] because threshold is lower.
   1.805 +  alarmsDbId += 1;
   1.806 +  netStatsDb.addAlarm(alarms[1], function (error, result) {
   1.807 +    do_check_eq(error, null);
   1.808 +    do_check_eq(result, alarmsDbId);
   1.809 +    netStatsDb.getFirstAlarm(networkWifi, function(error, result) {
   1.810 +      do_check_eq(error, null);
   1.811 +      do_check_eq(result.id, alarmsDbId);
   1.812 +      do_check_eq(result.networkId, alarms[1].networkId);
   1.813 +      do_check_eq(result.absoluteThreshold, alarms[1].absoluteThreshold);
   1.814 +      do_check_eq(result.relativeThreshold, alarms[1].relativeThreshold);
   1.815 +      do_check_eq(result.data.foo, alarms[1].data.foo);
   1.816 +      do_check_eq(result.pageURL, alarms[1].pageURL);
   1.817 +      do_check_eq(result.manifestURL, alarms[1].manifestURL);
   1.818 +      run_next_test();
   1.819 +    });
   1.820 +  });
   1.821 +});
   1.822 +
   1.823 +add_test(function test_removeAlarm() {
   1.824 +  // Remove alarms[1] (id: 2) -> DB: [ alarms[0] (id: 1) ]
   1.825 +  // Check get first return alarms[0].
   1.826 +  netStatsDb.removeAlarm(alarmsDbId, alarms[0].manifestURL, function (error, result) {
   1.827 +    do_check_eq(error, null);
   1.828 +    netStatsDb.getFirstAlarm(networkWifi, function(error, result) {
   1.829 +      do_check_eq(error, null);
   1.830 +      do_check_eq(result.id, alarmsDbId - 1);
   1.831 +      do_check_eq(result.networkId, alarms[0].networkId);
   1.832 +      do_check_eq(result.absoluteThreshold, alarms[0].absoluteThreshold);
   1.833 +      do_check_eq(result.relativeThreshold, alarms[0].relativeThreshold);
   1.834 +      do_check_eq(result.data.foo, alarms[0].data.foo);
   1.835 +      do_check_eq(result.pageURL, alarms[0].pageURL);
   1.836 +      do_check_eq(result.manifestURL, alarms[0].manifestURL);
   1.837 +      run_next_test();
   1.838 +    });
   1.839 +  });
   1.840 +});
   1.841 +
   1.842 +add_test(function test_removeAppAlarm() {
   1.843 +  // Remove alarms[0] (id: 1) -> DB: [ ]
   1.844 +  netStatsDb.removeAlarm(alarmsDbId - 1, alarms[0].manifestURL, function (error, result) {
   1.845 +    do_check_eq(error, null);
   1.846 +    netStatsDb.getAlarms(networkWifi, exampleManifestURL, function(error, result) {
   1.847 +      do_check_eq(error, null);
   1.848 +      do_check_eq(result.length, 0);
   1.849 +      run_next_test();
   1.850 +    });
   1.851 +  });
   1.852 +});
   1.853 +
   1.854 +add_test(function test_getAlarms() {
   1.855 +  // Add all alarms -> DB: [ alarms[0] (id: 3),
   1.856 +  //                         alarms[1] (id: 4),
   1.857 +  //                         alarms[2] (id: 5),
   1.858 +  //                         alarms[3] (id: 6) ]
   1.859 +  // Check that getAlarms for wifi returns 2 alarms.
   1.860 +  // Check that getAlarms for all connections returns 3 alarms.
   1.861 +
   1.862 +  var callback = function () {
   1.863 +    netStatsDb.getAlarms(networkWifi, exampleManifestURL, function(error, result) {
   1.864 +      do_check_eq(error, null);
   1.865 +      do_check_eq(result.length, 2);
   1.866 +      netStatsDb.getAlarms(null, exampleManifestURL, function(error, result) {
   1.867 +        do_check_eq(error, null);
   1.868 +        do_check_eq(result.length, 3);
   1.869 +        run_next_test();
   1.870 +      });
   1.871 +    });
   1.872 +  };
   1.873 +
   1.874 +  var index = 0;
   1.875 +
   1.876 +  var addFunction = function () {
   1.877 +    alarmsDbId += 1;
   1.878 +    netStatsDb.addAlarm(alarms[index], function (error, result) {
   1.879 +      do_check_eq(error, null);
   1.880 +      index += 1;
   1.881 +      do_check_eq(result, alarmsDbId);
   1.882 +      if (index >= alarms.length) {
   1.883 +        callback();
   1.884 +        return;
   1.885 +      }
   1.886 +      addFunction();
   1.887 +    });
   1.888 +  };
   1.889 +
   1.890 +  addFunction();
   1.891 +});
   1.892 +
   1.893 +add_test(function test_removeAppAllAlarms() {
   1.894 +  // Remove all alarms for exampleManifestURL -> DB: [ alarms[3] (id: 6) ]
   1.895 +  netStatsDb.removeAlarms(exampleManifestURL, function (error, result) {
   1.896 +    do_check_eq(error, null);
   1.897 +    netStatsDb.getAlarms(null, exampleManifestURL, function(error, result) {
   1.898 +      do_check_eq(error, null);
   1.899 +      do_check_eq(result.length, 0);
   1.900 +      netStatsDb.getAlarms(null, testManifestURL, function(error, result) {
   1.901 +        do_check_eq(error, null);
   1.902 +        do_check_eq(result.length, 1);
   1.903 +        run_next_test();
   1.904 +      });
   1.905 +    });
   1.906 +  });
   1.907 +});
   1.908 +
   1.909 +add_test(function test_updateAlarm() {
   1.910 +  // Update alarms[3] (id: 6) -> DB: [ alarms[3]* (id: 6) ]
   1.911 +
   1.912 +  var updatedAlarm = alarms[1];
   1.913 +  updatedAlarm.id = alarmsDbId;
   1.914 +  updatedAlarm.threshold = 10;
   1.915 +
   1.916 +  netStatsDb.updateAlarm(updatedAlarm, function (error, result) {
   1.917 +    do_check_eq(error, null);
   1.918 +    netStatsDb.getFirstAlarm(networkWifi, function(error, result) {
   1.919 +      do_check_eq(error, null);
   1.920 +      do_check_eq(result.id, updatedAlarm.id);
   1.921 +      do_check_eq(result.networkId, updatedAlarm.networkId);
   1.922 +      do_check_eq(result.absoluteThreshold, updatedAlarm.absoluteThreshold);
   1.923 +      do_check_eq(result.relativeThreshold, updatedAlarm.relativeThreshold);
   1.924 +      do_check_eq(result.data.foo, updatedAlarm.data.foo);
   1.925 +      do_check_eq(result.pageURL, updatedAlarm.pageURL);
   1.926 +      do_check_eq(result.manifestURL, updatedAlarm.manifestURL);
   1.927 +      run_next_test();
   1.928 +    });
   1.929 +  });
   1.930 +});
   1.931 +
   1.932 +function run_test() {
   1.933 +  do_get_profile();
   1.934 +  run_next_test();
   1.935 +}

mercurial