browser_proxy_backup.js (3252B)
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/. */ 5 6 function test() { 7 waitForExplicitFinish(); 8 9 // network.proxy.type needs to be backed up and restored because mochitest 10 // changes this setting from the default 11 let oldNetworkProxyType = Services.prefs.getIntPref("network.proxy.type"); 12 registerCleanupFunction(function () { 13 Services.prefs.setIntPref("network.proxy.type", oldNetworkProxyType); 14 Services.prefs.clearUserPref("network.proxy.share_proxy_settings"); 15 for (let proxyType of ["http", "ssl", "socks"]) { 16 Services.prefs.clearUserPref("network.proxy." + proxyType); 17 Services.prefs.clearUserPref("network.proxy." + proxyType + "_port"); 18 if (proxyType == "http") { 19 continue; 20 } 21 Services.prefs.clearUserPref("network.proxy.backup." + proxyType); 22 Services.prefs.clearUserPref( 23 "network.proxy.backup." + proxyType + "_port" 24 ); 25 } 26 // On accepting the dialog, we also write TRR values, so we need to clear 27 // them. They are tested separately in browser_privacy_dnsoverhttps.js. 28 Services.prefs.clearUserPref("network.trr.mode"); 29 Services.prefs.clearUserPref("network.trr.uri"); 30 }); 31 32 let connectionURL = 33 "chrome://browser/content/preferences/dialogs/connection.xhtml"; 34 35 // Set a shared proxy and an SSL backup 36 Services.prefs.setIntPref("network.proxy.type", 1); 37 Services.prefs.setBoolPref("network.proxy.share_proxy_settings", true); 38 Services.prefs.setCharPref("network.proxy.http", "example.com"); 39 Services.prefs.setIntPref("network.proxy.http_port", 1200); 40 Services.prefs.setCharPref("network.proxy.ssl", "example.com"); 41 Services.prefs.setIntPref("network.proxy.ssl_port", 1200); 42 Services.prefs.setCharPref("network.proxy.backup.ssl", "127.0.0.1"); 43 Services.prefs.setIntPref("network.proxy.backup.ssl_port", 9050); 44 45 /* 46 The connection dialog alone won't save onaccept since it uses type="child", 47 so it has to be opened as a sub dialog of the main pref tab. 48 Open the main tab here. 49 */ 50 open_preferences(async function tabOpened() { 51 is( 52 gBrowser.currentURI.spec, 53 "about:preferences", 54 "about:preferences loaded" 55 ); 56 let dialog = await openAndLoadSubDialog(connectionURL); 57 let dialogElement = dialog.document.getElementById("ConnectionsDialog"); 58 let dialogClosingPromise = BrowserTestUtils.waitForEvent( 59 dialogElement, 60 "dialogclosing" 61 ); 62 63 ok(dialog, "connection window opened"); 64 dialogElement.acceptDialog(); 65 66 let dialogClosingEvent = await dialogClosingPromise; 67 ok(dialogClosingEvent, "connection window closed"); 68 69 // The SSL backup should not be replaced by the shared value 70 is( 71 Services.prefs.getCharPref("network.proxy.backup.ssl"), 72 "127.0.0.1", 73 "Shared proxy backup shouldn't be replaced" 74 ); 75 is( 76 Services.prefs.getIntPref("network.proxy.backup.ssl_port"), 77 9050, 78 "Shared proxy port backup shouldn't be replaced" 79 ); 80 81 gBrowser.removeCurrentTab(); 82 finish(); 83 }); 84 }