Bug 783054 - part 1: refactor write_fake_shutdown_file to use a helper; r=taras
authorNathan Froyd <froydnj@mozilla.com>
Thu, 20 Sep 2012 12:59:55 -0400
changeset 108295 7ddcdc6f0619f8300f318d5c71d063ff8121c8b5
parent 108294 71e1ca0f2da33bdfc65e60d8dc5fb16ccabbb8dd
child 108296 624c912580fbc51b3db45a09227d699ea7a248a7
push id15466
push usernfroyd@mozilla.com
push dateThu, 27 Sep 2012 15:42:16 +0000
treeherdermozilla-inbound@96fd99a249cd [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 1: refactor write_fake_shutdown_file to use a helper; 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
@@ -377,30 +377,34 @@ const PLUGINHOST_CONTRACTID = "@mozilla.
 const PLUGINHOST_CID = Components.ID("{2329e6ea-1f15-4cbe-9ded-6e98e842de0e}");
 
 function registerFakePluginHost() {
   var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
   registrar.registerFactory(PLUGINHOST_CID, "Fake Plugin Host",
                             PLUGINHOST_CONTRACTID, PluginHostFactory);
 }
 
-function write_fake_shutdown_file() {
-  let profileDirectory = Services.dirsvc.get("ProfD", Ci.nsIFile);
-  let file = profileDirectory.clone();
-  file.append("Telemetry.ShutdownTime.txt");
-  let contents = "" + SHUTDOWN_TIME;
+function writeStringToFile(file, contents) {
   let ostream = Cc["@mozilla.org/network/safe-file-output-stream;1"]
                 .createInstance(Ci.nsIFileOutputStream);
   ostream.init(file, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE,
 	       RW_OWNER, ostream.DEFER_OPEN);
   ostream.write(contents, contents.length);
   ostream.QueryInterface(Ci.nsISafeOutputStream).finish();
   ostream.close();
 }
 
+function write_fake_shutdown_file() {
+  let profileDirectory = Services.dirsvc.get("ProfD", Ci.nsIFile);
+  let file = profileDirectory.clone();
+  file.append("Telemetry.ShutdownTime.txt");
+  let contents = "" + SHUTDOWN_TIME;
+  writeStringToFile(file, contents);
+}
+
 function run_test() {
   try {
     var gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfoDebug);
     gfxInfo.spoofVendorID("0xabcd");
     gfxInfo.spoofDeviceID("0x1234");
   } catch (x) {
     // If we can't test gfxInfo, that's fine, we'll note it later.
   }