2012-11-05 12:50:11 -08:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
this.EXPORTED_SYMBOLS = [
|
|
|
|
"DummyMeasurement",
|
|
|
|
"DummyProvider",
|
2013-01-31 08:58:19 -08:00
|
|
|
"DummyConstantProvider",
|
2012-11-05 12:50:11 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
const {utils: Cu} = Components;
|
|
|
|
|
2013-02-01 11:43:15 -08:00
|
|
|
Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js");
|
2013-01-06 12:13:19 -08:00
|
|
|
Cu.import("resource://gre/modules/Metrics.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Task.jsm");
|
2012-11-05 12:50:11 -08:00
|
|
|
|
|
|
|
this.DummyMeasurement = function DummyMeasurement(name="DummyMeasurement") {
|
2013-01-06 12:13:19 -08:00
|
|
|
this.name = name;
|
2012-11-05 12:50:11 -08:00
|
|
|
|
2013-01-06 12:13:19 -08:00
|
|
|
Metrics.Measurement.call(this);
|
|
|
|
}
|
2012-11-05 12:50:11 -08:00
|
|
|
|
2013-01-06 12:13:19 -08:00
|
|
|
DummyMeasurement.prototype = {
|
|
|
|
__proto__: Metrics.Measurement.prototype,
|
|
|
|
|
|
|
|
version: 1,
|
|
|
|
|
2013-02-21 14:11:54 -08:00
|
|
|
fields: {
|
|
|
|
"daily-counter": {type: Metrics.Storage.FIELD_DAILY_COUNTER},
|
|
|
|
"daily-discrete-numeric": {type: Metrics.Storage.FIELD_DAILY_DISCRETE_NUMERIC},
|
|
|
|
"daily-discrete-text": {type: Metrics.Storage.FIELD_DAILY_DISCRETE_TEXT},
|
|
|
|
"daily-last-numeric": {type: Metrics.Storage.FIELD_DAILY_LAST_NUMERIC},
|
|
|
|
"daily-last-text": {type: Metrics.Storage.FIELD_DAILY_LAST_TEXT},
|
|
|
|
"last-numeric": {type: Metrics.Storage.FIELD_LAST_NUMERIC},
|
|
|
|
"last-text": {type: Metrics.Storage.FIELD_LAST_TEXT},
|
2012-11-05 12:50:11 -08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.DummyProvider = function DummyProvider(name="DummyProvider") {
|
2013-03-11 14:12:24 -07:00
|
|
|
Object.defineProperty(this, "name", {
|
|
|
|
value: name,
|
|
|
|
});
|
2013-01-06 12:13:19 -08:00
|
|
|
|
|
|
|
this.measurementTypes = [DummyMeasurement];
|
|
|
|
|
|
|
|
Metrics.Provider.call(this);
|
2012-11-05 12:50:11 -08:00
|
|
|
|
|
|
|
this.constantMeasurementName = "DummyMeasurement";
|
2012-11-05 13:45:35 -08:00
|
|
|
this.collectConstantCount = 0;
|
2013-01-06 12:13:19 -08:00
|
|
|
this.throwDuringCollectConstantData = null;
|
2012-11-08 15:32:49 -08:00
|
|
|
this.throwDuringConstantPopulate = null;
|
2013-01-06 12:13:19 -08:00
|
|
|
|
2013-02-05 09:59:13 -08:00
|
|
|
this.collectDailyCount = 0;
|
|
|
|
|
2013-01-06 12:13:19 -08:00
|
|
|
this.havePushedMeasurements = true;
|
2012-11-05 12:50:11 -08:00
|
|
|
}
|
2013-01-06 12:13:19 -08:00
|
|
|
|
2012-11-05 12:50:11 -08:00
|
|
|
DummyProvider.prototype = {
|
2013-01-06 12:13:19 -08:00
|
|
|
__proto__: Metrics.Provider.prototype,
|
2012-11-05 12:50:11 -08:00
|
|
|
|
2013-03-11 14:12:24 -07:00
|
|
|
name: "DummyProvider",
|
|
|
|
|
2013-01-06 12:13:19 -08:00
|
|
|
collectConstantData: function () {
|
2012-11-05 13:45:35 -08:00
|
|
|
this.collectConstantCount++;
|
|
|
|
|
2013-01-06 12:13:19 -08:00
|
|
|
if (this.throwDuringCollectConstantData) {
|
|
|
|
throw new Error(this.throwDuringCollectConstantData);
|
2012-11-08 15:32:49 -08:00
|
|
|
}
|
|
|
|
|
2013-01-06 12:13:19 -08:00
|
|
|
return this.enqueueStorageOperation(function doStorage() {
|
|
|
|
if (this.throwDuringConstantPopulate) {
|
|
|
|
throw new Error(this.throwDuringConstantPopulate);
|
|
|
|
}
|
|
|
|
|
|
|
|
let m = this.getMeasurement("DummyMeasurement", 1);
|
|
|
|
let now = new Date();
|
|
|
|
m.incrementDailyCounter("daily-counter", now);
|
|
|
|
m.addDailyDiscreteNumeric("daily-discrete-numeric", 1, now);
|
|
|
|
m.addDailyDiscreteNumeric("daily-discrete-numeric", 2, now);
|
|
|
|
m.addDailyDiscreteText("daily-discrete-text", "foo", now);
|
|
|
|
m.addDailyDiscreteText("daily-discrete-text", "bar", now);
|
|
|
|
m.setDailyLastNumeric("daily-last-numeric", 3, now);
|
|
|
|
m.setDailyLastText("daily-last-text", "biz", now);
|
|
|
|
m.setLastNumeric("last-numeric", 4, now);
|
|
|
|
return m.setLastText("last-text", "bazfoo", now);
|
|
|
|
}.bind(this));
|
2012-11-08 15:32:49 -08:00
|
|
|
},
|
|
|
|
|
2013-02-05 09:59:13 -08:00
|
|
|
collectDailyData: function () {
|
|
|
|
this.collectDailyCount++;
|
|
|
|
|
|
|
|
return Promise.resolve();
|
|
|
|
},
|
2012-11-05 12:50:11 -08:00
|
|
|
};
|
2013-01-06 12:13:19 -08:00
|
|
|
|
2013-01-31 08:58:19 -08:00
|
|
|
|
|
|
|
this.DummyConstantProvider = function () {
|
|
|
|
DummyProvider.call(this, "DummyConstantProvider");
|
|
|
|
}
|
|
|
|
|
|
|
|
DummyConstantProvider.prototype = {
|
|
|
|
__proto__: DummyProvider.prototype,
|
|
|
|
|
2013-03-11 14:12:24 -07:00
|
|
|
name: "DummyConstantProvider",
|
|
|
|
|
2013-02-18 13:05:07 -08:00
|
|
|
pullOnly: true,
|
2013-01-31 08:58:19 -08:00
|
|
|
};
|
|
|
|
|