michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /* michael@0: WHERE'S MAH BUCKET?! michael@0: \ michael@0: ___ michael@0: .-9 9 `\ michael@0: =(:(::)= ; michael@0: |||| \ michael@0: |||| `-. michael@0: ,\|\| `, michael@0: / \ michael@0: ; `'---., michael@0: | `\ michael@0: ; / | michael@0: \ | / michael@0: ) \ __,.--\ / michael@0: .-' \,..._\ \` .-' .-' michael@0: `-=`` `: | /-/-/` michael@0: `.__/ michael@0: */ michael@0: michael@0: "use strict"; michael@0: michael@0: michael@0: function generatorTest() { michael@0: let s = {}; michael@0: Components.utils.import("resource:///modules/BrowserUITelemetry.jsm", s); michael@0: let BUIT = s.BrowserUITelemetry; michael@0: michael@0: registerCleanupFunction(function() { michael@0: BUIT.setBucket(null); michael@0: }); michael@0: michael@0: michael@0: // setBucket michael@0: is(BUIT.currentBucket, BUIT.BUCKET_DEFAULT, "Bucket should be default bucket"); michael@0: BUIT.setBucket("mah-bucket"); michael@0: is(BUIT.currentBucket, BUIT.BUCKET_PREFIX + "mah-bucket", "Bucket should have correct name"); michael@0: BUIT.setBucket(null); michael@0: is(BUIT.currentBucket, BUIT.BUCKET_DEFAULT, "Bucket should be reset to default"); michael@0: michael@0: michael@0: // _toTimeStr michael@0: is(BUIT._toTimeStr(10), "10ms", "Checking time string reprentation, 10ms"); michael@0: is(BUIT._toTimeStr(1000 + 10), "1s10ms", "Checking time string reprentation, 1s10ms"); michael@0: is(BUIT._toTimeStr((20 * 1000) + 10), "20s10ms", "Checking time string reprentation, 20s10ms"); michael@0: is(BUIT._toTimeStr(60 * 1000), "1m", "Checking time string reprentation, 1m"); michael@0: is(BUIT._toTimeStr(3 * 60 * 1000), "3m", "Checking time string reprentation, 3m"); michael@0: is(BUIT._toTimeStr((3 * 60 * 1000) + 1), "3m1ms", "Checking time string reprentation, 3m1ms"); michael@0: is(BUIT._toTimeStr((60 * 60 * 1000) + (10 * 60 * 1000)), "1h10m", "Checking time string reprentation, 1h10m"); michael@0: is(BUIT._toTimeStr(100 * 60 * 60 * 1000), "100h", "Checking time string reprentation, 100h"); michael@0: michael@0: michael@0: // setExpiringBucket michael@0: BUIT.setExpiringBucket("walrus", [1001, 2001, 3001, 10001]); michael@0: is(BUIT.currentBucket, BUIT.BUCKET_PREFIX + "walrus" + BUIT.BUCKET_SEPARATOR + "1s1ms", michael@0: "Bucket should be expiring and have time step of 1s1ms"); michael@0: michael@0: waitForCondition(function() { michael@0: return BUIT.currentBucket == (BUIT.BUCKET_PREFIX + "walrus" + BUIT.BUCKET_SEPARATOR + "2s1ms"); michael@0: }, nextStep, "Bucket should be expiring and have time step of 2s1ms"); michael@0: yield undefined; michael@0: michael@0: waitForCondition(function() { michael@0: return BUIT.currentBucket == (BUIT.BUCKET_PREFIX + "walrus" + BUIT.BUCKET_SEPARATOR + "3s1ms"); michael@0: }, nextStep, "Bucket should be expiring and have time step of 3s1ms"); michael@0: yield undefined; michael@0: michael@0: michael@0: // Interupt previous expiring bucket michael@0: BUIT.setExpiringBucket("walrus2", [1002, 2002]); michael@0: is(BUIT.currentBucket, BUIT.BUCKET_PREFIX + "walrus2" + BUIT.BUCKET_SEPARATOR + "1s2ms", michael@0: "Should be new expiring bucket, with time step of 1s2ms"); michael@0: michael@0: waitForCondition(function() { michael@0: return BUIT.currentBucket == (BUIT.BUCKET_PREFIX + "walrus2" + BUIT.BUCKET_SEPARATOR + "2s2ms"); michael@0: }, nextStep, "Should be new expiring bucket, with time step of 2s2ms"); michael@0: yield undefined; michael@0: michael@0: michael@0: // Let expiring bucket expire michael@0: waitForCondition(function() { michael@0: return BUIT.currentBucket == BUIT.BUCKET_DEFAULT; michael@0: }, nextStep, "Bucket should have expired, default bucket should now be active"); michael@0: yield undefined; michael@0: michael@0: michael@0: // Interupt expiring bucket with normal bucket michael@0: BUIT.setExpiringBucket("walrus3", [1003, 2003]); michael@0: is(BUIT.currentBucket, BUIT.BUCKET_PREFIX + "walrus3" + BUIT.BUCKET_SEPARATOR + "1s3ms", michael@0: "Should be new expiring bucket, with time step of 1s3ms"); michael@0: michael@0: BUIT.setBucket("mah-bucket"); michael@0: is(BUIT.currentBucket, BUIT.BUCKET_PREFIX + "mah-bucket", "Bucket should have correct name"); michael@0: michael@0: waitForCondition(function() { michael@0: return BUIT.currentBucket == (BUIT.BUCKET_PREFIX + "mah-bucket"); michael@0: }, nextStep, "Next step of old expiring bucket shouldn't have progressed"); michael@0: yield undefined; michael@0: }