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