Diff of /services/healthreport/modules-testing/utils.jsm [c1ad17] .. [eb85e4]  Maximize  Restore

Switch to side-by-side view

--- a/services/healthreport/modules-testing/utils.jsm
+++ b/services/healthreport/modules-testing/utils.jsm
@@ -10,17 +10,21 @@
   "makeFakeAppDir",
   "createFakeCrash",
   "InspectedHealthReporter",
+  "getHealthReporter",
 ];
 
 
 const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
 
+Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/Promise.jsm");
 Cu.import("resource://gre/modules/FileUtils.jsm");
 Cu.import("resource://gre/modules/osfile.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/services-common/utils.js");
-Cu.import("resource://gre/modules/HealthReport.jsm");
+Cu.import("resource://gre/modules/services/datareporting/policy.jsm");
+Cu.import("resource://gre/modules/services/healthreport/healthreporter.jsm");
+Cu.import("resource://gre/modules/services/healthreport/providers.jsm");
 
 
 let APP_INFO = {
@@ -267,3 +271,33 @@
   },
 };
 
+const DUMMY_URI="http://localhost:62013/";
+
+this.getHealthReporter = function (name, uri=DUMMY_URI, inspected=false) {
+  let branch = "healthreport.testing." + name + ".";
+
+  let prefs = new Preferences(branch + "healthreport.");
+  prefs.set("documentServerURI", uri);
+  prefs.set("dbName", name);
+
+  let reporter;
+
+  let policyPrefs = new Preferences(branch + "policy.");
+  let policy = new DataReportingPolicy(policyPrefs, prefs, {
+    onRequestDataUpload: function (request) {
+      reporter.requestDataUpload(request);
+    },
+
+    onNotifyDataPolicy: function (request) { },
+
+    onRequestRemoteDelete: function (request) {
+      reporter.deleteRemoteData(request);
+    },
+  });
+
+  let type = inspected ? InspectedHealthReporter : HealthReporter;
+  reporter = new type(branch + "healthreport.", policy, null,
+                      "state-" + name + ".json");
+
+  return reporter;
+};