Bug 809920 - Create testing/modules for shared testing-only JS modules; r=ted
authorGregory Szorc <gps@mozilla.com>
Fri, 01 Feb 2013 12:26:07 -0800
changeset 120624 d7b65369292acf21eb8392413dd18067c3ff271d
parent 120623 971141fe081e9e733ec87160e71dbc2217f49e3b
child 120625 b2ed3a48edbecd2d69b86c0e5955467422126b59
push id24261
push userphilringnalda@gmail.com
push dateSun, 03 Feb 2013 20:34:26 +0000
treeherdermozilla-central@847e28c7ba67 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs809920
milestone21.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 809920 - Create testing/modules for shared testing-only JS modules; r=ted Includes AppInfo.jsm with code for manipulating XULAppInfo.
testing/modules/AppInfo.jsm
testing/modules/Makefile.in
toolkit/toolkit-tiers.mk
copy from services/healthreport/modules-testing/utils.jsm
copy to testing/modules/AppInfo.jsm
--- a/services/healthreport/modules-testing/utils.jsm
+++ b/testing/modules/AppInfo.jsm
@@ -2,31 +2,22 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 this.EXPORTED_SYMBOLS = [
   "getAppInfo",
   "updateAppInfo",
-  "makeFakeAppDir",
-  "createFakeCrash",
-  "InspectedHealthReporter",
 ];
 
 
-const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
+const {interfaces: Ci, results: Cr, utils: Cu} = Components;
 
-Cu.import("resource://gre/modules/commonjs/promise/core.js");
-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");
-
 
 let APP_INFO = {
   vendor: "Mozilla",
   name: "xpcshell",
   ID: "xpcshell@tests.mozilla.org",
   version: "1",
   appBuildID: "20121107",
   platformVersion: "p-ver",
@@ -76,184 +67,8 @@ this.updateAppInfo = function (obj) {
 
       return obj.QueryInterface(iid);
     },
   };
 
   registrar.registerFactory(id, "XULAppInfo", cid, factory);
 };
 
-// Reference needed in order for fake app dir provider to be active.
-let gFakeAppDirectoryProvider;
-
-/**
- * Installs a fake UAppData directory.
- *
- * This is needed by tests because a UAppData directory typically isn't
- * present in the test environment.
- *
- * This function is suitable for use in different components. If we ever
- * establish a central location for convenient test helpers, this should
- * go there.
- *
- * We create the new UAppData directory under the profile's directory
- * because the profile directory is automatically cleaned as part of
- * test shutdown.
- *
- * This returns a promise that will be resolved once the new directory
- * is created and installed.
- */
-this.makeFakeAppDir = function () {
-  let dirMode = OS.Constants.libc.S_IRWXU;
-  let dirService = Cc["@mozilla.org/file/directory_service;1"]
-                     .getService(Ci.nsIProperties);
-  let baseFile = dirService.get("ProfD", Ci.nsIFile);
-  let appD = baseFile.clone();
-  appD.append("UAppData");
-
-  if (gFakeAppDirectoryProvider) {
-    return Promise.resolve(appD.path);
-  }
-
-  function makeDir(f) {
-    if (f.exists()) {
-      return;
-    }
-
-    dump("Creating directory: " + f.path + "\n");
-    f.create(Ci.nsIFile.DIRECTORY_TYPE, dirMode);
-  }
-
-  makeDir(appD);
-
-  let reportsD = appD.clone();
-  reportsD.append("Crash Reports");
-
-  let pendingD = reportsD.clone();
-  pendingD.append("pending");
-  let submittedD = reportsD.clone();
-  submittedD.append("submitted");
-
-  makeDir(reportsD);
-  makeDir(pendingD);
-  makeDir(submittedD);
-
-  let provider = {
-    getFile: function (prop, persistent) {
-      persistent.value = true;
-      if (prop == "UAppData") {
-        return appD.clone();
-      }
-
-      throw Cr.NS_ERROR_FAILURE;
-    },
-
-    QueryInterace: function (iid) {
-      if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
-          iid.equals(Ci.nsISupports)) {
-        return this;
-      }
-
-      throw Cr.NS_ERROR_NO_INTERFACE;
-    },
-  };
-
-  // Register the new provider.
-  dirService.QueryInterface(Ci.nsIDirectoryService)
-            .registerProvider(provider);
-
-  // And undefine the old one.
-  try {
-    dirService.undefine("UAppData");
-  } catch (ex) {};
-
-  gFakeAppDirectoryProvider = provider;
-
-  dump("Successfully installed fake UAppDir\n");
-  return Promise.resolve(appD.path);
-};
-
-
-/**
- * Creates a fake crash in the Crash Reports directory.
- *
- * Currently, we just create a dummy file. A more robust implementation would
- * create something that actually resembles a crash report file.
- *
- * This is very similar to code in crashreporter/tests/browser/head.js.
- *
- * FUTURE consolidate code in a shared JSM.
- */
-this.createFakeCrash = function (submitted=false, date=new Date()) {
-  let id = CommonUtils.generateUUID();
-  let filename;
-
-  let paths = ["Crash Reports"];
-  let mode;
-
-  if (submitted) {
-    paths.push("submitted");
-    filename = "bp-" + id + ".txt";
-    mode = OS.Constants.libc.S_IRUSR | OS.Constants.libc.S_IWUSR |
-           OS.Constants.libc.S_IRGRP | OS.Constants.libc.S_IROTH;
-  } else {
-    paths.push("pending");
-    filename = id + ".dmp";
-    mode = OS.Constants.libc.S_IRUSR | OS.Constants.libc.S_IWUSR;
-  }
-
-  paths.push(filename);
-
-  let file = FileUtils.getFile("UAppData", paths, true);
-  file.create(file.NORMAL_FILE_TYPE, mode);
-  file.lastModifiedTime = date.getTime();
-  dump("Created fake crash: " + id + "\n");
-
-  return id;
-};
-
-
-/**
- * A HealthReporter that is probed with various callbacks and counters.
- *
- * The purpose of this type is to aid testing of startup and shutdown.
- */
-this.InspectedHealthReporter = function (branch, policy) {
-  HealthReporter.call(this, branch, policy);
-
-  this.onStorageCreated = null;
-  this.onCollectorInitialized = null;
-  this.collectorShutdownCount = 0;
-  this.storageCloseCount = 0;
-}
-
-InspectedHealthReporter.prototype = {
-  __proto__: HealthReporter.prototype,
-
-  _onStorageCreated: function (storage) {
-    if (this.onStorageCreated) {
-      this.onStorageCreated(storage);
-    }
-
-    return HealthReporter.prototype._onStorageCreated.call(this, storage);
-  },
-
-  _onCollectorInitialized: function () {
-    if (this.onCollectorInitialized) {
-      this.onCollectorInitialized();
-    }
-
-    return HealthReporter.prototype._onCollectorInitialized.call(this);
-  },
-
-  _onCollectorShutdown: function () {
-    this.collectorShutdownCount++;
-
-    return HealthReporter.prototype._onCollectorShutdown.call(this);
-  },
-
-  _onStorageClose: function () {
-    this.storageCloseCount++;
-
-    return HealthReporter.prototype._onStorageClose.call(this);
-  },
-};
-
new file mode 100644
--- /dev/null
+++ b/testing/modules/Makefile.in
@@ -0,0 +1,17 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+DEPTH     = @DEPTH@
+topsrcdir = @top_srcdir@
+srcdir    = @srcdir@
+VPATH     = @srcdir@
+
+include $(DEPTH)/config/autoconf.mk
+
+TESTING_JS_MODULES := \
+  AppInfo.jsm \
+  $(NULL)
+
+include $(topsrcdir)/config/rules.mk
+
--- a/toolkit/toolkit-tiers.mk
+++ b/toolkit/toolkit-tiers.mk
@@ -319,13 +319,14 @@ tier_platform_dirs += testing/marionette
 endif
 
 ifdef ENABLE_TESTS
 tier_platform_dirs += testing/mochitest
 tier_platform_dirs += testing/xpcshell
 tier_platform_dirs += testing/tools/screenshot
 tier_platform_dirs += testing/peptest
 tier_platform_dirs += testing/mozbase
+tier_platform_dirs += testing/modules
 ifdef MOZ_WEBRTC
 tier_platform_dirs += media/webrtc/signaling/test
 tier_platform_dirs += media/mtransport/test
 endif
 endif