browser/modules/test/browser_BrowserUITelemetry_buckets.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /*
     5     WHERE'S MAH BUCKET?!
     6           \
     7                      ___
     8                   .-9 9 `\
     9                 =(:(::)=  ;
    10                   ||||     \
    11                   ||||      `-.
    12                  ,\|\|         `,
    13                 /                \
    14                ;                  `'---.,
    15                |                         `\
    16                ;                     /     |
    17                \                    |      /
    18                 )           \  __,.--\    /
    19              .-' \,..._\     \`   .-'  .-'
    20             `-=``      `:    |  /-/-/`
    21                          `.__/
    22 */
    24 "use strict";
    27 function generatorTest() {
    28   let s = {};
    29   Components.utils.import("resource:///modules/BrowserUITelemetry.jsm", s);
    30   let BUIT = s.BrowserUITelemetry;
    32   registerCleanupFunction(function() {
    33     BUIT.setBucket(null);
    34   });
    37   // setBucket
    38   is(BUIT.currentBucket, BUIT.BUCKET_DEFAULT, "Bucket should be default bucket");
    39   BUIT.setBucket("mah-bucket");
    40   is(BUIT.currentBucket, BUIT.BUCKET_PREFIX + "mah-bucket", "Bucket should have correct name");
    41   BUIT.setBucket(null);
    42   is(BUIT.currentBucket, BUIT.BUCKET_DEFAULT, "Bucket should be reset to default");
    45   // _toTimeStr
    46   is(BUIT._toTimeStr(10), "10ms", "Checking time string reprentation, 10ms");
    47   is(BUIT._toTimeStr(1000 + 10), "1s10ms", "Checking time string reprentation, 1s10ms");
    48   is(BUIT._toTimeStr((20 * 1000) + 10), "20s10ms", "Checking time string reprentation, 20s10ms");
    49   is(BUIT._toTimeStr(60 * 1000), "1m", "Checking time string reprentation, 1m");
    50   is(BUIT._toTimeStr(3 * 60 * 1000), "3m", "Checking time string reprentation, 3m");
    51   is(BUIT._toTimeStr((3 * 60 * 1000) + 1), "3m1ms", "Checking time string reprentation, 3m1ms");
    52   is(BUIT._toTimeStr((60 * 60 * 1000) + (10 * 60 * 1000)), "1h10m", "Checking time string reprentation, 1h10m");
    53   is(BUIT._toTimeStr(100 * 60 * 60 * 1000), "100h", "Checking time string reprentation, 100h");
    56   // setExpiringBucket
    57   BUIT.setExpiringBucket("walrus", [1001, 2001, 3001, 10001]);
    58   is(BUIT.currentBucket, BUIT.BUCKET_PREFIX + "walrus" + BUIT.BUCKET_SEPARATOR + "1s1ms",
    59      "Bucket should be expiring and have time step of 1s1ms");
    61   waitForCondition(function() {
    62     return BUIT.currentBucket == (BUIT.BUCKET_PREFIX + "walrus" + BUIT.BUCKET_SEPARATOR + "2s1ms");
    63   }, nextStep, "Bucket should be expiring and have time step of 2s1ms");
    64   yield undefined;
    66   waitForCondition(function() {
    67     return BUIT.currentBucket == (BUIT.BUCKET_PREFIX + "walrus" + BUIT.BUCKET_SEPARATOR + "3s1ms");
    68   }, nextStep, "Bucket should be expiring and have time step of 3s1ms");
    69   yield undefined;
    72   // Interupt previous expiring bucket
    73   BUIT.setExpiringBucket("walrus2", [1002, 2002]);
    74   is(BUIT.currentBucket, BUIT.BUCKET_PREFIX + "walrus2" + BUIT.BUCKET_SEPARATOR + "1s2ms",
    75      "Should be new expiring bucket, with time step of 1s2ms");
    77   waitForCondition(function() {
    78     return BUIT.currentBucket == (BUIT.BUCKET_PREFIX + "walrus2" + BUIT.BUCKET_SEPARATOR + "2s2ms");
    79   }, nextStep, "Should be new expiring bucket, with time step of 2s2ms");
    80   yield undefined;
    83   // Let expiring bucket expire
    84   waitForCondition(function() {
    85     return BUIT.currentBucket == BUIT.BUCKET_DEFAULT;
    86   }, nextStep, "Bucket should have expired, default bucket should now be active");
    87   yield undefined;
    90   // Interupt expiring bucket with normal bucket
    91   BUIT.setExpiringBucket("walrus3", [1003, 2003]);
    92   is(BUIT.currentBucket, BUIT.BUCKET_PREFIX + "walrus3" + BUIT.BUCKET_SEPARATOR + "1s3ms",
    93      "Should be new expiring bucket, with time step of 1s3ms");
    95   BUIT.setBucket("mah-bucket");
    96   is(BUIT.currentBucket, BUIT.BUCKET_PREFIX + "mah-bucket", "Bucket should have correct name");
    98   waitForCondition(function() {
    99     return BUIT.currentBucket == (BUIT.BUCKET_PREFIX + "mah-bucket");
   100   }, nextStep, "Next step of old expiring bucket shouldn't have progressed");
   101   yield undefined;
   102 }

mercurial