1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/preferences/in-content/tests/browser_proxy_backup.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,88 @@ 1.4 +/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +Components.utils.import("resource://gre/modules/Services.jsm"); 1.10 + 1.11 +function test() { 1.12 + waitForExplicitFinish(); 1.13 + 1.14 + // network.proxy.type needs to be backed up and restored because mochitest 1.15 + // changes this setting from the default 1.16 + let oldNetworkProxyType = Services.prefs.getIntPref("network.proxy.type"); 1.17 + registerCleanupFunction(function() { 1.18 + Services.prefs.setIntPref("network.proxy.type", oldNetworkProxyType); 1.19 + Services.prefs.clearUserPref("browser.preferences.instantApply"); 1.20 + Services.prefs.clearUserPref("network.proxy.share_proxy_settings"); 1.21 + for (let proxyType of ["http", "ssl", "ftp", "socks"]) { 1.22 + Services.prefs.clearUserPref("network.proxy." + proxyType); 1.23 + Services.prefs.clearUserPref("network.proxy." + proxyType + "_port"); 1.24 + if (proxyType == "http") { 1.25 + continue; 1.26 + } 1.27 + Services.prefs.clearUserPref("network.proxy.backup." + proxyType); 1.28 + Services.prefs.clearUserPref("network.proxy.backup." + proxyType + "_port"); 1.29 + } 1.30 + }); 1.31 + 1.32 + let connectionURL = "chrome://browser/content/preferences/connection.xul"; 1.33 + let windowWatcher = Services.ww; 1.34 + 1.35 + // instantApply must be true, otherwise connection dialog won't save 1.36 + // when opened from in-content prefs 1.37 + Services.prefs.setBoolPref("browser.preferences.instantApply", true); 1.38 + 1.39 + // Set a shared proxy and a SOCKS backup 1.40 + Services.prefs.setIntPref("network.proxy.type", 1); 1.41 + Services.prefs.setBoolPref("network.proxy.share_proxy_settings", true); 1.42 + Services.prefs.setCharPref("network.proxy.http", "example.com"); 1.43 + Services.prefs.setIntPref("network.proxy.http_port", 1200); 1.44 + Services.prefs.setCharPref("network.proxy.socks", "example.com"); 1.45 + Services.prefs.setIntPref("network.proxy.socks_port", 1200); 1.46 + Services.prefs.setCharPref("network.proxy.backup.socks", "127.0.0.1"); 1.47 + Services.prefs.setIntPref("network.proxy.backup.socks_port", 9050); 1.48 + 1.49 + // this observer is registered after the pref tab loads 1.50 + let observer = { 1.51 + observe: function(aSubject, aTopic, aData) { 1.52 + if (aTopic == "domwindowopened") { 1.53 + // when connection window loads, run tests and acceptDialog() 1.54 + let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow); 1.55 + win.addEventListener("load", function winLoadListener() { 1.56 + win.removeEventListener("load", winLoadListener, false); 1.57 + if (win.location.href == connectionURL) { 1.58 + ok(true, "connection window opened"); 1.59 + win.document.documentElement.acceptDialog(); 1.60 + } 1.61 + }, false); 1.62 + } else if (aTopic == "domwindowclosed") { 1.63 + // finish up when connection window closes 1.64 + let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow); 1.65 + if (win.location.href == connectionURL) { 1.66 + windowWatcher.unregisterNotification(observer); 1.67 + ok(true, "connection window closed"); 1.68 + 1.69 + // The SOCKS backup should not be replaced by the shared value 1.70 + is(Services.prefs.getCharPref("network.proxy.backup.socks"), "127.0.0.1", "Shared proxy backup shouldn't be replaced"); 1.71 + is(Services.prefs.getIntPref("network.proxy.backup.socks_port"), 9050, "Shared proxy port backup shouldn't be replaced"); 1.72 + 1.73 + gBrowser.removeCurrentTab(); 1.74 + finish(); 1.75 + } 1.76 + } 1.77 + } 1.78 + }; 1.79 + 1.80 + /* 1.81 + The connection dialog alone won't save onaccept since it uses type="child", 1.82 + so it has to be opened as a sub dialog of the main pref tab. 1.83 + Open the main tab here. 1.84 + */ 1.85 + open_preferences(function tabOpened(aContentWindow) { 1.86 + is(gBrowser.currentURI.spec, "about:preferences", "about:preferences loaded"); 1.87 + windowWatcher.registerNotification(observer); 1.88 + gBrowser.contentWindow.gAdvancedPane.showConnections(); 1.89 + }); 1.90 +} 1.91 +