2012-01-11 04:19:06 +04:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
function getSimpleMeasurementsFromTelemetryPing() {
|
|
|
|
const TelemetryPing = Cc["@mozilla.org/base/telemetry-ping;1"].getService(Ci.nsIObserver);
|
|
|
|
let str = Cc['@mozilla.org/supports-string;1'].createInstance(Ci.nsISupportsString);
|
|
|
|
TelemetryPing.observe(str, "get-payload", "");
|
|
|
|
|
|
|
|
return JSON.parse(str.data).simpleMeasurements;
|
|
|
|
}
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
// Test the module logic
|
2012-02-06 00:22:57 +04:00
|
|
|
let tmp = {};
|
|
|
|
Cu.import("resource:///modules/TelemetryTimestamps.jsm", tmp);
|
|
|
|
let TelemetryTimestamps = tmp.TelemetryTimestamps;
|
2012-01-11 04:19:06 +04:00
|
|
|
let now = Date.now();
|
|
|
|
TelemetryTimestamps.add("foo");
|
2012-01-28 00:37:28 +04:00
|
|
|
ok(TelemetryTimestamps.get().foo, "foo was added");
|
|
|
|
ok(TelemetryTimestamps.get().foo >= now, "foo has a reasonable value");
|
2012-01-11 04:19:06 +04:00
|
|
|
|
|
|
|
// Add timestamp with value
|
2012-01-28 00:37:28 +04:00
|
|
|
// Use a value far in the future since TelemetryPing substracts the time of
|
|
|
|
// process initialization.
|
|
|
|
const YEAR_4000_IN_MS = 64060588800000;
|
|
|
|
TelemetryTimestamps.add("bar", YEAR_4000_IN_MS);
|
2012-01-11 04:19:06 +04:00
|
|
|
ok(TelemetryTimestamps.get().bar, "bar was added");
|
2012-01-28 00:37:28 +04:00
|
|
|
is(TelemetryTimestamps.get().bar, YEAR_4000_IN_MS, "bar has the right value");
|
2012-01-11 04:19:06 +04:00
|
|
|
|
|
|
|
// Can't add the same timestamp twice
|
|
|
|
TelemetryTimestamps.add("bar", 2);
|
2012-01-28 00:37:28 +04:00
|
|
|
is(TelemetryTimestamps.get().bar, YEAR_4000_IN_MS, "bar wasn't overwritten");
|
2012-01-11 04:19:06 +04:00
|
|
|
|
|
|
|
let threw = false;
|
|
|
|
try {
|
|
|
|
TelemetryTimestamps.add("baz", "this isn't a number");
|
|
|
|
} catch (ex) {
|
|
|
|
threw = true;
|
|
|
|
}
|
|
|
|
ok(threw, "adding baz threw");
|
|
|
|
ok(!TelemetryTimestamps.get().baz, "no baz was added");
|
|
|
|
|
|
|
|
// Test that the data gets added to the telemetry ping properly
|
|
|
|
let simpleMeasurements = getSimpleMeasurementsFromTelemetryPing();
|
|
|
|
ok(simpleMeasurements, "got simple measurements from ping data");
|
2012-01-28 00:37:28 +04:00
|
|
|
ok(simpleMeasurements.foo > 1, "foo was included");
|
|
|
|
ok(simpleMeasurements.bar > 1, "bar was included");
|
2012-01-11 04:19:06 +04:00
|
|
|
ok(!simpleMeasurements.baz, "baz wasn't included since it wasn't added");
|
|
|
|
|
|
|
|
// Check browser timestamps that we add
|
|
|
|
let props = [
|
|
|
|
// These can't be reliably tested when the test is run alone
|
|
|
|
//"delayedStartupStarted",
|
|
|
|
//"delayedStartupFinished",
|
|
|
|
"sessionRestoreInitialized",
|
|
|
|
// This doesn't get hit in the testing profile
|
|
|
|
//"sessionRestoreRestoring"
|
|
|
|
];
|
|
|
|
|
|
|
|
props.forEach(function (p) {
|
|
|
|
let value = simpleMeasurements[p];
|
|
|
|
ok(value, p + " exists");
|
|
|
|
ok(!isNaN(value), p + " is a number");
|
2012-01-28 00:37:28 +04:00
|
|
|
ok(value > 0, p + " value is reasonable");
|
2012-01-11 04:19:06 +04:00
|
|
|
});
|
|
|
|
}
|