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
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 this.EXPORTED_SYMBOLS = [
8 "DummyMeasurement",
9 "DummyProvider",
10 "DummyConstantProvider",
11 "DummyPullOnlyThrowsOnInitProvider",
12 "DummyThrowOnInitProvider",
13 "DummyThrowOnShutdownProvider",
14 ];
16 const {utils: Cu} = Components;
18 Cu.import("resource://gre/modules/Promise.jsm");
19 Cu.import("resource://gre/modules/Metrics.jsm");
20 Cu.import("resource://gre/modules/Task.jsm");
22 this.DummyMeasurement = function DummyMeasurement(name="DummyMeasurement") {
23 this.name = name;
25 Metrics.Measurement.call(this);
26 }
28 DummyMeasurement.prototype = {
29 __proto__: Metrics.Measurement.prototype,
31 version: 1,
33 fields: {
34 "daily-counter": {type: Metrics.Storage.FIELD_DAILY_COUNTER},
35 "daily-discrete-numeric": {type: Metrics.Storage.FIELD_DAILY_DISCRETE_NUMERIC},
36 "daily-discrete-text": {type: Metrics.Storage.FIELD_DAILY_DISCRETE_TEXT},
37 "daily-last-numeric": {type: Metrics.Storage.FIELD_DAILY_LAST_NUMERIC},
38 "daily-last-text": {type: Metrics.Storage.FIELD_DAILY_LAST_TEXT},
39 "last-numeric": {type: Metrics.Storage.FIELD_LAST_NUMERIC},
40 "last-text": {type: Metrics.Storage.FIELD_LAST_TEXT},
41 },
42 };
45 this.DummyProvider = function DummyProvider(name="DummyProvider") {
46 Object.defineProperty(this, "name", {
47 value: name,
48 });
50 this.measurementTypes = [DummyMeasurement];
52 Metrics.Provider.call(this);
54 this.constantMeasurementName = "DummyMeasurement";
55 this.collectConstantCount = 0;
56 this.throwDuringCollectConstantData = null;
57 this.throwDuringConstantPopulate = null;
59 this.collectDailyCount = 0;
61 this.havePushedMeasurements = true;
62 }
64 DummyProvider.prototype = {
65 __proto__: Metrics.Provider.prototype,
67 name: "DummyProvider",
69 collectConstantData: function () {
70 this.collectConstantCount++;
72 if (this.throwDuringCollectConstantData) {
73 throw new Error(this.throwDuringCollectConstantData);
74 }
76 return this.enqueueStorageOperation(function doStorage() {
77 if (this.throwDuringConstantPopulate) {
78 throw new Error(this.throwDuringConstantPopulate);
79 }
81 let m = this.getMeasurement("DummyMeasurement", 1);
82 let now = new Date();
83 m.incrementDailyCounter("daily-counter", now);
84 m.addDailyDiscreteNumeric("daily-discrete-numeric", 1, now);
85 m.addDailyDiscreteNumeric("daily-discrete-numeric", 2, now);
86 m.addDailyDiscreteText("daily-discrete-text", "foo", now);
87 m.addDailyDiscreteText("daily-discrete-text", "bar", now);
88 m.setDailyLastNumeric("daily-last-numeric", 3, now);
89 m.setDailyLastText("daily-last-text", "biz", now);
90 m.setLastNumeric("last-numeric", 4, now);
91 return m.setLastText("last-text", "bazfoo", now);
92 }.bind(this));
93 },
95 collectDailyData: function () {
96 this.collectDailyCount++;
98 return Promise.resolve();
99 },
100 };
103 this.DummyConstantProvider = function () {
104 DummyProvider.call(this, this.name);
105 }
107 DummyConstantProvider.prototype = {
108 __proto__: DummyProvider.prototype,
110 name: "DummyConstantProvider",
112 pullOnly: true,
113 };
115 this.DummyThrowOnInitProvider = function () {
116 DummyProvider.call(this, "DummyThrowOnInitProvider");
118 throw new Error("Dummy Error");
119 };
121 this.DummyThrowOnInitProvider.prototype = {
122 __proto__: DummyProvider.prototype,
124 name: "DummyThrowOnInitProvider",
125 };
127 this.DummyPullOnlyThrowsOnInitProvider = function () {
128 DummyConstantProvider.call(this);
130 throw new Error("Dummy Error");
131 };
133 this.DummyPullOnlyThrowsOnInitProvider.prototype = {
134 __proto__: DummyConstantProvider.prototype,
136 name: "DummyPullOnlyThrowsOnInitProvider",
137 };
139 this.DummyThrowOnShutdownProvider = function () {
140 DummyProvider.call(this, "DummyThrowOnShutdownProvider");
141 };
143 this.DummyThrowOnShutdownProvider.prototype = {
144 __proto__: DummyProvider.prototype,
146 name: "DummyThrowOnShutdownProvider",
148 pullOnly: true,
150 onShutdown: function () {
151 throw new Error("Dummy shutdown error");
152 },
153 };