michael@0: /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: // network.proxy.type needs to be backed up and restored because mochitest michael@0: // changes this setting from the default michael@0: let oldNetworkProxyType = Services.prefs.getIntPref("network.proxy.type"); michael@0: registerCleanupFunction(function() { michael@0: Services.prefs.setIntPref("network.proxy.type", oldNetworkProxyType); michael@0: Services.prefs.clearUserPref("browser.preferences.instantApply"); michael@0: Services.prefs.clearUserPref("network.proxy.share_proxy_settings"); michael@0: for (let proxyType of ["http", "ssl", "ftp", "socks"]) { michael@0: Services.prefs.clearUserPref("network.proxy." + proxyType); michael@0: Services.prefs.clearUserPref("network.proxy." + proxyType + "_port"); michael@0: if (proxyType == "http") { michael@0: continue; michael@0: } michael@0: Services.prefs.clearUserPref("network.proxy.backup." + proxyType); michael@0: Services.prefs.clearUserPref("network.proxy.backup." + proxyType + "_port"); michael@0: } michael@0: }); michael@0: michael@0: let connectionURL = "chrome://browser/content/preferences/connection.xul"; michael@0: let windowWatcher = Services.ww; michael@0: michael@0: // instantApply must be true, otherwise connection dialog won't save michael@0: // when opened from in-content prefs michael@0: Services.prefs.setBoolPref("browser.preferences.instantApply", true); michael@0: michael@0: // Set a shared proxy and a SOCKS backup michael@0: Services.prefs.setIntPref("network.proxy.type", 1); michael@0: Services.prefs.setBoolPref("network.proxy.share_proxy_settings", true); michael@0: Services.prefs.setCharPref("network.proxy.http", "example.com"); michael@0: Services.prefs.setIntPref("network.proxy.http_port", 1200); michael@0: Services.prefs.setCharPref("network.proxy.socks", "example.com"); michael@0: Services.prefs.setIntPref("network.proxy.socks_port", 1200); michael@0: Services.prefs.setCharPref("network.proxy.backup.socks", "127.0.0.1"); michael@0: Services.prefs.setIntPref("network.proxy.backup.socks_port", 9050); michael@0: michael@0: // this observer is registered after the pref tab loads michael@0: let observer = { michael@0: observe: function(aSubject, aTopic, aData) { michael@0: if (aTopic == "domwindowopened") { michael@0: // when connection window loads, run tests and acceptDialog() michael@0: let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow); michael@0: win.addEventListener("load", function winLoadListener() { michael@0: win.removeEventListener("load", winLoadListener, false); michael@0: if (win.location.href == connectionURL) { michael@0: ok(true, "connection window opened"); michael@0: win.document.documentElement.acceptDialog(); michael@0: } michael@0: }, false); michael@0: } else if (aTopic == "domwindowclosed") { michael@0: // finish up when connection window closes michael@0: let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow); michael@0: if (win.location.href == connectionURL) { michael@0: windowWatcher.unregisterNotification(observer); michael@0: ok(true, "connection window closed"); michael@0: michael@0: // The SOCKS backup should not be replaced by the shared value michael@0: is(Services.prefs.getCharPref("network.proxy.backup.socks"), "127.0.0.1", "Shared proxy backup shouldn't be replaced"); michael@0: is(Services.prefs.getIntPref("network.proxy.backup.socks_port"), 9050, "Shared proxy port backup shouldn't be replaced"); michael@0: michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: } michael@0: } michael@0: } michael@0: }; michael@0: michael@0: /* michael@0: The connection dialog alone won't save onaccept since it uses type="child", michael@0: so it has to be opened as a sub dialog of the main pref tab. michael@0: Open the main tab here. michael@0: */ michael@0: open_preferences(function tabOpened(aContentWindow) { michael@0: is(gBrowser.currentURI.spec, "about:preferences", "about:preferences loaded"); michael@0: windowWatcher.registerNotification(observer); michael@0: gBrowser.contentWindow.gAdvancedPane.showConnections(); michael@0: }); michael@0: } michael@0: