browser/modules/test/browser_BrowserUITelemetry_buckets.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:50bda9a1b7c3
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
3
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 */
23
24 "use strict";
25
26
27 function generatorTest() {
28 let s = {};
29 Components.utils.import("resource:///modules/BrowserUITelemetry.jsm", s);
30 let BUIT = s.BrowserUITelemetry;
31
32 registerCleanupFunction(function() {
33 BUIT.setBucket(null);
34 });
35
36
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");
43
44
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");
54
55
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");
60
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;
65
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;
70
71
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");
76
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;
81
82
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;
88
89
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");
94
95 BUIT.setBucket("mah-bucket");
96 is(BUIT.currentBucket, BUIT.BUCKET_PREFIX + "mah-bucket", "Bucket should have correct name");
97
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