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