Bug 845935 - Don't perform FHR activities unless fully initialized; r=rnewman

This commit is contained in:
Gregory Szorc 2013-03-15 21:10:08 -07:00
parent 018a85ed75
commit 264e923d17
2 changed files with 42 additions and 0 deletions

View File

@ -499,6 +499,10 @@ AbstractHealthReporter.prototype = Object.freeze({
* Collect all measurements for all registered providers.
*/
collectMeasurements: function () {
if (!this._initialized) {
return Promise.reject(new Error("Not initialized."));
}
return Task.spawn(function doCollection() {
try {
TelemetryStopwatch.start(TELEMETRY_COLLECT_CONSTANT, this);
@ -548,6 +552,10 @@ AbstractHealthReporter.prototype = Object.freeze({
* @return Promise<Object | string>
*/
collectAndObtainJSONPayload: function (asObject=false) {
if (!this._initialized) {
return Promise.reject(new Error("Not initialized."));
}
return Task.spawn(function collectAndObtain() {
yield this._providerManager.ensurePullOnlyProvidersRegistered();
@ -591,6 +599,10 @@ AbstractHealthReporter.prototype = Object.freeze({
* @return Promise<string|object>
*/
getJSONPayload: function (asObject=false) {
if (!this._initialized) {
return Promise.reject(new Error("Not initialized."));
}
TelemetryStopwatch.start(TELEMETRY_GENERATE_PAYLOAD, this);
let deferred = Promise.defer();
@ -1011,6 +1023,10 @@ HealthReporter.prototype = Object.freeze({
* The passed argument is a `DataSubmissionRequest` from policy.jsm.
*/
requestDataUpload: function (request) {
if (!this._initialized) {
return Promise.reject(new Error("Not initialized."));
}
return Task.spawn(function doUpload() {
yield this._providerManager.ensurePullOnlyProvidersRegistered();
try {

View File

@ -630,3 +630,29 @@ add_task(function test_collect_when_upload_disabled() {
reporter._shutdown();
}
});
add_task(function test_failure_if_not_initialized() {
let reporter = yield getReporter("failure_if_not_initialized");
reporter._shutdown();
let error = false;
try {
yield reporter.requestDataUpload();
} catch (ex) {
error = true;
do_check_true(ex.message.contains("Not initialized."));
} finally {
do_check_true(error);
error = false;
}
try {
yield reporter.collectMeasurements();
} catch (ex) {
error = true;
do_check_true(ex.message.contains("Not initialized."));
} finally {
do_check_true(error);
error = false;
}
});