browser/modules/test/browser_BrowserUITelemetry_buckets.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/modules/test/browser_BrowserUITelemetry_buckets.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,102 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/*
     1.8 +    WHERE'S MAH BUCKET?!
     1.9 +          \
    1.10 +                     ___
    1.11 +                  .-9 9 `\
    1.12 +                =(:(::)=  ;
    1.13 +                  ||||     \
    1.14 +                  ||||      `-.
    1.15 +                 ,\|\|         `,
    1.16 +                /                \
    1.17 +               ;                  `'---.,
    1.18 +               |                         `\
    1.19 +               ;                     /     |
    1.20 +               \                    |      /
    1.21 +                )           \  __,.--\    /
    1.22 +             .-' \,..._\     \`   .-'  .-'
    1.23 +            `-=``      `:    |  /-/-/`
    1.24 +                         `.__/
    1.25 +*/
    1.26 +
    1.27 +"use strict";
    1.28 +
    1.29 +
    1.30 +function generatorTest() {
    1.31 +  let s = {};
    1.32 +  Components.utils.import("resource:///modules/BrowserUITelemetry.jsm", s);
    1.33 +  let BUIT = s.BrowserUITelemetry;
    1.34 +
    1.35 +  registerCleanupFunction(function() {
    1.36 +    BUIT.setBucket(null);
    1.37 +  });
    1.38 +
    1.39 +
    1.40 +  // setBucket
    1.41 +  is(BUIT.currentBucket, BUIT.BUCKET_DEFAULT, "Bucket should be default bucket");
    1.42 +  BUIT.setBucket("mah-bucket");
    1.43 +  is(BUIT.currentBucket, BUIT.BUCKET_PREFIX + "mah-bucket", "Bucket should have correct name");
    1.44 +  BUIT.setBucket(null);
    1.45 +  is(BUIT.currentBucket, BUIT.BUCKET_DEFAULT, "Bucket should be reset to default");
    1.46 +
    1.47 +
    1.48 +  // _toTimeStr
    1.49 +  is(BUIT._toTimeStr(10), "10ms", "Checking time string reprentation, 10ms");
    1.50 +  is(BUIT._toTimeStr(1000 + 10), "1s10ms", "Checking time string reprentation, 1s10ms");
    1.51 +  is(BUIT._toTimeStr((20 * 1000) + 10), "20s10ms", "Checking time string reprentation, 20s10ms");
    1.52 +  is(BUIT._toTimeStr(60 * 1000), "1m", "Checking time string reprentation, 1m");
    1.53 +  is(BUIT._toTimeStr(3 * 60 * 1000), "3m", "Checking time string reprentation, 3m");
    1.54 +  is(BUIT._toTimeStr((3 * 60 * 1000) + 1), "3m1ms", "Checking time string reprentation, 3m1ms");
    1.55 +  is(BUIT._toTimeStr((60 * 60 * 1000) + (10 * 60 * 1000)), "1h10m", "Checking time string reprentation, 1h10m");
    1.56 +  is(BUIT._toTimeStr(100 * 60 * 60 * 1000), "100h", "Checking time string reprentation, 100h");
    1.57 +
    1.58 +
    1.59 +  // setExpiringBucket
    1.60 +  BUIT.setExpiringBucket("walrus", [1001, 2001, 3001, 10001]);
    1.61 +  is(BUIT.currentBucket, BUIT.BUCKET_PREFIX + "walrus" + BUIT.BUCKET_SEPARATOR + "1s1ms",
    1.62 +     "Bucket should be expiring and have time step of 1s1ms");
    1.63 +
    1.64 +  waitForCondition(function() {
    1.65 +    return BUIT.currentBucket == (BUIT.BUCKET_PREFIX + "walrus" + BUIT.BUCKET_SEPARATOR + "2s1ms");
    1.66 +  }, nextStep, "Bucket should be expiring and have time step of 2s1ms");
    1.67 +  yield undefined;
    1.68 +
    1.69 +  waitForCondition(function() {
    1.70 +    return BUIT.currentBucket == (BUIT.BUCKET_PREFIX + "walrus" + BUIT.BUCKET_SEPARATOR + "3s1ms");
    1.71 +  }, nextStep, "Bucket should be expiring and have time step of 3s1ms");
    1.72 +  yield undefined;
    1.73 +
    1.74 +
    1.75 +  // Interupt previous expiring bucket
    1.76 +  BUIT.setExpiringBucket("walrus2", [1002, 2002]);
    1.77 +  is(BUIT.currentBucket, BUIT.BUCKET_PREFIX + "walrus2" + BUIT.BUCKET_SEPARATOR + "1s2ms",
    1.78 +     "Should be new expiring bucket, with time step of 1s2ms");
    1.79 +
    1.80 +  waitForCondition(function() {
    1.81 +    return BUIT.currentBucket == (BUIT.BUCKET_PREFIX + "walrus2" + BUIT.BUCKET_SEPARATOR + "2s2ms");
    1.82 +  }, nextStep, "Should be new expiring bucket, with time step of 2s2ms");
    1.83 +  yield undefined;
    1.84 +
    1.85 +
    1.86 +  // Let expiring bucket expire
    1.87 +  waitForCondition(function() {
    1.88 +    return BUIT.currentBucket == BUIT.BUCKET_DEFAULT;
    1.89 +  }, nextStep, "Bucket should have expired, default bucket should now be active");
    1.90 +  yield undefined;
    1.91 +
    1.92 +
    1.93 +  // Interupt expiring bucket with normal bucket
    1.94 +  BUIT.setExpiringBucket("walrus3", [1003, 2003]);
    1.95 +  is(BUIT.currentBucket, BUIT.BUCKET_PREFIX + "walrus3" + BUIT.BUCKET_SEPARATOR + "1s3ms",
    1.96 +     "Should be new expiring bucket, with time step of 1s3ms");
    1.97 +
    1.98 +  BUIT.setBucket("mah-bucket");
    1.99 +  is(BUIT.currentBucket, BUIT.BUCKET_PREFIX + "mah-bucket", "Bucket should have correct name");
   1.100 +
   1.101 +  waitForCondition(function() {
   1.102 +    return BUIT.currentBucket == (BUIT.BUCKET_PREFIX + "mah-bucket");
   1.103 +  }, nextStep, "Next step of old expiring bucket shouldn't have progressed");
   1.104 +  yield undefined;
   1.105 +}

mercurial