bug 930456: Enforce failure if search service is initialized from a child process. r=gavin
authorchrishood@eagles.ewu.edu
Tue, 30 Dec 2014 09:32:04 -0800
changeset 247674 5e34d8220c131d83090643565a54c733ebe50a02
parent 247673 4cc15f56104cb2a15ce9b6019459bf51aed8fb7a
child 247675 8a9910d1105bbc3f11b0f66c1996f06db0356ff5
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs930456
milestone37.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 930456: Enforce failure if search service is initialized from a child process. r=gavin
toolkit/components/search/tests/xpcshell/head_search.js
toolkit/components/search/tests/xpcshell/test_bug930456.js
toolkit/components/search/tests/xpcshell/test_bug930456_child.js
toolkit/components/search/tests/xpcshell/xpcshell.ini
toolkit/components/search/toolkitsearch.manifest
--- a/toolkit/components/search/tests/xpcshell/head_search.js
+++ b/toolkit/components/search/tests/xpcshell/head_search.js
@@ -17,48 +17,57 @@ const BROWSER_SEARCH_PREF = "browser.sea
 const NS_APP_SEARCH_DIR = "SrchPlugns";
 
 const MODE_RDONLY = FileUtils.MODE_RDONLY;
 const MODE_WRONLY = FileUtils.MODE_WRONLY;
 const MODE_CREATE = FileUtils.MODE_CREATE;
 const MODE_TRUNCATE = FileUtils.MODE_TRUNCATE;
 
 // nsSearchService.js uses Services.appinfo.name to build a salt for a hash.
+var XULRuntime = Components.classesByID["{95d89e3e-a169-41a3-8e56-719978e15b12}"]
+                           .getService(Ci.nsIXULRuntime);
 var XULAppInfo = {
   vendor: "Mozilla",
   name: "XPCShell",
   ID: "xpcshell@test.mozilla.org",
   version: "5",
   appBuildID: "2007010101",
   platformVersion: "1.9",
   platformBuildID: "2007010101",
   inSafeMode: false,
   logConsoleErrors: true,
   OS: "XPCShell",
   XPCOMABI: "noarch-spidermonkey",
+  // mirror processType from the base implementation
+  processType: XULRuntime.processType,
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo, Ci.nsIXULRuntime,
                                          Ci.nsISupports])
 };
 
 var XULAppInfoFactory = {
   createInstance: function (outer, iid) {
     if (outer != null)
       throw Cr.NS_ERROR_NO_AGGREGATION;
     return XULAppInfo.QueryInterface(iid);
   }
 };
 
+var isChild = XULRuntime.processType == XULRuntime.PROCESS_TYPE_CONTENT;
+
 Components.manager.QueryInterface(Ci.nsIComponentRegistrar)
           .registerFactory(Components.ID("{ecff8849-cee8-40a7-bd4a-3f4fdfeddb5c}"),
                            "XULAppInfo", "@mozilla.org/xre/app-info;1",
                            XULAppInfoFactory);
 
-// Need to create and register a profile folder.
-var gProfD = do_get_profile();
+var gProfD;
+if (!isChild) {
+  // Need to create and register a profile folder.
+  gProfD = do_get_profile();
+}
 
 function dumpn(text)
 {
   dump("search test: " + text + "\n");
 }
 
 /**
  * Clean the profile of any metadata files left from a previous run.
@@ -197,25 +206,29 @@ function isSubObjectOf(expectedObj, actu
       do_check_eq(expectedObj[prop].length, actualObj[prop].length);
       isSubObjectOf(expectedObj[prop], actualObj[prop]);
     } else {
       do_check_eq(expectedObj[prop], actualObj[prop]);
     }
   }
 }
 
-// Expand the amount of information available in error logs
-Services.prefs.setBoolPref("browser.search.log", true);
+// Can't set prefs if we're running in a child process, but the search  service
+// doesn't run in child processes anyways.
+if (!isChild) {
+  // Expand the amount of information available in error logs
+  Services.prefs.setBoolPref("browser.search.log", true);
 
-// The geo-specific search tests assume certain prefs are already setup, which
-// might not be true when run in comm-central etc.  So create them here.
-Services.prefs.setBoolPref("browser.search.geoSpecificDefaults", true);
-Services.prefs.setIntPref("browser.search.geoip.timeout", 2000);
-// But still disable geoip lookups - tests that need it will re-configure this.
-Services.prefs.setCharPref("browser.search.geoip.url", "");
+  // The geo-specific search tests assume certain prefs are already setup, which
+  // might not be true when run in comm-central etc.  So create them here.
+  Services.prefs.setBoolPref("browser.search.geoSpecificDefaults", true);
+  Services.prefs.setIntPref("browser.search.geoip.timeout", 2000);
+  // But still disable geoip lookups - tests that need it will re-configure this.
+  Services.prefs.setCharPref("browser.search.geoip.url", "");
+}
 
 /**
  * After useHttpServer() is called, this string contains the URL of the "data"
  * directory, including the final slash.
  */
 let gDataUrl;
 
 /**
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/test_bug930456.js
@@ -0,0 +1,11 @@
+/* Any copyright is dedicated to the Public Domain.
+ *    http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function run_test()
+{
+  if (isChild) {
+    do_check_false("@mozilla.org/browser/search-service;1" in Cc);
+  } else {
+    do_check_true("@mozilla.org/browser/search-service;1" in Cc);
+  }
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/test_bug930456_child.js
@@ -0,0 +1,3 @@
+function run_test() {
+  run_test_in_child("test_bug930456.js");
+}
--- a/toolkit/components/search/tests/xpcshell/xpcshell.ini
+++ b/toolkit/components/search/tests/xpcshell/xpcshell.ini
@@ -18,16 +18,18 @@ support-files =
   data/search-metadata.json
   data/search.json
   data/search.sqlite
   data/searchSuggestions.sjs
   data/searchTest.jar
 
 [test_nocache.js]
 [test_645970.js]
+[test_bug930456.js]
+[test_bug930456_child.js]
 [test_identifiers.js]
 [test_invalid_engine_from_dir.js]
 [test_init_async_multiple.js]
 [test_init_async_multiple_then_sync.js]
 [test_json_cache.js]
 [test_location.js]
 [test_location_error.js]
 [test_location_malformed_json.js]
--- a/toolkit/components/search/toolkitsearch.manifest
+++ b/toolkit/components/search/toolkitsearch.manifest
@@ -1,6 +1,6 @@
-component {7319788a-fe93-4db3-9f39-818cf08f4256} nsSearchService.js
-contract @mozilla.org/browser/search-service;1 {7319788a-fe93-4db3-9f39-818cf08f4256}
+component {7319788a-fe93-4db3-9f39-818cf08f4256} nsSearchService.js process=main
+contract @mozilla.org/browser/search-service;1 {7319788a-fe93-4db3-9f39-818cf08f4256} process=main
 # 21600 == 6 hours
 category update-timer nsSearchService @mozilla.org/browser/search-service;1,getService,search-engine-update-timer,browser.search.update.interval,21600
 component {aa892eb4-ffbf-477d-9f9a-06c995ae9f27} nsSearchSuggestions.js
-contract @mozilla.org/autocomplete/search;1?name=search-autocomplete {aa892eb4-ffbf-477d-9f9a-06c995ae9f27}
\ No newline at end of file
+contract @mozilla.org/autocomplete/search;1?name=search-autocomplete {aa892eb4-ffbf-477d-9f9a-06c995ae9f27}