No bug - Cleanup browser_connection.js so it's a better example for related tests. r=me
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Sat, 01 Mar 2014 16:19:57 -0500
changeset 171797 e8a7c100b5fe174827b055e73327942db1c046ac
parent 171794 6de7f6039a6841c6437d7256d1a37f62016657fe
child 171798 a1e0b41611215da99f3eb11c50fc9c127f65d890
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersme
milestone30.0a1
No bug - Cleanup browser_connection.js so it's a better example for related tests. r=me
browser/components/preferences/in-content/tests/browser_connection.js
--- a/browser/components/preferences/in-content/tests/browser_connection.js
+++ b/browser/components/preferences/in-content/tests/browser_connection.js
@@ -2,66 +2,63 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 function test() {
   waitForExplicitFinish();
-  
+
   // network.proxy.type needs to be backed up and restored because mochitest
   // changes this setting from the default
   let oldNetworkProxyType = Services.prefs.getIntPref("network.proxy.type");
   registerCleanupFunction(function() {
     Services.prefs.setIntPref("network.proxy.type", oldNetworkProxyType);
     Services.prefs.clearUserPref("network.proxy.no_proxies_on");
     Services.prefs.clearUserPref("browser.preferences.instantApply");
   });
-  
-  let connectionURI = "chrome://browser/content/preferences/connection.xul";
-  let windowWatcher = Cc["@mozilla.org/embedcomp/window-watcher;1"]
-                          .getService(Components.interfaces.nsIWindowWatcher);
+
+  let connectionURL = "chrome://browser/content/preferences/connection.xul";
+  let windowWatcher = Services.ww;
 
   // instantApply must be true, otherwise connection dialog won't save
   // when opened from in-content prefs
   Services.prefs.setBoolPref("browser.preferences.instantApply", true);
 
   // this observer is registered after the pref tab loads
   let observer = {
     observe: function(aSubject, aTopic, aData) {
-      
       if (aTopic == "domwindowopened") {
         // when connection window loads, run tests and acceptDialog()
         let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow);
         win.addEventListener("load", function winLoadListener() {
           win.removeEventListener("load", winLoadListener, false);
-          if (win.location.href == connectionURI) {
+          if (win.location.href == connectionURL) {
             ok(true, "connection window opened");
             runConnectionTests(win);
             win.document.documentElement.acceptDialog();
           }
         }, false);
       } else if (aTopic == "domwindowclosed") {
         // finish up when connection window closes
         let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow);
-        if (win.location.href == connectionURI) {
+        if (win.location.href == connectionURL) {
           windowWatcher.unregisterNotification(observer);
           ok(true, "connection window closed");
           // runConnectionTests will have changed this pref - make sure it was
           // sanitized correctly when the dialog was accepted
           is(Services.prefs.getCharPref("network.proxy.no_proxies_on"),
              ".a.com,.b.com,.c.com", "no_proxies_on pref has correct value");
           gBrowser.removeCurrentTab();
           finish();
         }
       }
-
     }
-  }
+  };
 
   /*
   The connection dialog alone won't save onaccept since it uses type="child",
   so it has to be opened as a sub dialog of the main pref tab.
   Open the main tab here.
   */
   open_preferences(function tabOpened(aContentWindow) {
     is(gBrowser.currentURI.spec, "about:preferences", "about:preferences loaded");
@@ -77,17 +74,17 @@ function runConnectionTests(win) {
   let networkProxyNonePref = doc.getElementById("network.proxy.no_proxies_on");
   let networkProxyTypePref = doc.getElementById("network.proxy.type");
 
   // make sure the networkProxyNone textbox is formatted properly
   is(networkProxyNone.getAttribute("multiline"), "true",
      "networkProxyNone textbox is multiline");
   is(networkProxyNone.getAttribute("rows"), "2",
      "networkProxyNone textbox has two rows");
-  
+
   // check if sanitizing the given input for the no_proxies_on pref results in
   // expected string
   function testSanitize(input, expected, errorMessage) {
     networkProxyNonePref.value = input;
     win.gConnectionsDialog.sanitizeNoProxiesPref();
     is(networkProxyNonePref.value, expected, errorMessage);
   }