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