From 1a6a9cae0dcf5c65476a3ef4d6e988d5d79e7097 Mon Sep 17 00:00:00 2001 From: "chrishood@eagles.ewu.edu" Date: Tue, 30 Dec 2014 09:32:04 -0800 Subject: [PATCH] bug 930456: Enforce failure if search service is initialized from a child process. r=gavin --HG-- extra : transplant_source : %1F%E46%1F%C7%F2%04%9B%EB%BF%FE%EB_%08%B3XN%F9%8B%29 --- .../search/tests/xpcshell/head_search.js | 33 +++++++++++++------ .../search/tests/xpcshell/test_bug930456.js | 11 +++++++ .../tests/xpcshell/test_bug930456_child.js | 3 ++ .../search/tests/xpcshell/xpcshell.ini | 2 ++ .../components/search/toolkitsearch.manifest | 6 ++-- 5 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 toolkit/components/search/tests/xpcshell/test_bug930456.js create mode 100644 toolkit/components/search/tests/xpcshell/test_bug930456_child.js diff --git a/toolkit/components/search/tests/xpcshell/head_search.js b/toolkit/components/search/tests/xpcshell/head_search.js index ed72d7c8b79e..85bb260b7e50 100644 --- a/toolkit/components/search/tests/xpcshell/head_search.js +++ b/toolkit/components/search/tests/xpcshell/head_search.js @@ -22,6 +22,8 @@ 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", @@ -34,6 +36,8 @@ var XULAppInfo = { 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]) @@ -47,13 +51,18 @@ var XULAppInfoFactory = { } }; +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) { @@ -202,15 +211,19 @@ function isSubObjectOf(expectedObj, actualObj) { } } -// 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" diff --git a/toolkit/components/search/tests/xpcshell/test_bug930456.js b/toolkit/components/search/tests/xpcshell/test_bug930456.js new file mode 100644 index 000000000000..1dbb06c59ffe --- /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); + } +} diff --git a/toolkit/components/search/tests/xpcshell/test_bug930456_child.js b/toolkit/components/search/tests/xpcshell/test_bug930456_child.js new file mode 100644 index 000000000000..8540a37f4e3b --- /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"); +} diff --git a/toolkit/components/search/tests/xpcshell/xpcshell.ini b/toolkit/components/search/tests/xpcshell/xpcshell.ini index 98f478bc959a..a899a59811ff 100644 --- a/toolkit/components/search/tests/xpcshell/xpcshell.ini +++ b/toolkit/components/search/tests/xpcshell/xpcshell.ini @@ -23,6 +23,8 @@ support-files = [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] diff --git a/toolkit/components/search/toolkitsearch.manifest b/toolkit/components/search/toolkitsearch.manifest index 2f81fc3dff36..359e5551fafb 100644 --- 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}