michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: this.EXPORTED_SYMBOLS = [ michael@0: "DummyMeasurement", michael@0: "DummyProvider", michael@0: "DummyConstantProvider", michael@0: "DummyPullOnlyThrowsOnInitProvider", michael@0: "DummyThrowOnInitProvider", michael@0: "DummyThrowOnShutdownProvider", michael@0: ]; michael@0: michael@0: const {utils: Cu} = Components; michael@0: michael@0: Cu.import("resource://gre/modules/Promise.jsm"); michael@0: Cu.import("resource://gre/modules/Metrics.jsm"); michael@0: Cu.import("resource://gre/modules/Task.jsm"); michael@0: michael@0: this.DummyMeasurement = function DummyMeasurement(name="DummyMeasurement") { michael@0: this.name = name; michael@0: michael@0: Metrics.Measurement.call(this); michael@0: } michael@0: michael@0: DummyMeasurement.prototype = { michael@0: __proto__: Metrics.Measurement.prototype, michael@0: michael@0: version: 1, michael@0: michael@0: fields: { michael@0: "daily-counter": {type: Metrics.Storage.FIELD_DAILY_COUNTER}, michael@0: "daily-discrete-numeric": {type: Metrics.Storage.FIELD_DAILY_DISCRETE_NUMERIC}, michael@0: "daily-discrete-text": {type: Metrics.Storage.FIELD_DAILY_DISCRETE_TEXT}, michael@0: "daily-last-numeric": {type: Metrics.Storage.FIELD_DAILY_LAST_NUMERIC}, michael@0: "daily-last-text": {type: Metrics.Storage.FIELD_DAILY_LAST_TEXT}, michael@0: "last-numeric": {type: Metrics.Storage.FIELD_LAST_NUMERIC}, michael@0: "last-text": {type: Metrics.Storage.FIELD_LAST_TEXT}, michael@0: }, michael@0: }; michael@0: michael@0: michael@0: this.DummyProvider = function DummyProvider(name="DummyProvider") { michael@0: Object.defineProperty(this, "name", { michael@0: value: name, michael@0: }); michael@0: michael@0: this.measurementTypes = [DummyMeasurement]; michael@0: michael@0: Metrics.Provider.call(this); michael@0: michael@0: this.constantMeasurementName = "DummyMeasurement"; michael@0: this.collectConstantCount = 0; michael@0: this.throwDuringCollectConstantData = null; michael@0: this.throwDuringConstantPopulate = null; michael@0: michael@0: this.collectDailyCount = 0; michael@0: michael@0: this.havePushedMeasurements = true; michael@0: } michael@0: michael@0: DummyProvider.prototype = { michael@0: __proto__: Metrics.Provider.prototype, michael@0: michael@0: name: "DummyProvider", michael@0: michael@0: collectConstantData: function () { michael@0: this.collectConstantCount++; michael@0: michael@0: if (this.throwDuringCollectConstantData) { michael@0: throw new Error(this.throwDuringCollectConstantData); michael@0: } michael@0: michael@0: return this.enqueueStorageOperation(function doStorage() { michael@0: if (this.throwDuringConstantPopulate) { michael@0: throw new Error(this.throwDuringConstantPopulate); michael@0: } michael@0: michael@0: let m = this.getMeasurement("DummyMeasurement", 1); michael@0: let now = new Date(); michael@0: m.incrementDailyCounter("daily-counter", now); michael@0: m.addDailyDiscreteNumeric("daily-discrete-numeric", 1, now); michael@0: m.addDailyDiscreteNumeric("daily-discrete-numeric", 2, now); michael@0: m.addDailyDiscreteText("daily-discrete-text", "foo", now); michael@0: m.addDailyDiscreteText("daily-discrete-text", "bar", now); michael@0: m.setDailyLastNumeric("daily-last-numeric", 3, now); michael@0: m.setDailyLastText("daily-last-text", "biz", now); michael@0: m.setLastNumeric("last-numeric", 4, now); michael@0: return m.setLastText("last-text", "bazfoo", now); michael@0: }.bind(this)); michael@0: }, michael@0: michael@0: collectDailyData: function () { michael@0: this.collectDailyCount++; michael@0: michael@0: return Promise.resolve(); michael@0: }, michael@0: }; michael@0: michael@0: michael@0: this.DummyConstantProvider = function () { michael@0: DummyProvider.call(this, this.name); michael@0: } michael@0: michael@0: DummyConstantProvider.prototype = { michael@0: __proto__: DummyProvider.prototype, michael@0: michael@0: name: "DummyConstantProvider", michael@0: michael@0: pullOnly: true, michael@0: }; michael@0: michael@0: this.DummyThrowOnInitProvider = function () { michael@0: DummyProvider.call(this, "DummyThrowOnInitProvider"); michael@0: michael@0: throw new Error("Dummy Error"); michael@0: }; michael@0: michael@0: this.DummyThrowOnInitProvider.prototype = { michael@0: __proto__: DummyProvider.prototype, michael@0: michael@0: name: "DummyThrowOnInitProvider", michael@0: }; michael@0: michael@0: this.DummyPullOnlyThrowsOnInitProvider = function () { michael@0: DummyConstantProvider.call(this); michael@0: michael@0: throw new Error("Dummy Error"); michael@0: }; michael@0: michael@0: this.DummyPullOnlyThrowsOnInitProvider.prototype = { michael@0: __proto__: DummyConstantProvider.prototype, michael@0: michael@0: name: "DummyPullOnlyThrowsOnInitProvider", michael@0: }; michael@0: michael@0: this.DummyThrowOnShutdownProvider = function () { michael@0: DummyProvider.call(this, "DummyThrowOnShutdownProvider"); michael@0: }; michael@0: michael@0: this.DummyThrowOnShutdownProvider.prototype = { michael@0: __proto__: DummyProvider.prototype, michael@0: michael@0: name: "DummyThrowOnShutdownProvider", michael@0: michael@0: pullOnly: true, michael@0: michael@0: onShutdown: function () { michael@0: throw new Error("Dummy shutdown error"); michael@0: }, michael@0: }; michael@0: