From 0a1297ce082c025099c2e3276f17a791e8094523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Fri, 7 Dec 2012 08:53:06 -0500 Subject: [PATCH] Bug 817944 - Replace test-load-histograms with a function. r=vladan. --- toolkit/components/telemetry/TelemetryPing.js | 11 ++++++----- toolkit/components/telemetry/nsITelemetryPing.idl | 8 ++++++++ .../telemetry/tests/unit/test_TelemetryPing.js | 8 ++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/toolkit/components/telemetry/TelemetryPing.js b/toolkit/components/telemetry/TelemetryPing.js index bdbd281c020..98213ae0746 100644 --- a/toolkit/components/telemetry/TelemetryPing.js +++ b/toolkit/components/telemetry/TelemetryPing.js @@ -805,6 +805,12 @@ TelemetryPing.prototype = { } }, + testLoadHistograms: function testLoadHistograms(file, sync) { + this._pingsLoaded = 0; + this._pingLoadsCompleted = 0; + this.loadHistograms(file, sync); + }, + loadSavedPings: function loadSavedPings(sync) { let directory = this.ensurePingDirectory(); let entries = directory.directoryEntries @@ -1035,11 +1041,6 @@ TelemetryPing.prototype = { this._isIdleObserver = true; }).bind(this), Ci.nsIThread.DISPATCH_NORMAL); break; - case "test-load-histograms": - this._pingsLoaded = 0; - this._pingLoadsCompleted = 0; - this.loadHistograms(aSubject.QueryInterface(Ci.nsIFile), aData != "async"); - break; case "idle": this.sendIdlePing(false, this._server); break; diff --git a/toolkit/components/telemetry/nsITelemetryPing.idl b/toolkit/components/telemetry/nsITelemetryPing.idl index 065319a90b6..619e63575f8 100644 --- a/toolkit/components/telemetry/nsITelemetryPing.idl +++ b/toolkit/components/telemetry/nsITelemetryPing.idl @@ -15,4 +15,12 @@ interface nsITelemetryPing : nsIObserver { void enableLoadSaveNotifications(); /* Used only for testing. */ void setAddOns(in AString aAddOns); void testPing(in AString aServer); + + /** + * Load histograms from a file. + * + * @param aFile - File to load from. + * @param aSync - Use sync reads. + */ + void testLoadHistograms(in nsIFile aFile, in boolean aSync); }; diff --git a/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js b/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js index 3e62b3b27a2..425dc6ca1a1 100644 --- a/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js +++ b/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js @@ -101,7 +101,7 @@ function telemetryObserver(aSubject, aTopic, aData) { const TelemetryPing = Cc["@mozilla.org/base/telemetry-ping;1"].getService(Ci.nsITelemetryPing); TelemetryPing.saveHistograms(histogramsFile, true); - TelemetryPing.observe(histogramsFile, "test-load-histograms", null); + TelemetryPing.testLoadHistograms(histogramsFile, true); telemetry_ping(); } @@ -286,7 +286,7 @@ function runAsyncTestObserver(aSubject, aTopic, aData) { telemetry_ping(); }, "telemetry-test-load-complete", false); - TelemetryPing.observe(histogramsFile, "test-load-histograms", "async"); + TelemetryPing.testLoadHistograms(histogramsFile, false); }, "telemetry-test-save-complete", false); TelemetryPing.saveHistograms(histogramsFile, false); } @@ -315,7 +315,7 @@ function runInvalidJSONTest() { do_check_true(histogramsFile.exists()); const TelemetryPing = Cc["@mozilla.org/base/telemetry-ping;1"].getService(Ci.nsITelemetryPing); - TelemetryPing.observe(histogramsFile, "test-load-histograms", null); + TelemetryPing.testLoadHistograms(histogramsFile, true); do_check_false(histogramsFile.exists()); } @@ -327,7 +327,7 @@ function runOldPingFileTest() { let mtime = histogramsFile.lastModifiedTime; histogramsFile.lastModifiedTime = mtime - 8 * 24 * 60 * 60 * 1000; // 8 days. - TelemetryPing.observe(histogramsFile, "test-load-histograms", null); + TelemetryPing.testLoadHistograms(histogramsFile, true); do_check_false(histogramsFile.exists()); }