Bug 767047 - Don't overwrite existing proxy backup preferences; r=MattN
authorMahdi Dibaiee <mdibaiee@aol.com>
Wed, 26 Feb 2014 11:06:00 -0500
changeset 171798 a1e0b41611215da99f3eb11c50fc9c127f65d890
parent 171797 e8a7c100b5fe174827b055e73327942db1c046ac
child 171799 435378ccdcbf72defbeaad95d491722d2bedf010
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersMattN
bugs767047
milestone30.0a1
Bug 767047 - Don't overwrite existing proxy backup preferences; r=MattN
browser/components/preferences/connection.js
browser/components/preferences/in-content/tests/browser.ini
browser/components/preferences/in-content/tests/browser_proxy_backup.js
--- a/browser/components/preferences/connection.js
+++ b/browser/components/preferences/connection.js
@@ -20,18 +20,18 @@ var gConnectionsDialog = {
     var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
     if (shareProxiesPref.value) {
       var proxyPrefs = ["ssl", "ftp", "socks"];
       for (var i = 0; i < proxyPrefs.length; ++i) {
         var proxyServerURLPref = document.getElementById("network.proxy." + proxyPrefs[i]);
         var proxyPortPref = document.getElementById("network.proxy." + proxyPrefs[i] + "_port");
         var backupServerURLPref = document.getElementById("network.proxy.backup." + proxyPrefs[i]);
         var backupPortPref = document.getElementById("network.proxy.backup." + proxyPrefs[i] + "_port");
-        backupServerURLPref.value = proxyServerURLPref.value;
-        backupPortPref.value = proxyPortPref.value;
+        backupServerURLPref.value = backupServerURLPref.value || proxyServerURLPref.value;
+        backupPortPref.value = backupPortPref.value || proxyPortPref.value;
         proxyServerURLPref.value = httpProxyURLPref.value;
         proxyPortPref.value = httpProxyPortPref.value;
       }
     }
     
     this.sanitizeNoProxiesPref();
     
     return true;
--- a/browser/components/preferences/in-content/tests/browser.ini
+++ b/browser/components/preferences/in-content/tests/browser.ini
@@ -4,12 +4,13 @@ support-files =
   privacypane_tests_perwindow.js
 
 [browser_advanced_update.js]
 [browser_bug410900.js]
 [browser_bug731866.js]
 [browser_connection.js]
 [browser_healthreport.js]
 skip-if = !healthreport || (os == 'linux' && debug)
+[browser_proxy_backup.js]
 [browser_privacypane_1.js]
 [browser_privacypane_3.js]
 [browser_privacypane_5.js]
 [browser_privacypane_8.js]
copy from browser/components/preferences/in-content/tests/browser_connection.js
copy to browser/components/preferences/in-content/tests/browser_proxy_backup.js
--- a/browser/components/preferences/in-content/tests/browser_connection.js
+++ b/browser/components/preferences/in-content/tests/browser_proxy_backup.js
@@ -8,51 +8,70 @@ Components.utils.import("resource://gre/
 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");
+    Services.prefs.clearUserPref("network.proxy.share_proxy_settings");
+    for (let proxyType of ["http", "ssl", "ftp", "socks"]) {
+      Services.prefs.clearUserPref("network.proxy." + proxyType);
+      Services.prefs.clearUserPref("network.proxy." + proxyType + "_port");
+      if (proxyType == "http") {
+        continue;
+      }
+      Services.prefs.clearUserPref("network.proxy.backup." + proxyType);
+      Services.prefs.clearUserPref("network.proxy.backup." + proxyType + "_port");
+    }
   });
 
   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);
 
+  // Set a shared proxy and a SOCKS backup
+  Services.prefs.setIntPref("network.proxy.type", 1);
+  Services.prefs.setBoolPref("network.proxy.share_proxy_settings", true);
+  Services.prefs.setCharPref("network.proxy.http", "example.com");
+  Services.prefs.setIntPref("network.proxy.http_port", 1200);
+  Services.prefs.setCharPref("network.proxy.socks", "example.com");
+  Services.prefs.setIntPref("network.proxy.socks_port", 1200);
+  Services.prefs.setCharPref("network.proxy.backup.socks", "127.0.0.1");
+  Services.prefs.setIntPref("network.proxy.backup.socks_port", 9050);
+
   // 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 == 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 == 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");
+
+          // The SOCKS backup should not be replaced by the shared value
+          is(Services.prefs.getCharPref("network.proxy.backup.socks"), "127.0.0.1", "Shared proxy backup shouldn't be replaced");
+          is(Services.prefs.getIntPref("network.proxy.backup.socks_port"), 9050, "Shared proxy port backup shouldn't be replaced");
+
           gBrowser.removeCurrentTab();
           finish();
         }
       }
     }
   };
 
   /*
@@ -62,60 +81,8 @@ function test() {
   */
   open_preferences(function tabOpened(aContentWindow) {
     is(gBrowser.currentURI.spec, "about:preferences", "about:preferences loaded");
     windowWatcher.registerNotification(observer);
     gBrowser.contentWindow.gAdvancedPane.showConnections();
   });
 }
 
-// run a bunch of tests on the window containing connection.xul
-function runConnectionTests(win) {
-  let doc = win.document;
-  let networkProxyNone = doc.getElementById("networkProxyNone");
-  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);
-  }
-
-  // change this pref so proxy exceptions are actually configurable
-  networkProxyTypePref.value = 1;
-  is(networkProxyNone.disabled, false, "networkProxyNone textbox is enabled");
-
-  testSanitize(".a.com", ".a.com",
-               "sanitize doesn't mess up single filter");
-  testSanitize(".a.com, .b.com, .c.com", ".a.com, .b.com, .c.com",
-               "sanitize doesn't mess up multiple comma/space sep filters");
-  testSanitize(".a.com\n.b.com", ".a.com,.b.com",
-               "sanitize turns line break into comma");
-  testSanitize(".a.com,\n.b.com", ".a.com,.b.com",
-               "sanitize doesn't add duplicate comma after comma");
-  testSanitize(".a.com\n,.b.com", ".a.com,.b.com",
-               "sanitize doesn't add duplicate comma before comma");
-  testSanitize(".a.com,\n,.b.com", ".a.com,,.b.com",
-               "sanitize doesn't add duplicate comma surrounded by commas");
-  testSanitize(".a.com, \n.b.com", ".a.com, .b.com",
-               "sanitize doesn't add comma after comma/space");
-  testSanitize(".a.com\n .b.com", ".a.com, .b.com",
-               "sanitize adds comma before space");
-  testSanitize(".a.com\n\n\n;;\n;\n.b.com", ".a.com,.b.com",
-               "sanitize only adds one comma per substring of bad chars");
-  testSanitize(".a.com,,.b.com", ".a.com,,.b.com",
-               "duplicate commas from user are untouched");
-  testSanitize(".a.com\n.b.com\n.c.com,\n.d.com,\n.e.com",
-               ".a.com,.b.com,.c.com,.d.com,.e.com",
-               "sanitize replaces things globally");
-
-  // will check that this was sanitized properly after window closes
-  networkProxyNonePref.value = ".a.com;.b.com\n.c.com";
-}