Wed, 31 Dec 2014 06:55:46 +0100
Added tag TORBROWSER_REPLICA for changeset 6474c204b198
michael@0 | 1 | /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 7 | |
michael@0 | 8 | function test() { |
michael@0 | 9 | waitForExplicitFinish(); |
michael@0 | 10 | |
michael@0 | 11 | // network.proxy.type needs to be backed up and restored because mochitest |
michael@0 | 12 | // changes this setting from the default |
michael@0 | 13 | let oldNetworkProxyType = Services.prefs.getIntPref("network.proxy.type"); |
michael@0 | 14 | registerCleanupFunction(function() { |
michael@0 | 15 | Services.prefs.setIntPref("network.proxy.type", oldNetworkProxyType); |
michael@0 | 16 | Services.prefs.clearUserPref("browser.preferences.instantApply"); |
michael@0 | 17 | Services.prefs.clearUserPref("network.proxy.share_proxy_settings"); |
michael@0 | 18 | for (let proxyType of ["http", "ssl", "ftp", "socks"]) { |
michael@0 | 19 | Services.prefs.clearUserPref("network.proxy." + proxyType); |
michael@0 | 20 | Services.prefs.clearUserPref("network.proxy." + proxyType + "_port"); |
michael@0 | 21 | if (proxyType == "http") { |
michael@0 | 22 | continue; |
michael@0 | 23 | } |
michael@0 | 24 | Services.prefs.clearUserPref("network.proxy.backup." + proxyType); |
michael@0 | 25 | Services.prefs.clearUserPref("network.proxy.backup." + proxyType + "_port"); |
michael@0 | 26 | } |
michael@0 | 27 | }); |
michael@0 | 28 | |
michael@0 | 29 | let connectionURL = "chrome://browser/content/preferences/connection.xul"; |
michael@0 | 30 | let windowWatcher = Services.ww; |
michael@0 | 31 | |
michael@0 | 32 | // instantApply must be true, otherwise connection dialog won't save |
michael@0 | 33 | // when opened from in-content prefs |
michael@0 | 34 | Services.prefs.setBoolPref("browser.preferences.instantApply", true); |
michael@0 | 35 | |
michael@0 | 36 | // Set a shared proxy and a SOCKS backup |
michael@0 | 37 | Services.prefs.setIntPref("network.proxy.type", 1); |
michael@0 | 38 | Services.prefs.setBoolPref("network.proxy.share_proxy_settings", true); |
michael@0 | 39 | Services.prefs.setCharPref("network.proxy.http", "example.com"); |
michael@0 | 40 | Services.prefs.setIntPref("network.proxy.http_port", 1200); |
michael@0 | 41 | Services.prefs.setCharPref("network.proxy.socks", "example.com"); |
michael@0 | 42 | Services.prefs.setIntPref("network.proxy.socks_port", 1200); |
michael@0 | 43 | Services.prefs.setCharPref("network.proxy.backup.socks", "127.0.0.1"); |
michael@0 | 44 | Services.prefs.setIntPref("network.proxy.backup.socks_port", 9050); |
michael@0 | 45 | |
michael@0 | 46 | // this observer is registered after the pref tab loads |
michael@0 | 47 | let observer = { |
michael@0 | 48 | observe: function(aSubject, aTopic, aData) { |
michael@0 | 49 | if (aTopic == "domwindowopened") { |
michael@0 | 50 | // when connection window loads, run tests and acceptDialog() |
michael@0 | 51 | let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow); |
michael@0 | 52 | win.addEventListener("load", function winLoadListener() { |
michael@0 | 53 | win.removeEventListener("load", winLoadListener, false); |
michael@0 | 54 | if (win.location.href == connectionURL) { |
michael@0 | 55 | ok(true, "connection window opened"); |
michael@0 | 56 | win.document.documentElement.acceptDialog(); |
michael@0 | 57 | } |
michael@0 | 58 | }, false); |
michael@0 | 59 | } else if (aTopic == "domwindowclosed") { |
michael@0 | 60 | // finish up when connection window closes |
michael@0 | 61 | let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow); |
michael@0 | 62 | if (win.location.href == connectionURL) { |
michael@0 | 63 | windowWatcher.unregisterNotification(observer); |
michael@0 | 64 | ok(true, "connection window closed"); |
michael@0 | 65 | |
michael@0 | 66 | // The SOCKS backup should not be replaced by the shared value |
michael@0 | 67 | is(Services.prefs.getCharPref("network.proxy.backup.socks"), "127.0.0.1", "Shared proxy backup shouldn't be replaced"); |
michael@0 | 68 | is(Services.prefs.getIntPref("network.proxy.backup.socks_port"), 9050, "Shared proxy port backup shouldn't be replaced"); |
michael@0 | 69 | |
michael@0 | 70 | gBrowser.removeCurrentTab(); |
michael@0 | 71 | finish(); |
michael@0 | 72 | } |
michael@0 | 73 | } |
michael@0 | 74 | } |
michael@0 | 75 | }; |
michael@0 | 76 | |
michael@0 | 77 | /* |
michael@0 | 78 | The connection dialog alone won't save onaccept since it uses type="child", |
michael@0 | 79 | so it has to be opened as a sub dialog of the main pref tab. |
michael@0 | 80 | Open the main tab here. |
michael@0 | 81 | */ |
michael@0 | 82 | open_preferences(function tabOpened(aContentWindow) { |
michael@0 | 83 | is(gBrowser.currentURI.spec, "about:preferences", "about:preferences loaded"); |
michael@0 | 84 | windowWatcher.registerNotification(observer); |
michael@0 | 85 | gBrowser.contentWindow.gAdvancedPane.showConnections(); |
michael@0 | 86 | }); |
michael@0 | 87 | } |
michael@0 | 88 |