Bug 783054 - part 3: add tests for deleting unparseable ping files; r=taras
authorNathan Froyd <froydnj@mozilla.com>
Thu, 20 Sep 2012 13:02:28 -0400
changeset 108306 08764617f060d869e0fd552363c7823bd2b478ca
parent 108305 624c912580fbc51b3db45a09227d699ea7a248a7
child 108307 96fd99a249cd6519567c766b2e696ffa61e2a363
push id23552
push userryanvm@gmail.com
push dateFri, 28 Sep 2012 03:05:08 +0000
treeherdermozilla-central@2d96ee8d9dd4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstaras
bugs783054
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 783054 - part 3: add tests for deleting unparseable ping files; r=taras
toolkit/components/telemetry/tests/unit/test_TelemetryPing.js
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js
@@ -79,17 +79,22 @@ function setupTestData() {
 
 function getSavedHistogramsFile(basename) {
   let tmpDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
   let histogramsFile = tmpDir.clone();
   histogramsFile.append(basename);
   if (histogramsFile.exists()) {
     histogramsFile.remove(true);
   }
-  do_register_cleanup(function () histogramsFile.remove(true));
+  do_register_cleanup(function () {
+    try {
+      histogramsFile.remove(true);
+    } catch (e) {
+    }
+  });
   return histogramsFile;
 }
 
 function telemetryObserver(aSubject, aTopic, aData) {
   Services.obs.removeObserver(telemetryObserver, aTopic);
   httpserver.registerPathHandler(PATH, checkHistogramsSync);
   let histogramsFile = getSavedHistogramsFile("saved-histograms.dat");
   setupTestData();
@@ -283,16 +288,26 @@ function checkPersistedHistogramsAsync(r
   gFinished = true;
 }
 
 function checkHistogramsAsync(request, response) {
   httpserver.registerPathHandler(PATH, checkPersistedHistogramsAsync);
   checkPayload(request, "test-ping", 3);
 }
 
+function runInvalidJSONTest() {
+  let histogramsFile = getSavedHistogramsFile("invalid-histograms.dat");
+  writeStringToFile(histogramsFile, "this.is.invalid.JSON");
+  do_check_true(histogramsFile.exists());
+  
+  const TelemetryPing = Cc["@mozilla.org/base/telemetry-ping;1"].getService(Ci.nsIObserver);
+  TelemetryPing.observe(histogramsFile, "test-load-histograms", null);
+  do_check_false(histogramsFile.exists());
+}
+
 // copied from toolkit/mozapps/extensions/test/xpcshell/head_addons.js
 const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1";
 const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}");
 
 function createAppInfo(id, name, version, platformVersion) {
   gAppInfo = {
     // nsIXULAppInfo
     vendor: "Mozilla",
@@ -422,15 +437,17 @@ function run_test() {
                          .QueryInterface(Ci.nsITimerCallback);
 
   gInternalManager.observe(null, "addons-startup", null);
   LightweightThemeManager.currentTheme = dummyTheme("1234");
 
   // fake plugin host for consistent flash version data
   registerFakePluginHost();
 
+  runInvalidJSONTest();
+
   Services.obs.addObserver(nonexistentServerObserver, "telemetry-test-xhr-complete", false);
   telemetry_ping();
   // spin the event loop
   do_test_pending();
   // ensure that test runs to completion
   do_register_cleanup(function () do_check_true(gFinished));
 }