use Services.* in browser chrome tests
authorDão Gottwald <dao@mozilla.com>
Fri, 02 Apr 2010 09:20:42 +0200
changeset 40141 c8f0660250e0fd52a207fa7777f8a5f930b973ff
parent 40140 7804b7b04915f7ac3df068a0c35e56f76dfba408
child 40142 a057e4a09a95aa0e385e360cf0310f65378683e8
push id12570
push userdgottwald@mozilla.com
push dateFri, 02 Apr 2010 07:21:37 +0000
treeherdermozilla-central@c8f0660250e0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone1.9.3a4pre
first release with
nightly linux32
c8f0660250e0 / 3.7a4pre / 20100402030334 / files
nightly linux64
c8f0660250e0 / 3.7a4pre / 20100402030627 / files
nightly mac
c8f0660250e0 / 3.7a4pre / 20100402030755 / files
nightly win32
c8f0660250e0 / 3.7a4pre / 20100402051154 / files
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
use Services.* in browser chrome tests
browser/base/content/test/browser_bug484315.js
browser/base/content/test/browser_getshortcutoruri.js
browser/base/content/test/browser_pageInfo.js
browser/base/content/test/browser_pluginnotification.js
browser/base/content/test/browser_sanitize-download-history.js
browser/base/content/test/browser_sanitizeDialog.js
browser/base/content/test/browser_sanitizeDialog_treeView.js
browser/components/preferences/tests/browser_bug410900.js
browser/components/preferences/tests/privacypane_tests.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_beforeunload.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_certexceptionsui.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_commandline_toggle.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cookieacceptdialog.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_downloadmonitor.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_forgetthissite.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_transition.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_ui.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_urlbarundo.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_viewsource.js
browser/components/search/test/browser_415700.js
browser/components/search/test/browser_426329.js
browser/components/search/test/browser_483086.js
browser/components/sessionstore/test/browser/browser_248970_a.js
browser/components/sessionstore/test/browser/browser_354894.js
browser/components/sessionstore/test/browser/browser_394759.js
browser/components/sessionstore/test/browser/browser_394759_privatebrowsing.js
browser/components/sessionstore/test/browser/browser_423132.js
browser/components/sessionstore/test/browser/browser_448741.js
browser/components/sessionstore/test/browser/browser_461634.js
browser/components/sessionstore/test/browser/browser_464199.js
browser/components/sessionstore/test/browser/browser_465223.js
browser/components/sessionstore/test/browser/browser_477657.js
browser/components/sessionstore/test/browser/browser_480148.js
browser/components/sessionstore/test/browser/browser_490040.js
browser/components/sessionstore/test/browser/browser_491168.js
browser/components/sessionstore/test/browser/browser_491577.js
browser/components/sessionstore/test/browser/browser_493467.js
browser/components/sessionstore/test/browser/browser_495495.js
browser/components/sessionstore/test/browser/browser_514751.js
browser/components/sessionstore/test/browser/browser_522545.js
browser/components/sessionstore/test/browser/browser_524745.js
browser/components/sessionstore/test/browser/browser_526613.js
browser/components/sessionstore/test/browser/browser_528776.js
browser/fuel/test/browser_Application.js
browser/fuel/test/browser_ApplicationQuitting.js
browser/fuel/test/browser_Bookmarks.js
docshell/test/browser/browser_bug134911.js
docshell/test/browser/browser_bug349769.js
docshell/test/browser/browser_bug388121-1.js
docshell/test/browser/browser_bug388121-2.js
docshell/test/browser/browser_bug92473.js
toolkit/components/downloads/test/browser/browser_bug414214.js
toolkit/components/downloads/test/browser/browser_nsIDownloadManagerUI.js
toolkit/components/passwordmgr/test/browser/browser_passwordmgr_sort.js
toolkit/components/passwordmgr/test/browser/browser_passwordmgrdlg.js
toolkit/crashreporter/test/browser/browser_aboutCrashesResubmit.js
toolkit/mozapps/extensions/test/browser/browser_bug510909.js
--- a/browser/base/content/test/browser_bug484315.js
+++ b/browser/base/content/test/browser_bug484315.js
@@ -1,13 +1,11 @@
 function test() {
   var contentWin = window.open("about:blank", "", "width=100,height=100");
-  var enumerator = Cc["@mozilla.org/appshell/window-mediator;1"]
-                     .getService(Ci.nsIWindowMediator)
-                     .getEnumerator("navigator:browser");
+  var enumerator = Services.wm.getEnumerator("navigator:browser");
 
   while (enumerator.hasMoreElements()) {
     let win = enumerator.getNext();
     if (win.content == contentWin) {
       gPrefService.setBoolPref("browser.tabs.closeWindowWithLastTab", false);
       win.gBrowser.removeCurrentTab();
       ok(win.closed, "popup is closed");
 
--- a/browser/base/content/test/browser_getshortcutoruri.js
+++ b/browser/base/content/test/browser_getshortcutoruri.js
@@ -95,39 +95,35 @@ function test() {
   }
 
   cleanupKeywords();
 }
 
 var gBMFolder = null;
 var gAddedEngines = [];
 function setupKeywords() {
-  var searchService = Cc["@mozilla.org/browser/search-service;1"].
-                      getService(Ci.nsIBrowserSearchService);
   gBMFolder = Application.bookmarks.menu.addFolder("keyword-test");
   for each (var item in testData) {
     var data = item[0];
     if (data instanceof bmKeywordData) {
       var bm = gBMFolder.addBookmark(data.keyword, data.uri);
       bm.keyword = data.keyword;
       if (data.postData)
         bm.annotations.set("bookmarkProperties/POSTData", data.postData, Ci.nsIAnnotationService.EXPIRE_SESSION);
     }
 
     if (data instanceof searchKeywordData) {
-      searchService.addEngineWithDetails(data.keyword, "", data.keyword, "", data.method, data.uri.spec);
-      var addedEngine = searchService.getEngineByName(data.keyword);
+      Services.search.addEngineWithDetails(data.keyword, "", data.keyword, "", data.method, data.uri.spec);
+      var addedEngine = Services.search.getEngineByName(data.keyword);
       if (data.postData) {
         var [paramName, paramValue] = data.postData.split("=");
         addedEngine.addParam(paramName, paramValue, null);
       }
 
       gAddedEngines.push(addedEngine);
     }
   }
 }
 
 function cleanupKeywords() {
-  var searchService = Cc["@mozilla.org/browser/search-service;1"].
-                      getService(Ci.nsIBrowserSearchService);
   gBMFolder.remove();
-  gAddedEngines.map(searchService.removeEngine);
+  gAddedEngines.map(Services.search.removeEngine);
 }
--- a/browser/base/content/test/browser_pageInfo.js
+++ b/browser/base/content/test/browser_pageInfo.js
@@ -1,19 +1,17 @@
-var obs = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
-
 function test() {
   waitForExplicitFinish();
 
   var pageInfo, atTest = 0;
   gBrowser.selectedTab = gBrowser.addTab();
   gBrowser.selectedBrowser.addEventListener("load", function () {
     gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
     pageInfo = BrowserPageInfo();
-    obs.addObserver(observer, "page-info-dialog-loaded", false);
+    Services.obs.addObserver(observer, "page-info-dialog-loaded", false);
   }, true);
   content.location =
     "https://example.com/browser/browser/base/content/test/feed_tab.html";
 
   function observer(win, topic, data) {
     if (topic != "page-info-dialog-loaded")
       return;
 
@@ -24,17 +22,17 @@ function test() {
         break;
       case 1:
         atTest++;
         pageInfo = win;
         testLockClick();
         break;
       case 2:
         atTest++;
-        obs.removeObserver(observer, "page-info-dialog-loaded");
+        Services.obs.removeObserver(observer, "page-info-dialog-loaded");
         testLockDoubleClick();
         break;
     }
   }
 
   function $(aId) { return pageInfo.document.getElementById(aId) };
 
   function handlePageInfo() {
@@ -71,19 +69,17 @@ function test() {
       var lockIcon = document.getElementById("security-button");
       EventUtils.synthesizeMouse(lockIcon, 0, 0, {clickCount: 1});
       EventUtils.synthesizeMouse(lockIcon, 0, 0, {clickCount: 2});
     }, false);
     pageInfo.close();
   }
 
   function testLockDoubleClick() {
-    var pageInfoDialogs = Cc["@mozilla.org/appshell/window-mediator;1"]
-                            .getService(Ci.nsIWindowMediator)
-                            .getEnumerator("Browser:page-info");
+    var pageInfoDialogs = Services.wm.getEnumerator("Browser:page-info");
     var i = 0;
     while (pageInfoDialogs.hasMoreElements()) {
       i++;
       pageInfo = pageInfoDialogs.getNext();
       pageInfo.close();
     }
     is(i, 1, "When the lock is clicked twice there should be only one page info dialog");
     gBrowser.removeCurrentTab();
--- a/browser/base/content/test/browser_pluginnotification.js
+++ b/browser/base/content/test/browser_pluginnotification.js
@@ -1,16 +1,15 @@
 const gTestRoot = "chrome://mochikit/content/browser/browser/base/content/test/";
 
 var gTestBrowser = null;
 var gNextTest = null;
 
 function get_test_plugin() {
-  var ph = Components.classes["@mozilla.org/plugin/host;1"]
-                     .getService(Components.interfaces.nsIPluginHost);
+  var ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
   var tags = ph.getPluginTags();
   
   // Find the test plugin
   for (var i = 0; i < tags.length; i++) {
     if (tags[i].name == "Test Plug-in")
       return tags[i];
   }
 }
@@ -18,19 +17,17 @@ function get_test_plugin() {
 // This listens for the next opened window and checks it is of the right url.
 // opencallback is called when the new window is fully loaded
 // closecallback is called when the window is closed
 function WindowOpenListener(url, opencallback, closecallback) {
   this.url = url;
   this.opencallback = opencallback;
   this.closecallback = closecallback;
 
-  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
-                     .getService(Components.interfaces.nsIWindowMediator);
-  wm.addListener(this);
+  Services.wm.addListener(this);
 }
 
 WindowOpenListener.prototype = {
   url: null,
   opencallback: null,
   closecallback: null,
   window: null,
   domwindow: null,
@@ -56,19 +53,17 @@ WindowOpenListener.prototype = {
                            .getInterface(Components.interfaces.nsIDOMWindowInternal);
     this.domwindow.addEventListener("load", this, false);
   },
 
   onCloseWindow: function(window) {
     if (this.window != window)
       return;
 
-    var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
-                       .getService(Components.interfaces.nsIWindowMediator);
-    wm.removeListener(this);
+    Services.wm.removeListener(this);
     this.opencallback = null;
     this.window = null;
     this.domwindow = null;
 
     // Let the window close complete
     executeSoon(this.closecallback);
     this.closecallback = null;
   }
--- a/browser/base/content/test/browser_sanitize-download-history.js
+++ b/browser/base/content/test/browser_sanitize-download-history.js
@@ -66,23 +66,21 @@ function test()
 
   function test_checkedAfterAddingDownload(aWin)
   {
     let doc = aWin.document;
     let downloads = doc.getElementById("downloads-checkbox");
     let history = doc.getElementById("history-checkbox");
 
     // Add download to DB
-    let ios = Cc["@mozilla.org/network/io-service;1"].
-              getService(Ci.nsIIOService);
     let file = Cc["@mozilla.org/file/directory_service;1"].
                getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
     file.append("satitize-dm-test.file");
     file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
-    let testPath = ios.newFileURI(file).spec;
+    let testPath = Services.io.newFileURI(file).spec;
     let data = {
       name: "381603.patch",
       source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
       target: testPath,
       startTime: 1180493839859230,
       endTime: 1180493839859239,
       state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
       currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0
@@ -137,42 +135,40 @@ function test()
   let dm = Cc["@mozilla.org/download-manager;1"].
            getService(Ci.nsIDownloadManager);
   let db = dm.DBConnection;
 
   // Empty any old downloads
   db.executeSimpleSQL("DELETE FROM moz_downloads");
 
   // Close the UI if necessary
-  let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-           getService(Ci.nsIWindowWatcher);
-  let win = ww.getWindowByName("Sanatize", null);
+  let win = Services.ww.getWindowByName("Sanatize", null);
   if (win && (win instanceof Ci.nsIDOMWindowInternal))
     win.close();
 
   // Start the test when the sanitize window loads
-  ww.registerNotification(function (aSubject, aTopic, aData) {
-    ww.unregisterNotification(arguments.callee);
+  Services.ww.registerNotification(function (aSubject, aTopic, aData) {
+    Services.ww.unregisterNotification(arguments.callee);
     aSubject.QueryInterface(Ci.nsIDOMEventTarget)
             .addEventListener("DOMContentLoaded", doTest, false);
   });
 
   // Let the methods that run onload finish before we test
   let doTest = function() setTimeout(function() {
-    let win = ww.getWindowByName("Sanitize", null)
+    let win = Services.ww.getWindowByName("Sanitize", null)
                 .QueryInterface(Ci.nsIDOMWindowInternal);
 
     for (let i = 0; i < tests.length; i++)
       tests[i](win);
 
     win.close();
     finish();
   }, 0);
  
   // Show the UI
-  ww.openWindow(window,
-                "chrome://browser/content/sanitize.xul",
-                "Sanitize",
-                "chrome,titlebar,centerscreen",
-                null);
+  Services.ww.openWindow(window,
+                         "chrome://browser/content/sanitize.xul",
+                         "Sanitize",
+                         "chrome,titlebar,centerscreen",
+                         null);
 
   waitForExplicitFinish();
 }
--- a/browser/base/content/test/browser_sanitizeDialog.js
+++ b/browser/base/content/test/browser_sanitizeDialog.js
@@ -46,25 +46,23 @@
  * test checks the UI of the dialog and makes sure it's correctly connected to
  * the sanitize timespan code.
  *
  * Some of this code, especially the history creation parts, was taken from
  * browser/base/content/test/browser_sanitize-timespans.js.
  */
 
 Cc["@mozilla.org/moz/jssubscript-loader;1"].
-  getService(Components.interfaces.mozIJSSubScriptLoader).
+  getService(Ci.mozIJSSubScriptLoader).
   loadSubScript("chrome://mochikit/content/MochiKit/packed.js");
 
 Cc["@mozilla.org/moz/jssubscript-loader;1"].
-  getService(Components.interfaces.mozIJSSubScriptLoader).
+  getService(Ci.mozIJSSubScriptLoader).
   loadSubScript("chrome://browser/content/sanitize.js");
 
-const winWatch = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-                 getService(Ci.nsIWindowWatcher);
 const dm = Cc["@mozilla.org/download-manager;1"].
            getService(Ci.nsIDownloadManager);
 const bhist = Cc["@mozilla.org/browser/global-history;2"].
               getService(Ci.nsIBrowserHistory);
 const formhist = Cc["@mozilla.org/satchel/form-history;1"].
                  getService(Ci.nsIFormHistory2);
 
 // Add tests here.  Each is a function that's called by doNextTest().
@@ -535,17 +533,17 @@ WindowHelper.prototype = {
    */
   open: function () {
     let wh = this;
 
     function windowObserver(aSubject, aTopic, aData) {
       if (aTopic != "domwindowopened")
         return;
 
-      winWatch.unregisterNotification(windowObserver);
+      Services.ww.unregisterNotification(windowObserver);
 
       var loaded = false;
       let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
 
       win.addEventListener("load", function onload(event) {
         win.removeEventListener("load", onload, false);
 
         if (win.name !== "SanitizeDialog")
@@ -592,22 +590,22 @@ WindowHelper.prototype = {
           catch (exc) {
             win.close();
             ok(false, "Unexpected exception: " + exc + "\n" + exc.stack);
             finish();
           }
         });
       }, false);
     }
-    winWatch.registerNotification(windowObserver);
-    winWatch.openWindow(null,
-                        "chrome://browser/content/sanitize.xul",
-                        "SanitizeDialog",
-                        "chrome,titlebar,dialog,centerscreen,modal",
-                        null);
+    Services.ww.registerNotification(windowObserver);
+    Services.ww.openWindow(null,
+                           "chrome://browser/content/sanitize.xul",
+                           "SanitizeDialog",
+                           "chrome,titlebar,dialog,centerscreen,modal",
+                           null);
   },
 
   /**
    * Selects a duration in the duration dropdown.
    *
    * @param aDurVal
    *        One of the Sanitizer.TIMESPAN_* values
    */
--- a/browser/base/content/test/browser_sanitizeDialog_treeView.js
+++ b/browser/base/content/test/browser_sanitizeDialog_treeView.js
@@ -45,25 +45,23 @@
  * test checks the UI of the dialog and makes sure it's correctly connected to
  * the sanitize timespan code.
  *
  * Some of this code, especially the history creation parts, was taken from
  * browser/base/content/test/browser_sanitize-timespans.js.
  */
 
 Cc["@mozilla.org/moz/jssubscript-loader;1"].
-  getService(Components.interfaces.mozIJSSubScriptLoader).
+  getService(Ci.mozIJSSubScriptLoader).
   loadSubScript("chrome://mochikit/content/MochiKit/packed.js");
 
 Cc["@mozilla.org/moz/jssubscript-loader;1"].
-  getService(Components.interfaces.mozIJSSubScriptLoader).
+  getService(Ci.mozIJSSubScriptLoader).
   loadSubScript("chrome://browser/content/sanitize.js");
 
-const winWatch = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-                 getService(Ci.nsIWindowWatcher);
 const dm = Cc["@mozilla.org/download-manager;1"].
            getService(Ci.nsIDownloadManager);
 const bhist = Cc["@mozilla.org/browser/global-history;2"].
               getService(Ci.nsIBrowserHistory);
 const formhist = Cc["@mozilla.org/satchel/form-history;1"].
                  getService(Ci.nsIFormHistory2);
 
 // Add tests here.  Each is a function that's called by doNextTest().
@@ -617,17 +615,17 @@ function ensureHistoryClearedState(aURIs
  * @param aOnloadCallback
  *        A function that will be called once the dialog has loaded
  */
 function openWindow(aOnloadCallback) {
   function windowObserver(aSubject, aTopic, aData) {
     if (aTopic != "domwindowopened")
       return;
 
-    winWatch.unregisterNotification(windowObserver);
+    Services.ww.unregisterNotification(windowObserver);
     let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
     win.addEventListener("load", function onload(event) {
       win.removeEventListener("load", onload, false);
       executeSoon(function () {
         // Some exceptions that reach here don't reach the test harness, but
         // ok()/is() do...
         try {
           aOnloadCallback(win);
@@ -636,22 +634,22 @@ function openWindow(aOnloadCallback) {
         catch (exc) {
           win.close();
           ok(false, "Unexpected exception: " + exc + "\n" + exc.stack);
           finish();
         }
       });
     }, false);
   }
-  winWatch.registerNotification(windowObserver);
-  winWatch.openWindow(null,
-                      "chrome://browser/content/sanitize.xul",
-                      "Sanitize",
-                      "chrome,titlebar,dialog,centerscreen,modal",
-                      null);
+  Services.ww.registerNotification(windowObserver);
+  Services.ww.openWindow(null,
+                         "chrome://browser/content/sanitize.xul",
+                         "Sanitize",
+                         "chrome,titlebar,dialog,centerscreen,modal",
+                         null);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 
 function test() {
   blankSlate();
   waitForExplicitFinish();
   // Kick off all the tests in the gAllTests array.
--- a/browser/components/preferences/tests/browser_bug410900.js
+++ b/browser/components/preferences/tests/browser_bug410900.js
@@ -11,27 +11,24 @@ function test() {
               getService(Ci.nsIExternalProtocolService);
   var info = extps.getProtocolHandlerInfo("apppanetest");
   info.possibleApplicationHandlers.appendElement(handler, false);
 
   var hserv = Cc["@mozilla.org/uriloader/handler-service;1"].
               getService(Ci.nsIHandlerService);
   hserv.store(info);
 
-  var obs = Cc["@mozilla.org/observer-service;1"].
-            getService(Ci.nsIObserverService);
-
   function observer(win, topic, data) {
     if (topic != "app-handler-pane-loaded")
       return;
 
-    obs.removeObserver(observer, "app-handler-pane-loaded");
+    Services.obs.removeObserver(observer, "app-handler-pane-loaded");
     runTest(win);
   }
-  obs.addObserver(observer, "app-handler-pane-loaded", false);
+  Services.obs.addObserver(observer, "app-handler-pane-loaded", false);
 
   openDialog("chrome://browser/content/preferences/preferences.xul", "Preferences",
              "chrome,titlebar,toolbar,centerscreen,dialog=no", "paneApplications");
 }
 
 function runTest(win) {
   var sel = win.document.documentElement.getAttribute("lastSelected");
   ok(sel == "paneApplications", "Specified pane was opened");
--- a/browser/components/preferences/tests/privacypane_tests.js
+++ b/browser/components/preferences/tests/privacypane_tests.js
@@ -31,38 +31,36 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  * 
  * ***** END LICENSE BLOCK ***** */
 
 function runTestOnPrivacyPrefPane(testFunc) {
-  let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-           getService(Ci.nsIWindowWatcher);
   let observer = {
     observe: function(aSubject, aTopic, aData) {
       if (aTopic == "domwindowopened") {
-        ww.unregisterNotification(this);
+        Services.ww.unregisterNotification(this);
 
         let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
         win.addEventListener("load", function() {
           win.removeEventListener("load", arguments.callee, false);
           testFunc(dialog.document.defaultView);
 
-          ww.registerNotification(observer);
+          Services.ww.registerNotification(observer);
           dialog.close();
         }, false);
       } else if (aTopic == "domwindowclosed") {
-        ww.unregisterNotification(this);
+        Services.ww.unregisterNotification(this);
         testRunner.runNext();
       }
     }
   };
-  ww.registerNotification(observer);
+  Services.ww.registerNotification(observer);
 
   let dialog = openDialog("chrome://browser/content/preferences/preferences.xul", "Preferences",
                           "chrome,titlebar,toolbar,centerscreen,dialog=no", "panePrivacy");
 }
 
 function controlChanged(element) {
   element.doCommand();
 }
@@ -523,30 +521,28 @@ function reset_preferences(win) {
   let prefs = win.document.getElementsByTagName("preference");
   for (let i = 0; i < prefs.length; ++i)
     if (prefs[i].hasUserValue)
       prefs[i].reset();
 }
 
 let testRunner;
 function run_test_subset(subset) {
-  let psvc = Cc["@mozilla.org/preferences-service;1"].
-             getService(Ci.nsIPrefBranch);
-  let instantApplyOrig = psvc.getBoolPref("browser.preferences.instantApply");
-  psvc.setBoolPref("browser.preferences.instantApply", true);
+  let instantApplyOrig = Services.prefs.getBoolPref("browser.preferences.instantApply");
+  Services.prefs.setBoolPref("browser.preferences.instantApply", true);
 
   waitForExplicitFinish();
 
   testRunner = {
     tests: subset,
     counter: 0,
     runNext: function() {
       if (this.counter == this.tests.length) {
         // cleanup
-        psvc.setBoolPref("browser.preferences.instantApply", instantApplyOrig);
+        Services.prefs.setBoolPref("browser.preferences.instantApply", instantApplyOrig);
         finish();
       } else {
         let self = this;
         setTimeout(function() {
           runTestOnPrivacyPrefPane(self.tests[self.counter++]);
         }, 0);
       }
     }
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_beforeunload.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_beforeunload.js
@@ -52,19 +52,17 @@ function test() {
     let dialogWin = aSubject.QueryInterface(Ci.nsIDOMWindow);
     confirmCalls++;
     if (acceptDialog-- > 0)
       dialogWin.document.documentElement.getButton("accept").click();
     else if (rejectDialog-- > 0)
       dialogWin.document.documentElement.getButton("cancel").click();
   }
 
-  Cc["@mozilla.org/observer-service;1"]
-    .getService(Ci.nsIObserverService)
-    .addObserver(promptObserver, "common-dialog-loaded", false);
+  Services.obs.addObserver(promptObserver, "common-dialog-loaded", false);
 
   waitForExplicitFinish();
   let browser1 = gBrowser.getBrowserForTab(gBrowser.addTab());
   browser1.addEventListener("load", function() {
     browser1.removeEventListener("load", arguments.callee, true);
 
     let browser2 = gBrowser.getBrowserForTab(gBrowser.addTab());
     browser2.addEventListener("load", function() {
@@ -145,19 +143,17 @@ function test() {
                  "The last tab should be the same one we opened");
               is(acceptDialog, 0, "Two confirm dialogs should have been accepted");
               is(acceptDialog, 0, "Two prompts should have been raised");
 
               acceptDialog = 2;
               gBrowser.removeTab(gBrowser.tabContainer.lastChild);
               gBrowser.removeTab(gBrowser.tabContainer.lastChild);
 
-              Cc["@mozilla.org/observer-service;1"]
-                .getService(Ci.nsIObserverService)
-                .removeObserver(promptObserver, "common-dialog-loaded", false);
+              Services.obs.removeObserver(promptObserver, "common-dialog-loaded", false);
               finish();
             }
             for (let i = 0; i < gBrowser.browsers.length; ++i)
               gBrowser.browsers[i].addEventListener("load", waitForLoad, true);
           }, true);
           gBrowser.selectedBrowser.loadURI(TEST_PAGE_2);
         }, true);
         gBrowser.selectedBrowser.loadURI(TEST_PAGE_1);
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_certexceptionsui.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_certexceptionsui.js
@@ -58,20 +58,18 @@ function test() {
   function step1() {
     let params = {
       exceptionAdded : false,
       location: INVALID_CERT_LOCATION,
       handlePrivateBrowsing : true,
       prefetchCert: true,
     };
     function testCheckbox() {
-      let obsSvc = Cc["@mozilla.org/observer-service;1"].
-                   getService(Ci.nsIObserverService);
-      obsSvc.addObserver(function (aSubject, aTopic, aData) {
-        obsSvc.removeObserver(arguments.callee, "cert-exception-ui-ready", false);
+      Services.obs.addObserver(function (aSubject, aTopic, aData) {
+        Services.obs.removeObserver(arguments.callee, "cert-exception-ui-ready", false);
         ok(win.gCert, "The certificate information should be available now");
 
         let checkbox = win.document.getElementById("permanent");
         ok(checkbox.hasAttribute("disabled"),
           "the permanent checkbox should be disabled when handling the private browsing mode");
         ok(!checkbox.hasAttribute("checked"),
           "the permanent checkbox should not be checked when handling the private browsing mode");
         win.close();
@@ -85,20 +83,18 @@ function test() {
   // Test the certificate excetions dialog as it is invoked from the Preferences dialog
   function step2() {
     let params = {
       exceptionAdded : false,
       location: INVALID_CERT_LOCATION,
       prefetchCert: true,
     };
     function testCheckbox() {
-      let obsSvc = Cc["@mozilla.org/observer-service;1"].
-                   getService(Ci.nsIObserverService);
-      obsSvc.addObserver(function (aSubject, aTopic, aData) {
-        obsSvc.removeObserver(arguments.callee, "cert-exception-ui-ready", false);
+      Services.obs.addObserver(function (aSubject, aTopic, aData) {
+        Services.obs.removeObserver(arguments.callee, "cert-exception-ui-ready", false);
         ok(win.gCert, "The certificate information should be available now");
 
         let checkbox = win.document.getElementById("permanent");
         ok(!checkbox.hasAttribute("disabled"),
           "the permanent checkbox should not be disabled when not handling the private browsing mode");
         ok(checkbox.hasAttribute("checked"),
           "the permanent checkbox should be checked when not handling the private browsing mode");
         win.close();
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_commandline_toggle.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_commandline_toggle.js
@@ -37,18 +37,16 @@
 
 // This test makes sure that private browsing toggles correctly via the -private
 // command line argument.
 
 function test() {
   // initialization
   let pb = Cc["@mozilla.org/privatebrowsing;1"].
            getService(Ci.nsIPrivateBrowsingService);
-  let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-           getService(Ci.nsIWindowWatcher);
 
   waitForExplicitFinish();
 
   function simulatePrivateCommandLineArgument() {
     function testprivatecl() {
     }
 
     testprivatecl.prototype = {
@@ -115,17 +113,17 @@ function test() {
       let handler = Cc[contractID].getService(Ci.nsICommandLineHandler);
       handler.handle(testcl);
     }
   }
 
   function observer(aSubject, aTopic, aData) {
     isnot(aTopic, "domwindowopened", "The -private-toggle argument should be silent");
   }
-  ww.registerNotification(observer);
+  Services.ww.registerNotification(observer);
 
   let tab = gBrowser.selectedTab;
   let browser = gBrowser.getBrowserForTab(tab);
   browser.addEventListener("load", function () {
     browser.removeEventListener("load", arguments.callee, true);
     ok(!pb.privateBrowsingEnabled, "The private browsing mode should not be started");
     is(browser.contentWindow.location, "about:", "The correct page has been loaded");
 
@@ -144,15 +142,15 @@ function test() {
       browser.addEventListener("load", function() {
         browser.removeEventListener("load", arguments.callee, true);
         ok(!pb.privateBrowsingEnabled, "The private browsing mode should be stopped");
         is(browser.contentWindow.location, "about:",
            "about: should now be loaded");
 
         let newTab = gBrowser.addTab();
         gBrowser.removeTab(tab);
-        ww.unregisterNotification(observer);
+        Services.ww.unregisterNotification(observer);
         finish();
       }, true);
     }, true);
   }, true);
   browser.loadURI("about:");
 }
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cookieacceptdialog.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cookieacceptdialog.js
@@ -37,29 +37,27 @@
 
 // This test makes sure that private browsing mode disables the "remember"
 // option in the cookie accept dialog.
 
 function test() {
   // initialization
   let pb = Cc["@mozilla.org/privatebrowsing;1"].
            getService(Ci.nsIPrivateBrowsingService);
-  let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-           getService(Ci.nsIWindowWatcher);
   let cp = Cc["@mozilla.org/embedcomp/cookieprompt-service;1"].
            getService(Ci.nsICookiePromptService);
 
   waitForExplicitFinish();
 
   function checkRememberOption(expectedDisabled, callback) {
     function observer(aSubject, aTopic, aData) {
       if (aTopic != "domwindowopened")
         return;
 
-      ww.unregisterNotification(observer);
+      Services.ww.unregisterNotification(observer);
       let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
       win.addEventListener("load", function onLoad(event) {
         win.removeEventListener("load", onLoad, false);
 
         executeSoon(function () {
           let doc = win.document;
           let remember = doc.getElementById("persistDomainAcceptance");
           ok(remember, "The remember checkbox should exist");
@@ -71,17 +69,17 @@ function test() {
             ok(!remember.hasAttribute("disabled"),
                "The checkbox should not be disabled");
 
           win.close();
           callback();
         });
       }, false);
     }
-    ww.registerNotification(observer);
+    Services.ww.registerNotification(observer);
 
     let remember = {};
     const time = (new Date("Jan 1, 2030")).getTime() / 1000;
     let cookie = {
       name: "foo",
       value: "bar",
       isDomain: true,
       host: "mozilla.org",
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_downloadmonitor.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_downloadmonitor.js
@@ -41,18 +41,16 @@
 function test() {
   // initialization
   let pb = Cc["@mozilla.org/privatebrowsing;1"].
            getService(Ci.nsIPrivateBrowsingService);
   let dm = Cc["@mozilla.org/download-manager;1"].
            getService(Ci.nsIDownloadManager);
   if (!gDownloadMgr)
     gDownloadMgr = dm;
-  let iosvc = Cc["@mozilla.org/network/io-service;1"].
-              getService(Ci.nsIIOService);
   let panel = document.getElementById("download-monitor");
   waitForExplicitFinish();
 
   // Add a new download
   addDownload(dm, {
     resultFileName: "pbtest-1",
     downloadName: "PB Test 1"
   });
@@ -154,15 +152,13 @@ function addDownload(dm, aParams)
   aParams.runBeforeStart.call(undefined, dl);
 
   persist.progressListener = dl.QueryInterface(Ci.nsIWebProgressListener);
   persist.saveURI(dl.source, null, null, null, null, dl.targetFile);
 
   return dl;
 }
 
-function createURI(aObj)
-{
-  let ios = Cc["@mozilla.org/network/io-service;1"].
-            getService(Ci.nsIIOService);
+function createURI(aObj) {
+  let ios = Services.io;
   return (aObj instanceof Ci.nsIFile) ? ios.newFileURI(aObj) :
                                         ios.newURI(aObj, null, null);
 }
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_forgetthissite.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_forgetthissite.js
@@ -37,34 +37,32 @@
 
 // This test makes sure that the Forget This Site command is hidden in private
 // browsing mode.
 
 function test() {
   // initialization
   let pb = Cc["@mozilla.org/privatebrowsing;1"].
            getService(Ci.nsIPrivateBrowsingService);
-  let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-           getService(Ci.nsIWindowWatcher);
   waitForExplicitFinish();
 
   // Add a history entry.
   const TEST_URI = "http://www.mozilla.org/privatebrowsing";
   ok(PlacesUtils, "checking PlacesUtils, running in chrome context?");
   let history = PlacesUtils.history;
   let visitId = history.addVisit(PlacesUtils._uri(TEST_URI), Date.now() * 1000,
                                  null, PlacesUtils.history.TRANSITION_TYPED, false, 0);
   ok(visitId > 0, TEST_URI + " successfully marked visited");
 
   function testForgetThisSiteVisibility(expected, funcNext) {
     function observer(aSubject, aTopic, aData) {
       if (aTopic != "domwindowopened")
         return;
 
-      ww.unregisterNotification(observer);
+      Services.ww.unregisterNotification(observer);
       let organizer = aSubject.QueryInterface(Ci.nsIDOMWindow);
       organizer.addEventListener("load", function onLoad(event) {
         organizer.removeEventListener("load", onLoad, false);
         executeSoon(function () {
           // Select History in the left pane.
           let PO = organizer.PlacesOrganizer;
           PO.selectLeftPaneQuery('History');
           let histContainer = PO._places.selectedNode.QueryInterface(Ci.nsINavHistoryContainerResultNode);
@@ -98,22 +96,22 @@ function test() {
           event.initMouseEvent("contextmenu", true, true, organizer, 0,
                                0, 0, 0, 0, false, false, false, false,
                                0, null);
           tree.dispatchEvent(event);
         });
       }, false);
     }
 
-    ww.registerNotification(observer);
-    ww.openWindow(null,
-                  "chrome://browser/content/places/places.xul",
-                  "",
-                  "chrome,toolbar=yes,dialog=no,resizable",
-                  null);
+    Services.ww.registerNotification(observer);
+    Services.ww.openWindow(null,
+                           "chrome://browser/content/places/places.xul",
+                           "",
+                           "chrome,toolbar=yes,dialog=no,resizable",
+                           null);
   }
 
   testForgetThisSiteVisibility(true, function() {
     // Enter private browsing mode
     pb.privateBrowsingEnabled = true;
     testForgetThisSiteVisibility(false, function() {
       // Leave private browsing mode
       pb.privateBrowsingEnabled = false;
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_transition.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_transition.js
@@ -37,41 +37,39 @@
  
 // Tests the order of events and notifications when entering/exiting private
 // browsing mode. This ensures that all private data is removed on exit, e.g.
 // a cookie set in on unload handler, see bug 476463.
 let cookieManager = Cc["@mozilla.org/cookiemanager;1"].
                     getService(Ci.nsICookieManager2);
 let pb = Cc["@mozilla.org/privatebrowsing;1"].
          getService(Ci.nsIPrivateBrowsingService);
-let _obs = Cc["@mozilla.org/observer-service;1"].
-           getService(Ci.nsIObserverService);
 let observerNotified = 0, firstUnloadFired = 0, secondUnloadFired = 0;
 
 function pbObserver(aSubject, aTopic, aData) {
   if (aTopic != "private-browsing")
     return;
   switch (aData) {
     case "enter":
       observerNotified++;
       is(observerNotified, 1, "This should be the first notification");
       is(firstUnloadFired, 1, "The first unload event should have been processed by now");
       break;
     case "exit":
-      _obs.removeObserver(pbObserver, "private-browsing");
+      Services.obs.removeObserver(pbObserver, "private-browsing");
       observerNotified++;
       is(observerNotified, 2, "This should be the second notification");
       is(secondUnloadFired, 1, "The second unload event should have been processed by now");
       break;
   }
 }
 
 function test() {
   waitForExplicitFinish();
-  _obs.addObserver(pbObserver, "private-browsing", false);
+  Services.obs.addObserver(pbObserver, "private-browsing", false);
   is(gBrowser.tabs.length, 1, "There should only be one tab");
   let testTab = gBrowser.addTab();
   gBrowser.selectedTab = testTab;
   testTab.linkedBrowser.addEventListener("unload", function () {
     testTab.linkedBrowser.removeEventListener("unload", arguments.callee, true);
     firstUnloadFired++;
     is(observerNotified, 0, "The notification shouldn't have been sent yet");
   }, true);
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_ui.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_ui.js
@@ -43,19 +43,17 @@ function test() {
   gPrefService.setBoolPref("browser.privatebrowsing.keep_current_session", true);
   let pb = Cc["@mozilla.org/privatebrowsing;1"].
            getService(Ci.nsIPrivateBrowsingService);
   let observerData;
   function observer(aSubject, aTopic, aData) {
     if (aTopic == "private-browsing")
       observerData = aData;
   }
-  let os = Cc["@mozilla.org/observer-service;1"].
-           getService(Ci.nsIObserverService);
-  os.addObserver(observer, "private-browsing", false);
+  Services.obs.addObserver(observer, "private-browsing", false);
   let pbMenuItem = document.getElementById("privateBrowsingItem");
   // add a new blank tab to ensure the title can be meaningfully compared later
   gBrowser.selectedTab = gBrowser.addTab();
   let originalTitle = document.title;
 
   // test the gPrivateBrowsingUI object
   ok(gPrivateBrowsingUI, "The gPrivateBrowsingUI object exists");
   is(pb.privateBrowsingEnabled, false, "The private browsing mode should not be started initially");
@@ -87,11 +85,11 @@ function test() {
   func.call(cmd);
   // check to see if the Private Browsing mode was deactivated successfully
   is(observerData, "exit", "Private Browsing mode was deactivated using the command object");
   // check to see that the window title has been restored correctly
   is(document.title, originalTitle, "Private browsing mode has correctly restored the title");
 
   // cleanup
   gBrowser.removeCurrentTab();
-  os.removeObserver(observer, "private-browsing");
+  Services.obs.removeObserver(observer, "private-browsing");
   gPrefService.clearUserPref("browser.privatebrowsing.keep_current_session");
 }
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_urlbarundo.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_urlbarundo.js
@@ -34,19 +34,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 // This test makes sure that the undo history of the URL bar is cleared when
 // leaving the private browsing mode.
 
 function test() {
   // initialization
-  let prefBranch = Cc["@mozilla.org/preferences-service;1"].
-                   getService(Ci.nsIPrefBranch);
-  prefBranch.setBoolPref("browser.privatebrowsing.keep_current_session", true);
+  Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
   let pb = Cc["@mozilla.org/privatebrowsing;1"].
            getService(Ci.nsIPrivateBrowsingService);
 
   // enter private browsing mode
   pb.privateBrowsingEnabled = true;
 
   // fill in the URL bar with something
   gURLBar.value = "some test value";
@@ -56,11 +54,11 @@ function test() {
 
   // leave private browsing mode
   pb.privateBrowsingEnabled = false;
 
   is(gURLBar.editor.transactionManager.numberOfUndoItems, 0,
      "The undo history of the URL bar should be cleared after leaving the private browsing mode");
 
   // cleanup
-  prefBranch.clearUserPref("browser.privatebrowsing.keep_current_session");
+  Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
 }
 
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_viewsource.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_viewsource.js
@@ -45,58 +45,56 @@ function test() {
 
   waitForExplicitFinish();
 
   gBrowser.selectedTab = gBrowser.addTab();
   let aboutBrowser = gBrowser.selectedBrowser;
   aboutBrowser.addEventListener("load", function () {
     aboutBrowser.removeEventListener("load", arguments.callee, true);
 
-    let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-             getService(Ci.nsIWindowWatcher);
     function observer(aSubject, aTopic, aData) {
       if (aTopic != "domwindowopened")
         return;
 
-      ww.unregisterNotification(observer);
+      Services.ww.unregisterNotification(observer);
 
       let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
       win.addEventListener("load", function () {
         win.removeEventListener("load", arguments.callee, false);
 
         let browser = win.gBrowser;
         browser.addEventListener("load", function () {
           browser.removeEventListener("load", arguments.callee, true);
           
           // view source window is loaded, proceed with the rest of the test
           step1();
         }, true);
       }, false);
     }
-    ww.registerNotification(observer);
+    Services.ww.registerNotification(observer);
 
     openViewSource();
 
     function openViewSource() {
       // invoke the View Source command
       document.getElementById("View:PageSource").doCommand();
     }
 
     function step1() {
       function observer(aSubject, aTopic, aData) {
         if (aTopic == "domwindowclosed") {
           ok(true, "Entering the private browsing mode should close the view source window");
-          ww.unregisterNotification(observer);
+          Services.ww.unregisterNotification(observer);
 
           step2();
         }
         else if (aTopic == "domwindowopened")
           ok(false, "Entering the private browsing mode should not open any view source window");
       }
-      ww.registerNotification(observer);
+      Services.ww.registerNotification(observer);
 
       gBrowser.addTabsProgressListener({
         onLocationChange: function() {},
         onProgressChange: function() {},
         onSecurityChange: function() {},
         onStatusChange: function() {},
         onRefreshAttempted: function() {},
         onStateChange: function(aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) {
@@ -119,49 +117,49 @@ function test() {
         step4();
     }
 
     function step4() {
       function observer(aSubject, aTopic, aData) {
         if (aTopic != "domwindowopened")
           return;
 
-        ww.unregisterNotification(observer);
+        Services.ww.unregisterNotification(observer);
 
         let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
         win.addEventListener("load", function () {
           win.removeEventListener("load", arguments.callee, false);
 
           let browser = win.gBrowser;
           browser.addEventListener("load", function () {
             browser.removeEventListener("load", arguments.callee, true);
             
             // view source window inside private browsing mode opened
             step5();
           }, true);
         }, false);
       }
-      ww.registerNotification(observer);
+      Services.ww.registerNotification(observer);
 
       openViewSource();
     }
 
     function step5() {
       let events = 0;
 
       function observer(aSubject, aTopic, aData) {
         if (aTopic == "domwindowclosed") {
           ok(true, "Leaving the private browsing mode should close the existing view source window");
           if (++events == 2)
-            ww.unregisterNotification(observer);
+            Services.ww.unregisterNotification(observer);
         }
         else if (aTopic == "domwindowopened") {
           ok(true, "Leaving the private browsing mode should restore the previous view source window");
           if (++events == 2)
-            ww.unregisterNotification(observer);
+            Services.ww.unregisterNotification(observer);
 
           let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
           win.addEventListener("load", function () {
             win.removeEventListener("load", arguments.callee, false);
 
             let browser = win.gBrowser;
             browser.addEventListener("load", function () {
               browser.removeEventListener("load", arguments.callee, true);
@@ -172,16 +170,16 @@ function test() {
               // cleanup
               win.close();
               gBrowser.removeCurrentTab();
               finish();
             }, true);
           }, false);
         }
       }
-      ww.registerNotification(observer);
+      Services.ww.registerNotification(observer);
 
       // exit private browsing mode
       pb.privateBrowsingEnabled = false;
     }
   }, true);
   aboutBrowser.loadURI("about:");
 }
--- a/browser/components/search/test/browser_415700.js
+++ b/browser/components/search/test/browser_415700.js
@@ -28,20 +28,17 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
-var gSS = Cc["@mozilla.org/browser/search-service;1"].
-           getService(Ci.nsIBrowserSearchService);
-var gObs = Cc["@mozilla.org/observer-service;1"].
-           getService(Ci.nsIObserverService);
+var gSS = Services.search;
 
 function observers(aSubject, aTopic, aData) {
   switch (aData) {
     case "engine-added":
       test2();
       break;
     case "engine-current":
       test3();
@@ -49,17 +46,17 @@ function observers(aSubject, aTopic, aDa
     case "engine-removed":
       test4();
       break;
   }
 }
 
 function test() {
   waitForExplicitFinish();
-  gObs.addObserver(observers, "browser-search-engine-modified", false);
+  Services.obs.addObserver(observers, "browser-search-engine-modified", false);
 
   gSS.addEngine("http://mochi.test:8888/browser/browser/components/search/test/testEngine.xml",
                 Ci.nsISearchEngine.DATA_XML, "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGklEQVQoz2NgGB6AnZ1dUlJSXl4eSDIyMhLW4Ovr%2B%2Fr168uXL69Zs4YoG%2BLi4i5dusTExMTGxsbNzd3f37937976%2BnpmZmagbHR09J49e5YvX66kpATVEBYW9ubNm2nTphkbG7e2tp44cQLIuHfvXm5urpaWFlDKysqqu7v73LlzECMYIiIiHj58mJCQoKKicvXq1bS0NKBgW1vbjh074uPjgeqAXE1NzSdPnvDz84M0AEUvXLgAsW379u1z5swBen3jxo2zZ892cHB4%2BvQp0KlAfwI1cHJyghQFBwfv2rULokFXV%2FfixYu7d%2B8GGqGgoMDKyrpu3br9%2B%2FcDuXl5eVA%2FAEWBfoWHAdAYoNuAYQ0XAeoUERFhGDYAAPoUaT2dfWJuAAAAAElFTkSuQmCC",
                 false);
 }
 
 function test2() {
   var engine = gSS.getEngineByName("Foo");
@@ -78,11 +75,11 @@ function test3() {
   gSS.removeEngine(engine);
 }
 
 function test4() {
   var engine = gSS.currentEngine;
   ok(engine, "An engine is present.");
   isnot(engine.name, "Foo", "Current engine reset after removal");
 
-  gObs.removeObserver(observers, "browser-search-engine-modified");
+  Services.obs.removeObserver(observers, "browser-search-engine-modified");
   finish();
 }
--- a/browser/components/search/test/browser_426329.js
+++ b/browser/components/search/test/browser_426329.js
@@ -3,41 +3,38 @@ function test() {
 
   var searchBar = BrowserSearch.searchBar;
   var searchButton = document.getAnonymousElementByAttribute(searchBar,
                      "anonid", "search-go-button");
   ok(searchButton, "got search-go-button");
 
   searchBar.value = "test";
 
-  var obs = Cc["@mozilla.org/observer-service;1"].
-            getService(Ci.nsIObserverService);
-  var ss = Cc["@mozilla.org/browser/search-service;1"].
-           getService(Ci.nsIBrowserSearchService);
+  var ss = Services.search;
 
   function observer(aSub, aTopic, aData) {
     switch (aData) {
       case "engine-added":
         var engine = ss.getEngineByName("Bug 426329");
         ok(engine, "Engine was added.");
         //XXX Bug 493051
         //ss.currentEngine = engine;
         break;
       case "engine-current":
         ok(ss.currentEngine.name == "Bug 426329", "currentEngine set");
         testReturn();
         break;
       case "engine-removed":
-        obs.removeObserver(observer, "browser-search-engine-modified");
+        Services.obs.removeObserver(observer, "browser-search-engine-modified");
         finish();
         break;
     }
   }
 
-  obs.addObserver(observer, "browser-search-engine-modified", false);
+  Services.obs.addObserver(observer, "browser-search-engine-modified", false);
   ss.addEngine("http://mochi.test:8888/browser/browser/components/search/test/426329.xml",
                Ci.nsISearchEngine.DATA_XML, "data:image/x-icon,%00",
                false);
 
   var preSelectedBrowser, preTabNo;
   function init() {
     preSelectedBrowser = gBrowser.selectedBrowser;
     preTabNo = gBrowser.mTabs.length;
--- a/browser/components/search/test/browser_483086.js
+++ b/browser/components/search/test/browser_483086.js
@@ -28,59 +28,58 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
-let gSS = Cc["@mozilla.org/browser/search-service;1"].
-           getService(Ci.nsIBrowserSearchService);
+let gSS = Services.search;
 let gObs = Cc["@mozilla.org/observer-service;1"].
            getService(Ci.nsIObserverService);
 
 function test() {
   waitForExplicitFinish();
 
   function observer(aSubject, aTopic, aData) {
     switch (aData) {
       case "engine-added":
         let engine = gSS.getEngineByName("483086a");
         ok(engine, "Test engine 1 installed");
         isnot(engine.searchForm, "foo://example.com",
               "Invalid SearchForm URL dropped");
         gSS.removeEngine(engine);
         break;
       case "engine-removed":
-        gObs.removeObserver(observer, "browser-search-engine-modified");
+        Services.obs.removeObserver(observer, "browser-search-engine-modified");
         test2();
         break;
     }
   }
 
-  gObs.addObserver(observer, "browser-search-engine-modified", false);
+  Services.obs.addObserver(observer, "browser-search-engine-modified", false);
   gSS.addEngine("http://mochi.test:8888/browser/browser/components/search/test/483086-1.xml",
                 Ci.nsISearchEngine.DATA_XML, "data:image/x-icon;%00",
                 false);
 }
 
 function test2() {
   function observer(aSubject, aTopic, aData) {
     switch (aData) {
       case "engine-added":
         let engine = gSS.getEngineByName("483086b");
         ok(engine, "Test engine 2 installed");
         is(engine.searchForm, "http://example.com", "SearchForm is correct");
         gSS.removeEngine(engine);
         break;
       case "engine-removed":  
-        gObs.removeObserver(observer, "browser-search-engine-modified");
+        Services.obs.removeObserver(observer, "browser-search-engine-modified");
         finish();
         break;
     }
   }
 
-  gObs.addObserver(observer, "browser-search-engine-modified", false);
+  Services.obs.addObserver(observer, "browser-search-engine-modified", false);
   gSS.addEngine("http://mochi.test:8888/browser/browser/components/search/test/483086-2.xml",
                 Ci.nsISearchEngine.DATA_XML, "data:image/x-icon;%00",
                 false);
 }
--- a/browser/components/sessionstore/test/browser/browser_248970_a.js
+++ b/browser/components/sessionstore/test/browser/browser_248970_a.js
@@ -58,23 +58,21 @@ function test() {
   function getSessionstorejsModificationTime() {
     let file = getSessionstoreFile();
     if (file.exists())
       return file.lastModifiedTime;
     else
       return -1;
   }
 
-  let os = Cc["@mozilla.org/observer-service;1"].
-           getService(Ci.nsIObserverService);
   function waitForFileExistence(aMessage, aDoNext) {
     const TOPIC = "sessionstore-state-write-complete";
-    os.addObserver(function (aSubject, aTopic, aData) {
+    Services.obs.addObserver(function (aSubject, aTopic, aData) {
       // Remove the observer so we do not leak.
-      os.removeObserver(arguments.callee, TOPIC);
+      Services.obs.removeObserver(arguments.callee, TOPIC);
 
       // Check that the file exists.
       ok(getSessionstoreFile().exists(), aMessage);
 
       // Run our next set of work.
       aDoNext();
     }, TOPIC, false);
   }
--- a/browser/components/sessionstore/test/browser/browser_354894.js
+++ b/browser/components/sessionstore/test/browser/browser_354894.js
@@ -104,19 +104,17 @@
  * nsSessionStore restore a window next time it gets a chance and will post
  * notifications. The latter won't.
  */
 
 function browserWindowsCount(expected, msg) {
   if (typeof expected == "number")
     expected = [expected, expected];
   let count = 0;
-  let e = Cc["@mozilla.org/appshell/window-mediator;1"]
-            .getService(Ci.nsIWindowMediator)
-            .getEnumerator("navigator:browser");
+  let e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     if (!e.getNext().closed)
       ++count;
   }
   is(count, expected[0], msg + " (nsIWindowMediator)");
   let state = Cc["@mozilla.org/browser/sessionstore;1"]
                 .getService(Ci.nsISessionStore)
                 .getBrowserState();
@@ -167,18 +165,16 @@ function test() {
     observing[aTopic]++;
 
     // handle some tests
     if (++hitCount == 1) {
       // Test 6
       aCancel.QueryInterface(Ci.nsISupportsPRBool).data = true;
     }
   }
-  let observerService = Cc["@mozilla.org/observer-service;1"].
-                        getService(Ci.nsIObserverService);
 
   /**
    * Helper: Sets prefs as the testsuite requires
    * @note Will be reset in cleanTestSuite just before finishing the tests
    */
   function setPrefs() {
     gPrefService.setIntPref("browser.startup.page", 3);
     gPrefService.setBoolPref(
@@ -189,30 +185,30 @@ function test() {
   }
 
   /**
    * Helper: Sets up this testsuite
    */
   function setupTestsuite(testFn) {
     // Register our observers
     for (let o in observing)
-      observerService.addObserver(observer, o, false);
+      Services.obs.addObserver(observer, o, false);
 
     // Make the main test window not count as a browser window any longer
     oldWinType = document.documentElement.getAttribute("windowtype");
     document.documentElement.setAttribute("windowtype", "navigator:testrunner");
   }
 
   /**
    * Helper: Cleans up behind the testsuite
    */
   function cleanupTestsuite(callback) {
     // Finally remove observers again
     for (let o in observing)
-      observerService.removeObserver(observer, o, false);
+      Services.obs.removeObserver(observer, o, false);
 
     // Reset the prefs we touched
     [
       "browser.startup.page",
       "browser.privatebrowsing.keep_current_session"
     ].forEach(function (pref) {
       if (gPrefService.prefHasUserValue(pref))
         gPrefService.clearUserPref(pref);
--- a/browser/components/sessionstore/test/browser/browser_394759.js
+++ b/browser/components/sessionstore/test/browser/browser_394759.js
@@ -32,19 +32,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 function browserWindowsCount() {
   let count = 0;
-  let e = Cc["@mozilla.org/appshell/window-mediator;1"]
-            .getService(Ci.nsIWindowMediator)
-            .getEnumerator("navigator:browser");
+  let e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     if (!e.getNext().closed)
       ++count;
   }
   return count;
 }
 
 function test() {
--- a/browser/components/sessionstore/test/browser/browser_394759_privatebrowsing.js
+++ b/browser/components/sessionstore/test/browser/browser_394759_privatebrowsing.js
@@ -34,19 +34,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 function browserWindowsCount() {
   let count = 0;
-  let e = Cc["@mozilla.org/appshell/window-mediator;1"]
-            .getService(Ci.nsIWindowMediator)
-            .getEnumerator("navigator:browser");
+  let e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     if (!e.getNext().closed)
       ++count;
   }
   return count;
 }
 
 function test() {
@@ -69,20 +67,18 @@ function test() {
     }],
     _closedWindows: []
   });
   ss.setBrowserState(blankState);
 
   // Wait for the sessionstore.js file to be written before going on.
   // Note: we don't wait for the complete event, since if asyncCopy fails we
   // would timeout.
-  let os = Cc["@mozilla.org/observer-service;1"].
-           getService(Ci.nsIObserverService);
-  os.addObserver(function (aSubject, aTopic, aData) {
-    os.removeObserver(arguments.callee, aTopic);
+  Services.obs.addObserver(function (aSubject, aTopic, aData) {
+    Services.obs.removeObserver(arguments.callee, aTopic);
     info("sessionstore.js is being written");
     executeSoon(continue_test);
   }, "sessionstore-state-write", false);
 
   // Remove the sessionstore.js file before setting the interval to 0
   let profilePath = Cc["@mozilla.org/file/directory_service;1"].
                     getService(Ci.nsIProperties).
                     get("ProfD", Ci.nsIFile);
--- a/browser/components/sessionstore/test/browser/browser_423132.js
+++ b/browser/components/sessionstore/test/browser/browser_423132.js
@@ -31,19 +31,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 function browserWindowsCount() {
   let count = 0;
-  let e = Cc["@mozilla.org/appshell/window-mediator;1"]
-            .getService(Ci.nsIWindowMediator)
-            .getEnumerator("navigator:browser");
+  let e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     if (!e.getNext().closed)
       ++count;
   }
   return count;
 }
 
 function test() {
--- a/browser/components/sessionstore/test/browser/browser_448741.js
+++ b/browser/components/sessionstore/test/browser/browser_448741.js
@@ -34,17 +34,16 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 function test() {
   /** Test for Bug 448741 **/
 
   // test setup
   let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
-  let os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
   waitForExplicitFinish();
 
   let uniqueName = "bug 448741";
   let uniqueValue = "as good as unique: " + Date.now();
 
   // set a unique value on a new, blank tab
   var tab = gBrowser.addTab();
   tab.linkedBrowser.stop();
@@ -66,32 +65,32 @@ function test() {
           delete tabData.extData[uniqueName];
           valueWasCleaned = true;
         }
       });
     });
 
     ok(valueWasCleaned, "found and removed the specific tab value");
     aSubject.data = uneval(state);
-    os.removeObserver(cleaningObserver, aTopic, false);
+    Services.obs.removeObserver(cleaningObserver, aTopic, false);
   }
 
   // make sure that all later observers don't see that value any longer
   function checkingObserver(aSubject, aTopic, aData) {
     ok(valueWasCleaned && aSubject instanceof Ci.nsISupportsString,
        "ready to check the cleaned state?");
     ok(aSubject.data.indexOf(uniqueValue) == -1, "data no longer contains our value?");
 
     // clean up
     gBrowser.removeTab(tab);
-    os.removeObserver(checkingObserver, aTopic, false);
+    Services.obs.removeObserver(checkingObserver, aTopic, false);
     if (gPrefService.prefHasUserValue("browser.sessionstore.interval"))
       gPrefService.clearUserPref("browser.sessionstore.interval");
     finish();
   }
 
   // last added observers are invoked first
-  os.addObserver(checkingObserver, "sessionstore-state-write", false);
-  os.addObserver(cleaningObserver, "sessionstore-state-write", false);
+  Services.obs.addObserver(checkingObserver, "sessionstore-state-write", false);
+  Services.obs.addObserver(cleaningObserver, "sessionstore-state-write", false);
 
   // trigger an immediate save operation
   gPrefService.setIntPref("browser.sessionstore.interval", 0);
 }
--- a/browser/components/sessionstore/test/browser/browser_461634.js
+++ b/browser/components/sessionstore/test/browser/browser_461634.js
@@ -32,19 +32,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 function browserWindowsCount() {
   let count = 0;
-  let e = Cc["@mozilla.org/appshell/window-mediator;1"]
-            .getService(Ci.nsIWindowMediator)
-            .getEnumerator("navigator:browser");
+  let e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     if (!e.getNext().closed)
       ++count;
   }
   return count;
 }
 
 function test() {
--- a/browser/components/sessionstore/test/browser/browser_464199.js
+++ b/browser/components/sessionstore/test/browser/browser_464199.js
@@ -31,19 +31,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 function browserWindowsCount() {
   let count = 0;
-  let e = Cc["@mozilla.org/appshell/window-mediator;1"]
-            .getService(Ci.nsIWindowMediator)
-            .getEnumerator("navigator:browser");
+  let e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     if (!e.getNext().closed)
       ++count;
   }
   return count;
 }
 
 function test() {
--- a/browser/components/sessionstore/test/browser/browser_465223.js
+++ b/browser/components/sessionstore/test/browser/browser_465223.js
@@ -31,19 +31,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 function browserWindowsCount() {
   let count = 0;
-  let e = Cc["@mozilla.org/appshell/window-mediator;1"]
-            .getService(Ci.nsIWindowMediator)
-            .getEnumerator("navigator:browser");
+  let e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     if (!e.getNext().closed)
       ++count;
   }
   return count;
 }
 
 function test() {
--- a/browser/components/sessionstore/test/browser/browser_477657.js
+++ b/browser/components/sessionstore/test/browser/browser_477657.js
@@ -31,19 +31,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 function browserWindowsCount() {
   let count = 0;
-  let e = Cc["@mozilla.org/appshell/window-mediator;1"]
-            .getService(Ci.nsIWindowMediator)
-            .getEnumerator("navigator:browser");
+  let e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     if (!e.getNext().closed)
       ++count;
   }
   return count;
 }
 
 function test() {
--- a/browser/components/sessionstore/test/browser/browser_480148.js
+++ b/browser/components/sessionstore/test/browser/browser_480148.js
@@ -31,19 +31,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 function browserWindowsCount() {
   let count = 0;
-  let e = Cc["@mozilla.org/appshell/window-mediator;1"]
-            .getService(Ci.nsIWindowMediator)
-            .getEnumerator("navigator:browser");
+  let e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     if (!e.getNext().closed)
       ++count;
   }
   return count;
 }
 
 function test() {
--- a/browser/components/sessionstore/test/browser/browser_490040.js
+++ b/browser/components/sessionstore/test/browser/browser_490040.js
@@ -32,36 +32,30 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 function browserWindowsCount() {
   let count = 0;
-  let e = Cc["@mozilla.org/appshell/window-mediator;1"]
-            .getService(Ci.nsIWindowMediator)
-            .getEnumerator("navigator:browser");
+  let e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     if (!e.getNext().closed)
       ++count;
   }
   return count;
 }
 
 function test() {
   /** Test for Bug 490040 **/
   is(browserWindowsCount(), 1, "Only one browser window should be open initially");
 
   let ss = Cc["@mozilla.org/browser/sessionstore;1"].
            getService(Ci.nsISessionStore);
-  let os = Cc["@mozilla.org/observer-service;1"].
-           getService(Ci.nsIObserverService);
-  let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-           getService(Ci.nsIWindowWatcher);
 
   waitForExplicitFinish();
 
   function testWithState(aState) {
     // Ensure we can store the window if needed.
     let curClosedWindowCount = ss.getClosedWindowCount();
     gPrefService.setIntPref("browser.sessionstore.max_windows_undo",
                             curClosedWindowCount + 1);
@@ -93,34 +87,34 @@ function test() {
               }
               ss.setWindowState(theWin, JSON.stringify(aState.windowState),
                                 true);
             });
           }, false);
           break;
 
         case "domwindowclosed":
-          ww.unregisterNotification(windowObserver);
+          Services.ww.unregisterNotification(windowObserver);
           // Use executeSoon to ensure this happens after SS observer.
           executeSoon(function () {
             is(ss.getClosedWindowCount(),
                curClosedWindowCount + (aState.shouldBeAdded ? 1 : 0),
                "That window should " + (aState.shouldBeAdded ? "" : "not ") +
                "be restorable");
             executeSoon(runNextTest);
           });
           break;
       }
     }
-    ww.registerNotification(windowObserver);
-    ww.openWindow(null,
-                  location,
-                  "_blank",
-                  "chrome,all,dialog=no",
-                  null);
+    Services.ww.registerNotification(windowObserver);
+    Services.ww.openWindow(null,
+                           location,
+                           "_blank",
+                           "chrome,all,dialog=no",
+                           null);
   }
 
   // Only windows with open tabs are restorable. Windows where a lone tab is
   // detached may have _closedTabs, but is left with just an empty tab.
   let states = [
     {
       shouldBeAdded: true,
       windowState: {
--- a/browser/components/sessionstore/test/browser/browser_491168.js
+++ b/browser/components/sessionstore/test/browser/browser_491168.js
@@ -31,33 +31,30 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 function browserWindowsCount() {
   let count = 0;
-  let e = Cc["@mozilla.org/appshell/window-mediator;1"]
-            .getService(Ci.nsIWindowMediator)
-            .getEnumerator("navigator:browser");
+  let e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     if (!e.getNext().closed)
       ++count;
   }
   return count;
 }
 
 function test() {
   /** Test for Bug 491168 **/
   is(browserWindowsCount(), 1, "Only one browser window should be open initially");
 
   // test setup
   let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
-  let ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
 
   waitForExplicitFinish();
 
   const REFERRER1 = "http://example.org/?" + Date.now();
   const REFERRER2 = "http://example.org/?" + Math.random();
 
   let tab = gBrowser.addTab();
   gBrowser.selectedTab = tab;
@@ -86,11 +83,11 @@ function test() {
         gBrowser.removeTab(newTab);
 
         is(browserWindowsCount(), 1, "Only one browser window should be open eventually");
         finish();
       }, true);
     }, true);
   },true);
 
-  let referrerURI = ioService.newURI(REFERRER1, null, null);
+  let referrerURI = Services.io.newURI(REFERRER1, null, null);
   browser.loadURI("http://example.org", referrerURI, null);
 }
--- a/browser/components/sessionstore/test/browser/browser_491577.js
+++ b/browser/components/sessionstore/test/browser/browser_491577.js
@@ -32,19 +32,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 function browserWindowsCount() {
   let count = 0;
-  let e = Cc["@mozilla.org/appshell/window-mediator;1"]
-            .getService(Ci.nsIWindowMediator)
-            .getEnumerator("navigator:browser");
+  let e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     if (!e.getNext().closed)
       ++count;
   }
   return count;
 }
 
 function test() {
--- a/browser/components/sessionstore/test/browser/browser_493467.js
+++ b/browser/components/sessionstore/test/browser/browser_493467.js
@@ -31,19 +31,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 function browserWindowsCount() {
   let count = 0;
-  let e = Cc["@mozilla.org/appshell/window-mediator;1"]
-            .getService(Ci.nsIWindowMediator)
-            .getEnumerator("navigator:browser");
+  let e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     if (!e.getNext().closed)
       ++count;
   }
   return count;
 }
 
 function test() {
--- a/browser/components/sessionstore/test/browser/browser_495495.js
+++ b/browser/components/sessionstore/test/browser/browser_495495.js
@@ -31,19 +31,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 function browserWindowsCount() {
   let count = 0;
-  let e = Cc["@mozilla.org/appshell/window-mediator;1"]
-            .getService(Ci.nsIWindowMediator)
-            .getEnumerator("navigator:browser");
+  let e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     if (!e.getNext().closed)
       ++count;
   }
   return count;
 }
 
 function test() {
--- a/browser/components/sessionstore/test/browser/browser_514751.js
+++ b/browser/components/sessionstore/test/browser/browser_514751.js
@@ -31,19 +31,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 function browserWindowsCount() {
   let count = 0;
-  let e = Cc["@mozilla.org/appshell/window-mediator;1"]
-            .getService(Ci.nsIWindowMediator)
-            .getEnumerator("navigator:browser");
+  let e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     if (!e.getNext().closed)
       ++count;
   }
   return count;
 }
 
 function test() {
--- a/browser/components/sessionstore/test/browser/browser_522545.js
+++ b/browser/components/sessionstore/test/browser/browser_522545.js
@@ -32,19 +32,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 function browserWindowsCount() {
   let count = 0;
-  let e = Cc["@mozilla.org/appshell/window-mediator;1"]
-            .getService(Ci.nsIWindowMediator)
-            .getEnumerator("navigator:browser");
+  let e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     if (!e.getNext().closed)
       ++count;
   }
   return count;
 }
 
 function test() {
--- a/browser/components/sessionstore/test/browser/browser_524745.js
+++ b/browser/components/sessionstore/test/browser/browser_524745.js
@@ -32,34 +32,30 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 function browserWindowsCount() {
   let count = 0;
-  let e = Cc["@mozilla.org/appshell/window-mediator;1"]
-            .getService(Ci.nsIWindowMediator)
-            .getEnumerator("navigator:browser");
+  let e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     if (!e.getNext().closed)
       ++count;
   }
   return count;
 }
 
 function test() {
   /** Test for Bug 524745 **/
   is(browserWindowsCount(), 1, "Only one browser window should be open initially");
 
   let ss = Cc["@mozilla.org/browser/sessionstore;1"].
            getService(Ci.nsISessionStore);
-  let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-           getService(Ci.nsIWindowWatcher);
   let uniqKey = "bug524745";
   let uniqVal = Date.now();
 
   waitForExplicitFinish();
 
   let window_B = openDialog(location, "_blank", "chrome,all,dialog=no");
   window_B.addEventListener("load", function(aEvent) {
     window_B.removeEventListener("load", arguments.callee, false);
--- a/browser/components/sessionstore/test/browser/browser_526613.js
+++ b/browser/components/sessionstore/test/browser/browser_526613.js
@@ -36,25 +36,21 @@
  * ***** END LICENSE BLOCK ***** */
 
 function test() {
   /** Test for Bug 526613 **/
   
   // test setup
   let ss = Cc["@mozilla.org/browser/sessionstore;1"].
            getService(Ci.nsISessionStore);
-  let os = Cc["@mozilla.org/observer-service;1"].
-           getService(Ci.nsIObserverService);
-  let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
-           getService(Ci.nsIWindowMediator);
   waitForExplicitFinish();
 
   function browserWindowsCount(expected) {
     let count = 0;
-    let e = wm.getEnumerator("navigator:browser");
+    let e = Services.wm.getEnumerator("navigator:browser");
     while (e.hasMoreElements()) {
       if (!e.getNext().closed)
         ++count;
     }
     is(count, expected,
        "number of open browser windows according to nsIWindowMediator");
     let state = ss.getBrowserState();
     info(state);
@@ -82,30 +78,30 @@ function test() {
     is(aTopic, "sessionstore-browser-state-restored",
        "The sessionstore-browser-state-restored notification was observed");
 
     if (pass++ == 1) {
       browserWindowsCount(2);
 
       // let the first window be focused (see above)
       function pollMostRecentWindow() {
-        if (wm.getMostRecentWindow("navigator:browser") == window) {
+        if (Services.wm.getMostRecentWindow("navigator:browser") == window) {
           ss.setBrowserState(oldState);
         } else {
           info("waiting for the current window to become active");
           setTimeout(pollMostRecentWindow, 0);
           window.focus(); //XXX Why is this needed?
         }
       }
       pollMostRecentWindow();
     }
     else {
       browserWindowsCount(1);
       ok(!window.closed, "Restoring the old state should have left this window open");
-      os.removeObserver(observer, "sessionstore-browser-state-restored");
+      Services.obs.removeObserver(observer, "sessionstore-browser-state-restored");
       finish();
     }
   }
-  os.addObserver(observer, "sessionstore-browser-state-restored", false);
+  Services.obs.addObserver(observer, "sessionstore-browser-state-restored", false);
 
   // set browser to test state
   ss.setBrowserState(JSON.stringify(testState));
 }
--- a/browser/components/sessionstore/test/browser/browser_528776.js
+++ b/browser/components/sessionstore/test/browser/browser_528776.js
@@ -1,14 +1,13 @@
 var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
-var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
 
 function browserWindowsCount(expected) {
   var count = 0;
-  var e = wm.getEnumerator("navigator:browser");
+  var e = Services.wm.getEnumerator("navigator:browser");
   while (e.hasMoreElements()) {
     if (!e.getNext().closed)
       ++count;
   }
   is(count, expected,
      "number of open browser windows according to nsIWindowMediator");
   is(JSON.parse(ss.getBrowserState()).windows.length, expected,
      "number of open browser windows according to getBrowserState");
--- a/browser/fuel/test/browser_Application.js
+++ b/browser/fuel/test/browser_Application.js
@@ -1,22 +1,17 @@
-const Ci = Components.interfaces;
-const Cc = Components.classes;
-
 // This listens for the next opened window and checks it is of the right url.
 // opencallback is called when the new window is fully loaded
 // closecallback is called when the window is closed
 function WindowOpenListener(url, opencallback, closecallback) {
   this.url = url;
   this.opencallback = opencallback;
   this.closecallback = closecallback;
 
-  var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
-           getService(Ci.nsIWindowMediator);
-  wm.addListener(this);
+  Services.wm.addListener(this);
 }
 
 WindowOpenListener.prototype = {
   url: null,
   opencallback: null,
   closecallback: null,
   window: null,
   domwindow: null,
@@ -42,19 +37,17 @@ WindowOpenListener.prototype = {
                            .getInterface(Ci.nsIDOMWindowInternal);
     this.domwindow.addEventListener("load", this, false);
   },
 
   onCloseWindow: function(window) {
     if (this.window != window)
       return;
 
-    var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
-             getService(Ci.nsIWindowMediator);
-    wm.removeListener(this);
+    Services.wm.removeListener(this);
     this.opencallback = null;
     this.window = null;
     this.domwindow = null;
 
     // Let the window close complete
     executeSoon(this.closecallback);
     this.closecallback = null;
   }
--- a/browser/fuel/test/browser_ApplicationQuitting.js
+++ b/browser/fuel/test/browser_ApplicationQuitting.js
@@ -1,18 +1,17 @@
 function test() {
   function quitRequestObserver(aSubject, aTopic, aData) {
     ok(aTopic == "quit-application-requested" &&
        aSubject instanceof Components.interfaces.nsISupportsPRBool,
        "Received a quit request we're going to deny");
     aSubject.data = true;
   }
-  
+
   // ensure that we don't accidentally quit
-  let os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
-  os.addObserver(quitRequestObserver, "quit-application-requested", false);
-  
+  Services.obs.addObserver(quitRequestObserver, "quit-application-requested", false);
+
   ok(!Application.quit(),    "Tried to quit - and didn't succeed");
   ok(!Application.restart(), "Tried to restart - and didn't succeed");
-  
+
   // clean up
-  os.removeObserver(quitRequestObserver, "quit-application-requested", false);
+  Services.obs.removeObserver(quitRequestObserver, "quit-application-requested", false);
 }
--- a/browser/fuel/test/browser_Bookmarks.js
+++ b/browser/fuel/test/browser_Bookmarks.js
@@ -1,17 +1,13 @@
-const Ci = Components.interfaces;
-const Cc = Components.classes;
-
 var gLastFolderAction = "";
 var gLastBookmarkAction = "";
 
 function url(spec) {
-  var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
-  return ios.newURI(spec, null, null);
+  return Services.io.newURI(spec, null, null);
 }
 
 function test() {
   // Some very basic tests on the tags root
   var tags = Application.bookmarks.tags;
   ok(tags, "Check access to bookmark tags root");
   ok(!tags.parent, "Check tags parent (should be null)");
 
--- a/docshell/test/browser/browser_bug134911.js
+++ b/docshell/test/browser/browser_bug134911.js
@@ -1,11 +1,8 @@
-const Ci = Components.interfaces;
-const Cc = Components.classes;
-
 /* The test text decoded correctly as Shift_JIS */
 const rightText="\u30E6\u30CB\u30B3\u30FC\u30C9\u306F\u3001\u3059\u3079\u3066\u306E\u6587\u5B57\u306B\u56FA\u6709\u306E\u756A\u53F7\u3092\u4ED8\u4E0E\u3057\u307E\u3059";
 
 const enteredText1="The quick brown fox jumps over the lazy dog";
 const enteredText2="\u03BE\u03B5\u03C3\u03BA\u03B5\u03C0\u03AC\u03B6\u03C9\u0020\u03C4\u1F74\u03BD\u0020\u03C8\u03C5\u03C7\u03BF\u03C6\u03B8\u03CC\u03C1\u03B1\u0020\u03B2\u03B4\u03B5\u03BB\u03C5\u03B3\u03BC\u03AF\u03B1";
 
 var testPage;
 
@@ -37,11 +34,10 @@ function afterChangeCharset() {
     is(testPage.document.getElementById("testinput").value, enteredText2,
        "text preserved in <input>");
 
     testPage.close();
     finish();
 }
 
 function url(spec) {
-  var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
-  return ios.newURI(spec, null, null);
+  return Services.io.newURI(spec, null, null);
 }
--- a/docshell/test/browser/browser_bug349769.js
+++ b/docshell/test/browser/browser_bug349769.js
@@ -1,15 +1,14 @@
 function test() {
   waitForExplicitFinish(); 
 
   var newTab;
   var newBrowser;
-  const secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"].
-                   getService(Components.interfaces.nsIScriptSecurityManager);
+  const secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager);
   var iteration = 1;
   const uris = [undefined, "about:blank"];
   var uri;
 
   function testLoad(event) {
     newBrowser.removeEventListener("load", testLoad, true);
     is (event.target, newBrowser.contentDocument, "Unexpected target");
     var prin = newBrowser.contentDocument.nodePrincipal;
--- a/docshell/test/browser/browser_bug388121-1.js
+++ b/docshell/test/browser/browser_bug388121-1.js
@@ -1,15 +1,14 @@
 function test() {
   waitForExplicitFinish(); 
 
   var newTab;
   var newBrowser;
-  const secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"].
-                   getService(Components.interfaces.nsIScriptSecurityManager);
+  const secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager);
 
   function testLoad(event) {
     newBrowser.removeEventListener("load", testLoad, true);
     is (event.target, newBrowser.contentDocument, "Unexpected target");
     var prin = newBrowser.contentDocument.nodePrincipal;
     isnot(prin, null, "Loaded principal must not be null");
     isnot(prin, undefined, "Loaded principal must not be undefined");
     is(secMan.isSystemPrincipal(prin), false,
--- a/docshell/test/browser/browser_bug388121-2.js
+++ b/docshell/test/browser/browser_bug388121-2.js
@@ -1,14 +1,13 @@
 function test() {
   waitForExplicitFinish(); 
 
   var w;
-  const secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"].
-                   getService(Components.interfaces.nsIScriptSecurityManager);
+  const secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager);
   var iteration = 1;
   const uris = ["", "about:blank"];
   var uri;
   var origDoc;
 
   function testLoad() {
     if (w.document == origDoc) {
       // Go back to polling
--- a/docshell/test/browser/browser_bug92473.js
+++ b/docshell/test/browser/browser_bug92473.js
@@ -1,23 +1,19 @@
-const Ci = Components.interfaces;
-const Cc = Components.classes;
-
 /* The test text decoded correctly as Shift_JIS */
 const rightText="\u30E6\u30CB\u30B3\u30FC\u30C9\u306F\u3001\u3059\u3079\u3066\u306E\u6587\u5B57\u306B\u56FA\u6709\u306E\u756A\u53F7\u3092\u4ED8\u4E0E\u3057\u307E\u3059";
 
 /* The test text decoded incorrectly as Windows-1251. This is the "right" wrong
    text; anything else is unexpected. */
 const wrongText="\u0453\u2020\u0453\u006A\u0453\u0052\u0403\u005B\u0453\u0068\u201A\u041D\u0403\u0041\u201A\u00B7\u201A\u0427\u201A\u0414\u201A\u041C\u2022\u00B6\u040B\u0459\u201A\u0419\u040A\u0415\u2014\u004C\u201A\u041C\u201D\u0424\u040C\u2020\u201A\u0440\u2022\u0074\u2014\u005E\u201A\u00B5\u201A\u042C\u201A\u00B7";
 
 var testPage;
 
 function url(spec) {
-  var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
-  return ios.newURI(spec, null, null);
+  return Services.io.newURI(spec, null, null);
 }
 
 function testContent(text) {
     is(testPage.document.getElementById("testpar").innerHTML, text,
        "<p> contains expected text");
     is(testPage.document.getElementById("testtextarea").innerHTML, text,
        "<textarea> contains expected text");
     is(testPage.document.getElementById("testinput").value, text,
--- a/toolkit/components/downloads/test/browser/browser_bug414214.js
+++ b/toolkit/components/downloads/test/browser/browser_bug414214.js
@@ -41,48 +41,41 @@ function test()
   var dm = Cc["@mozilla.org/download-manager;1"].
            getService(Ci.nsIDownloadManager);
   var db = dm.DBConnection;
 
   // First, we clean up the DM
   db.executeSimpleSQL("DELETE FROM moz_downloads");
 
   // See if the DM is already open, and if it is, close it!
-  var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
-           getService(Ci.nsIWindowMediator);
-  var win = wm.getMostRecentWindow("Download:Manager");
+  var win = Services.wm.getMostRecentWindow("Download:Manager");
   if (win)
     win.close();
 
   // We need to set browser.download.manager.closeWhenDone to true to test this
-  Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch).
-  setBoolPref(PREF_BDM_CLOSEWHENDONE, true);
-
-  var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-           getService(Ci.nsIWindowWatcher);
+  Services.prefs.setBoolPref(PREF_BDM_CLOSEWHENDONE, true);
 
   // register a callback to add a load listener to know when the download
   // manager opens
-  ww.registerNotification(function (aSubject, aTopic, aData) {
-    ww.unregisterNotification(arguments.callee);
+  Services.ww.registerNotification(function (aSubject, aTopic, aData) {
+    Services.ww.unregisterNotification(arguments.callee);
 
     var win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
     win.addEventListener("DOMContentLoaded", finishUp, false);
   });
 
   // The window doesn't open once we call show, so we need to wait a little bit
   function finishUp() {
     var dmui = Cc["@mozilla.org/download-manager-ui;1"].
                getService(Ci.nsIDownloadManagerUI);
     ok(dmui.visible, "Download Manager window is open, as expected.");
 
     // Reset the pref to its default value
     try {
-      Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch).    
-      clearUserPref(PREF_BDM_CLOSEWHENDONE);
+      Services.prefs.clearUserPref(PREF_BDM_CLOSEWHENDONE);
     }
     catch (err) { }
 
     finish();
   }
   
   // OK, let's pull up the UI
   // Linux uses y, everything else is j
--- a/toolkit/components/downloads/test/browser/browser_nsIDownloadManagerUI.js
+++ b/toolkit/components/downloads/test/browser/browser_nsIDownloadManagerUI.js
@@ -100,29 +100,27 @@ function test()
   var dm = Cc["@mozilla.org/download-manager;1"].
            getService(Ci.nsIDownloadManager);
   var db = dm.DBConnection;
 
   // First, we populate the database with some fake data
   db.executeSimpleSQL("DELETE FROM moz_downloads");
 
   // See if the DM is already open, and if it is, close it!
-  var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
-           getService(Ci.nsIWindowMediator);
-  var win = wm.getMostRecentWindow("Download:Manager");
+  var win = Services.wm.getMostRecentWindow("Download:Manager");
   if (win)
     win.close();
 
   // OK, now that all the data is in, let's pull up the UI
   Cc["@mozilla.org/download-manager-ui;1"].
   getService(Ci.nsIDownloadManagerUI).show();
 
   // The window doesn't open once we call show, so we need to wait a little bit
   function finishUp() {
-    var win = wm.getMostRecentWindow("Download:Manager");
+    var win = Services.wm.getMostRecentWindow("Download:Manager");
 
     // Now we can run our tests
     for each (var t in testFuncs)
       t(win);
 
     finish();
   }
   
--- a/toolkit/components/passwordmgr/test/browser/browser_passwordmgr_sort.js
+++ b/toolkit/components/passwordmgr/test/browser/browser_passwordmgr_sort.js
@@ -84,20 +84,16 @@ function test() {
         "mozilla.com",
     ];
     let nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
                                                  Ci.nsILoginInfo, "init");
     for (let i = 0; i < 10; i++)
         pwmgr.addLogin(new nsLoginInfo(urls[i], urls[i], null, users[i], pwds[i],
                                        "u"+(i+1), "p"+(i+1)));
 
-    // Detect when the password manager window is opened
-    let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-             getService(Ci.nsIWindowWatcher);
-
     // Open the password manager dialog
     const PWMGR_DLG = "chrome://passwordmgr/content/passwordManager.xul";
     let pwmgrdlg = window.openDialog(PWMGR_DLG, "Toolkit:PasswordManager", "");
     SimpleTest.waitForFocus(doTest, pwmgrdlg);
 
     // the meat of the test
     function doTest() {
         let doc = pwmgrdlg.document;
@@ -110,33 +106,31 @@ function test() {
 
         let toggleCalls = 0;
         function toggleShowPasswords(func) {
             let toggleButton = doc.getElementById("togglePasswords");
             let showMode = (toggleCalls++ % 2) == 0;
 
             // only watch for a confirmation dialog every other time being called
             if (showMode) {
-                ww.registerNotification(function (aSubject, aTopic, aData) {
+                Services.ww.registerNotification(function (aSubject, aTopic, aData) {
                     if (aTopic == "domwindowclosed")
-                        ww.unregisterNotification(arguments.callee);
+                        Services.ww.unregisterNotification(arguments.callee);
                     else if (aTopic == "domwindowopened") {
                         let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
                         SimpleTest.waitForFocus(function() {
                             EventUtils.synthesizeKey("VK_RETURN", {}, win)
                         }, win);
                     }
                 });
             }
 
-            let obsSvc = Cc["@mozilla.org/observer-service;1"].
-                         getService(Ci.nsIObserverService);
-            obsSvc.addObserver(function (aSubject, aTopic, aData) {
+            Services.obs.addObserver(function (aSubject, aTopic, aData) {
                 if (aTopic == "passwordmgr-password-toggle-complete") {
-                    obsSvc.removeObserver(arguments.callee, aTopic, false);
+                    Services.obs.removeObserver(arguments.callee, aTopic, false);
                     func();
                 }
             }, "passwordmgr-password-toggle-complete", false);
 
             EventUtils.synthesizeMouse(toggleButton, 1, 1, {}, win);
         }
 
         function clickCol(col) {
@@ -229,19 +223,19 @@ function test() {
                 // Reset filter
                 setFilter("");
                 break;
             case 5:
                 expectedValues = pwds.slice().sort();
                 checkColumnEntries(2, expectedValues);
                 checkSortDirection(passwordCol, true);
                 // cleanup
-                ww.registerNotification(function (aSubject, aTopic, aData) {
+                Services.ww.registerNotification(function (aSubject, aTopic, aData) {
                     // unregister ourself
-                    ww.unregisterNotification(arguments.callee);
+                    Services.ww.unregisterNotification(arguments.callee);
 
                     pwmgr.removeAllLogins();
                     finish();
                 });
                 pwmgrdlg.close();
             }
         }
 
--- a/toolkit/components/passwordmgr/test/browser/browser_passwordmgrdlg.js
+++ b/toolkit/components/passwordmgr/test/browser/browser_passwordmgrdlg.js
@@ -69,20 +69,16 @@ function test() {
         new nsLoginInfo(urls[5], urls[5], null, "what?", "very secret", "u6", "p6"),
         new nsLoginInfo(urls[6], urls[6], null, "really?", "super secret", "u7", "p7"),
         new nsLoginInfo(urls[7], urls[7], null, "you sure?", "absolutely", "u8", "p8"),
         new nsLoginInfo(urls[8], urls[8], null, "my user name", "mozilla", "u9", "p9"),
         new nsLoginInfo(urls[9], urls[9], null, "my username", "mozilla.com", "u10", "p10"),
     ];
     logins.forEach(function (login) pwmgr.addLogin(login));
 
-    // Detect when the password manager window is opened
-    let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-             getService(Ci.nsIWindowWatcher);
-
     // Open the password manager dialog
     const PWMGR_DLG = "chrome://passwordmgr/content/passwordManager.xul";
     let pwmgrdlg = window.openDialog(PWMGR_DLG, "Toolkit:PasswordManager", "");
     SimpleTest.waitForFocus(doTest, pwmgrdlg);
 
     // the meat of the test
     function doTest() {
         let doc = pwmgrdlg.document;
@@ -120,33 +116,31 @@ function test() {
 
         let toggleCalls = 0;
         function toggleShowPasswords(func) {
             let toggleButton = doc.getElementById("togglePasswords");
             let showMode = (toggleCalls++ % 2) == 0;
 
             // only watch for a confirmation dialog every other time being called
             if (showMode) {
-                ww.registerNotification(function (aSubject, aTopic, aData) {
+                Services.ww.registerNotification(function (aSubject, aTopic, aData) {
                     if (aTopic == "domwindowclosed")
-                        ww.unregisterNotification(arguments.callee);
+                        Services.ww.unregisterNotification(arguments.callee);
                     else if (aTopic == "domwindowopened") {
                         let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
                         SimpleTest.waitForFocus(function() {
                             EventUtils.synthesizeKey("VK_RETURN", {}, win)
                         }, win);
                     }
                 });
             }
 
-            let obsSvc = Cc["@mozilla.org/observer-service;1"].
-                         getService(Ci.nsIObserverService);
-            obsSvc.addObserver(function (aSubject, aTopic, aData) {
+            Services.obs.addObserver(function (aSubject, aTopic, aData) {
                 if (aTopic == "passwordmgr-password-toggle-complete") {
-                    obsSvc.removeObserver(arguments.callee, aTopic, false);
+                    Services.obs.removeObserver(arguments.callee, aTopic, false);
                     func();
                 }
             }, "passwordmgr-password-toggle-complete", false);
 
             EventUtils.synthesizeMouse(toggleButton, 1, 1, {}, win);
         }
 
         function runTests(mode, endFunction) {
@@ -214,19 +208,19 @@ function test() {
         function step3() {
             toggleShowPasswords(function() {
                 runTests(3, lastStep);
             });
         }
 
         function lastStep() {
             // cleanup
-            ww.registerNotification(function (aSubject, aTopic, aData) {
+            Services.ww.registerNotification(function (aSubject, aTopic, aData) {
                 // unregister ourself
-                ww.unregisterNotification(arguments.callee);
+                Services.ww.unregisterNotification(arguments.callee);
 
                 pwmgr.removeAllLogins();
                 finish();
             });
             pwmgrdlg.close();
         }
 
         step1();
--- a/toolkit/crashreporter/test/browser/browser_aboutCrashesResubmit.js
+++ b/toolkit/crashreporter/test/browser/browser_aboutCrashesResubmit.js
@@ -2,19 +2,17 @@
 var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
                              .getService(Components.interfaces.mozIJSSubScriptLoader);
 scriptLoader.loadSubScript("chrome://mochikit/content/browser/toolkit/crashreporter/test/browser/aboutcrashes_utils.js", this);
 
 function cleanup_and_finish() {
   try {
     cleanup_fake_appdir();
   } catch(ex) {}
-  let prefs = Components.classes["@mozilla.org/preferences-service;1"]
-    .getService(Components.interfaces.nsIPrefService);
-  prefs.clearUserPref("breakpad.reportURL");
+  Services.prefs.clearUserPref("breakpad.reportURL");
   gBrowser.removeTab(gBrowser.selectedTab);
   finish();
 }
 
 /*
  * check_crash_list
  *
  * Check that the list of crashes displayed by about:crashes matches
@@ -130,20 +128,18 @@ function test() {
                                            'ProductName': 'Test App',
                                            // test that we don't truncate
                                            // at = (bug 512853)
                                            'Foo': 'ABC=XYZ'
                                           }));
   crashes.sort(function(a,b) b.date - a.date);
 
   // set this pref so we can link to our test server
-  let prefs = Components.classes["@mozilla.org/preferences-service;1"]
-    .getService(Components.interfaces.nsIPrefService);
-
-  prefs.setCharPref("breakpad.reportURL", "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs?id=");
+  Services.prefs.setCharPref("breakpad.reportURL",
+                             "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs?id=");
 
   let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank");
   let browser = gBrowser.getBrowserForTab(tab);
   browser.addEventListener("load", function test_load() {
                              browser.removeEventListener("load", test_load, true);
                              executeSoon(function () {
                                            check_crash_list(tab, crashes);
                                            check_submit_pending(tab, crashes);
--- a/toolkit/mozapps/extensions/test/browser/browser_bug510909.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug510909.js
@@ -1,18 +1,16 @@
 Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm");
 
 var win = null;
 
 function WindowListener(url) {
   this.url = url;
 
-  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
-                     .getService(Components.interfaces.nsIWindowMediator);
-  wm.addListener(this);
+  Services.wm.addListener(this);
 }
 
 WindowListener.prototype = {
   url: null,
 
   onWindowTitleChange: function(window, title) {
   },
 
@@ -33,19 +31,17 @@ WindowListener.prototype = {
   },
 
   windowReady: function(win) {
     is(win.document.location.href, this.url, "Should have seen the right window");
     win.document.documentElement.acceptDialog();
   },
 
   onCloseWindow: function(window) {
-    var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
-                       .getService(Components.interfaces.nsIWindowMediator);
-    wm.removeListener(this);
+    Services.wm.removeListener(this);
   },
 
   QueryInterface: function(iid) {
     if (iid.equals(Components.interfaces.nsIWindowMediatorListener) ||
         iid.equals(Components.interfaces.nsISupports))
       return this;
 
     throw Components.results.NS_ERROR_NO_INTERFACE;