browser_connection_bug388287.js (4207B)
1 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 2 /* Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/publicdomain/zero/1.0/ */ 4 5 function test() { 6 waitForExplicitFinish(); 7 const connectionURL = 8 "chrome://browser/content/preferences/dialogs/connection.xhtml"; 9 let closeable = false; 10 let finalTest = false; 11 12 // The changed preferences need to be backed up and restored because this mochitest 13 // changes them setting from the default 14 let oldNetworkProxyType = Services.prefs.getIntPref("network.proxy.type"); 15 registerCleanupFunction(function () { 16 Services.prefs.setIntPref("network.proxy.type", oldNetworkProxyType); 17 Services.prefs.clearUserPref("network.proxy.share_proxy_settings"); 18 for (let proxyType of ["http", "ssl", "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( 26 "network.proxy.backup." + proxyType + "_port" 27 ); 28 } 29 // On accepting the dialog, we also write TRR values, so we need to clear 30 // them. They are tested separately in browser_privacy_dnsoverhttps.js. 31 Services.prefs.clearUserPref("network.trr.mode"); 32 Services.prefs.clearUserPref("network.trr.uri"); 33 }); 34 35 /* 36 The connection dialog alone won't save onaccept since it uses type="child", 37 so it has to be opened as a sub dialog of the main pref tab. 38 Open the main tab here. 39 */ 40 open_preferences(async function tabOpened() { 41 let dialog, dialogClosingPromise, dialogElement; 42 let proxyTypePref, sharePref, httpPref, httpPortPref; 43 44 // Convenient function to reset the variables for the new window 45 async function setDoc() { 46 if (closeable) { 47 let dialogClosingEvent = await dialogClosingPromise; 48 ok(dialogClosingEvent, "Connection dialog closed"); 49 } 50 51 if (finalTest) { 52 gBrowser.removeCurrentTab(); 53 finish(); 54 return; 55 } 56 57 dialog = await openAndLoadSubDialog(connectionURL); 58 dialogElement = dialog.document.getElementById("ConnectionsDialog"); 59 dialogClosingPromise = BrowserTestUtils.waitForEvent( 60 dialogElement, 61 "dialogclosing" 62 ); 63 64 proxyTypePref = dialog.Preferences.get("network.proxy.type"); 65 sharePref = dialog.Preferences.get("network.proxy.share_proxy_settings"); 66 httpPref = dialog.Preferences.get("network.proxy.http"); 67 httpPortPref = dialog.Preferences.get("network.proxy.http_port"); 68 } 69 70 // This batch of tests should not close the dialog 71 await setDoc(); 72 73 // Testing HTTP port 0 with share on 74 proxyTypePref.value = 1; 75 sharePref.value = true; 76 httpPref.value = "localhost"; 77 httpPortPref.value = 0; 78 dialogElement.acceptDialog(); 79 80 // Testing HTTP port 0 + FTP port 80 with share off 81 sharePref.value = false; 82 dialogElement.acceptDialog(); 83 84 // Testing HTTP port 80 + FTP port 0 with share off 85 httpPortPref.value = 80; 86 dialogElement.acceptDialog(); 87 88 // From now on, the dialog should close since we are giving it legitimate inputs. 89 // The test will timeout if the onbeforeaccept kicks in erroneously. 90 closeable = true; 91 92 // Both ports 80, share on 93 httpPortPref.value = 80; 94 dialogElement.acceptDialog(); 95 96 // HTTP 80, FTP 0, with share on 97 await setDoc(); 98 proxyTypePref.value = 1; 99 sharePref.value = true; 100 httpPref.value = "localhost"; 101 httpPortPref.value = 80; 102 dialogElement.acceptDialog(); 103 104 // HTTP host empty, port 0 with share on 105 await setDoc(); 106 proxyTypePref.value = 1; 107 sharePref.value = true; 108 httpPref.value = ""; 109 httpPortPref.value = 0; 110 dialogElement.acceptDialog(); 111 112 // HTTP 0, but in no proxy mode 113 await setDoc(); 114 proxyTypePref.value = 0; 115 sharePref.value = true; 116 httpPref.value = "localhost"; 117 httpPortPref.value = 0; 118 119 // This is the final test, don't spawn another connection window 120 finalTest = true; 121 dialogElement.acceptDialog(); 122 await setDoc(); 123 }); 124 }