Bug 707786 - Use Services.prefs instead of preferences-service / gPrefService in SeaMonkey. r=Neil
authorEdmund Wong <ewong@pw-wspx.org>
Tue, 13 Mar 2012 09:29:52 +0800
changeset 11080 f3dd079d3da97f57cce376943b24fd456675f5ec
parent 11079 8cdfed92867f885fda98664395236b7829947a1d
child 11081 5df4e53682a20cd2b41c755f6553d959ffbfcd6f
push id463
push userbugzilla@standard8.plus.com
push dateTue, 24 Apr 2012 17:34:51 +0000
treeherdercomm-beta@e53588e8f7b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil
bugs707786
Bug 707786 - Use Services.prefs instead of preferences-service / gPrefService in SeaMonkey. r=Neil
suite/common/places/tests/unit/test_384370.js
suite/common/places/tests/unit/test_browserGlue_prefs.js
--- a/suite/common/places/tests/unit/test_384370.js
+++ b/suite/common/places/tests/unit/test_384370.js
@@ -56,18 +56,17 @@ function run_test() {
     - tag multiple URIs with multiple tags
     - export as json, import, test
   */
 
   // get places import/export service
   var importer = Cc["@mozilla.org/browser/places/import-export-service;1"].getService(Ci.nsIPlacesImportExportService);
 
   // avoid creating the places smart folder during tests
-  Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch).
-  setIntPref("browser.places.smartBookmarksVersion", -1);
+  Services.prefs.setIntPref("browser.places.smartBookmarksVersion", -1);
 
   // file pointer to legacy bookmarks file
   //var bookmarksFileOld = do_get_file("bookmarks.large.html");
   var bookmarksFileOld = do_get_file("bookmarks.preplaces.html");
   // file pointer to a new places-exported json file
   var jsonFile = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
   jsonFile.append("bookmarks.exported.json");
 
--- a/suite/common/places/tests/unit/test_browserGlue_prefs.js
+++ b/suite/common/places/tests/unit/test_browserGlue_prefs.js
@@ -49,18 +49,16 @@ let bg = Cc["@mozilla.org/suite/suiteglu
          getService(Ci.nsISuiteGlue);
 */
 
 // Initialize Places through Bookmarks Service.
 let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
          getService(Ci.nsINavBookmarksService);
 
 // Get other services.
-let ps = Cc["@mozilla.org/preferences-service;1"].
-         getService(Ci.nsIPrefBranch);
 let os = Cc["@mozilla.org/observer-service;1"].
          getService(Ci.nsIObserverService);
 
 const PREF_IMPORT_BOOKMARKS_HTML = "browser.places.importBookmarksHTML";
 const PREF_RESTORE_DEFAULT_BOOKMARKS = "browser.bookmarks.restore_default_bookmarks";
 const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion";
 const PREF_AUTO_EXPORT_HTML = "browser.bookmarks.autoExportHTML";
 
@@ -69,167 +67,167 @@ let tests = [];
 
 tests.push({
   description: "Import from bookmarks.html if importBookmarksHTML is true.",
   exec: function() {
     // Sanity check: we should not have any bookmark on the toolbar.
     do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
 
     // Set preferences.
-    ps.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
+    Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
 
     // Force nsSuiteGlue::_initPlaces().
     print("Simulate Places init");
     bg.QueryInterface(Ci.nsIObserver).observe(null,
                                               PlacesUtils.TOPIC_INIT_COMPLETE,
                                               null);
     // Check bookmarks.html has been imported, and a smart bookmark has been
     // created.
     let itemId = bs.getIdForItemAt(bs.toolbarFolder,
                                    SMART_BOOKMARKS_ON_TOOLBAR);
     do_check_eq(bs.getItemTitle(itemId), "example");
     // Check preferences have been reverted.
-    do_check_false(ps.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
+    do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
 
     next_test();
   }
 });
 
 //------------------------------------------------------------------------------
 
 tests.push({
   description: "import from bookmarks.html, but don't create smart bookmarks if they are disabled",
   exec: function() {
     // Sanity check: we should not have any bookmark on the toolbar.
     do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
 
     // Set preferences.
-    ps.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1);
-    ps.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
+    Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1);
+    Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
 
     // Force nsSuiteGlue::_initPlaces().
     print("Simulate Places init");
     bg.QueryInterface(Ci.nsIObserver).observe(null,
                                               PlacesUtils.TOPIC_INIT_COMPLETE,
                                               null);
     // Check bookmarks.html has been imported, but smart bookmarks have not
     // been created.
     let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
     do_check_eq(bs.getItemTitle(itemId), "example");
     // Check preferences have been reverted.
-    do_check_false(ps.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
+    do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
 
     next_test();
   }
 });
 
 //------------------------------------------------------------------------------
 
 tests.push({
   description: "Import from bookmarks.html, but don't create smart bookmarks if autoExportHTML is true and they are at latest version",
   exec: function() {
     // Sanity check: we should not have any bookmark on the toolbar.
     do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
     // Set preferences.
-    ps.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 999);
-    ps.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
-    ps.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
+    Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 999);
+    Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
+    Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
 
     // Force nsSuiteGlue::_initPlaces()
     print("Simulate Places init");
     bg.QueryInterface(Ci.nsIObserver).observe(null,
                                               PlacesUtils.TOPIC_INIT_COMPLETE,
                                               null);
     // Check bookmarks.html has been imported, but smart bookmarks have not
     // been created.
     let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
     do_check_eq(bs.getItemTitle(itemId), "example");
-    do_check_false(ps.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
+    do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
     // Check preferences have been reverted.
-    ps.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
+    Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
 
     next_test();
   }
 });
 
 //------------------------------------------------------------------------------
 
 tests.push({
   description: "Import from bookmarks.html, and create smart bookmarks if autoExportHTML is true and they are not at latest version.",
   exec: function() {
     // Sanity check: we should not have any bookmark on the toolbar.
     do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
     // Set preferences.
-    ps.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0);
-    ps.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
-    ps.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
+    Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0);
+    Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
+    Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
 
     // Force nsSuiteGlue::_initPlaces()
     print("Simulate Places init");
     bg.QueryInterface(Ci.nsIObserver).observe(null,
                                               PlacesUtils.TOPIC_INIT_COMPLETE,
                                               null);
     // Check bookmarks.html has been imported, but smart bookmarks have not
     // been created.
     let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
     do_check_eq(bs.getItemTitle(itemId), "example");
-    do_check_false(ps.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
+    do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
     // Check preferences have been reverted.
-    ps.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
+    Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
 
     next_test();
   }
 });
 
 //------------------------------------------------------------------------------
 tests.push({
   description: "restore from default bookmarks.html if restore_default_bookmarks is true.",
   exec: function() {
     // Sanity check: we should not have any bookmark on the toolbar.
     do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
     // Set preferences.
-    ps.setBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS, true);
+    Services.prefs.setBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS, true);
 
     // Force nsSuiteGlue::_initPlaces()
     print("Simulate Places init");
     bg.QueryInterface(Ci.nsIObserver).observe(null,
                                               PlacesUtils.TOPIC_INIT_COMPLETE,
                                               null);
     // Check bookmarks.html has been restored.
     let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR + 1);
     do_check_true(itemId > 0);
     // Check preferences have been reverted.
-    do_check_false(ps.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
+    do_check_false(Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
 
     next_test();
   }
 });
 
 //------------------------------------------------------------------------------
 
 tests.push({
   description: "setting both importBookmarksHTML and restore_default_bookmarks should restore defaults.",
   exec: function() {
     // Sanity check: we should not have any bookmark on the toolbar.
     do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
     // Set preferences.
-    ps.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
-    ps.setBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS, true);
+    Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
+    Services.prefs.setBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS, true);
 
     // Force nsSuiteGlue::_initPlaces()
     print("Simulate Places init");
     bg.QueryInterface(Ci.nsIObserver).observe(null,
                                               PlacesUtils.TOPIC_INIT_COMPLETE,
                                               null);
     // Check bookmarks.html has been restored.
     let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR + 1);
     do_check_true(itemId > 0);
     // Check preferences have been reverted.
-    do_check_false(ps.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
-    do_check_false(ps.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
+    do_check_false(Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
+    do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
 
     do_test_finished();
   }
 });
 
 //------------------------------------------------------------------------------
 
 function finish_test() {
@@ -265,23 +263,23 @@ function run_test() {
   do_timeout(0, start_tests);
 }
 
 function start_tests() {
   // Clean up database from all bookmarks.
   remove_all_bookmarks();
 
   // Ensure preferences status.
-  do_check_false(ps.getBoolPref(PREF_AUTO_EXPORT_HTML));
+  do_check_false(Services.prefs.getBoolPref(PREF_AUTO_EXPORT_HTML));
   try {
-    do_check_false(ps.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
+    do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
     do_throw("importBookmarksHTML pref should not exist");
   }
   catch(ex) {}
-  do_check_false(ps.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
+  do_check_false(Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
 
   // Create our bookmarks.html from bookmarks.glue.html.
   create_bookmarks_html("bookmarks.glue.html");
   // Create our JSON backup from bookmarks.glue.json.
   create_JSON_backup("bookmarks.glue.json");
   // Kick-off tests.
   next_test();
 }