browser_connection_valid_hostname.js (2012B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 add_task(async function test_valid_hostname() { 7 await openPreferencesViaOpenPreferencesAPI("general", { leaveOpen: true }); 8 const connectionURL = 9 "chrome://browser/content/preferences/dialogs/connection.xhtml"; 10 let dialog = await openAndLoadSubDialog(connectionURL); 11 let dialogElement = dialog.document.getElementById("ConnectionsDialog"); 12 13 let oldNetworkProxyType = Services.prefs.getIntPref("network.proxy.type"); 14 registerCleanupFunction(function () { 15 Services.prefs.setIntPref("network.proxy.type", oldNetworkProxyType); 16 Services.prefs.clearUserPref("network.proxy.share_proxy_settings"); 17 for (let proxyType of ["http", "ssl", "socks"]) { 18 Services.prefs.clearUserPref("network.proxy." + proxyType); 19 Services.prefs.clearUserPref("network.proxy." + proxyType + "_port"); 20 if (proxyType == "http") { 21 continue; 22 } 23 Services.prefs.clearUserPref("network.proxy.backup." + proxyType); 24 Services.prefs.clearUserPref( 25 "network.proxy.backup." + proxyType + "_port" 26 ); 27 } 28 }); 29 30 let proxyType = dialog.Preferences.get("network.proxy.type"); 31 let httpPref = dialog.Preferences.get("network.proxy.http"); 32 let httpPortPref = dialog.Preferences.get("network.proxy.http_port"); 33 proxyType.value = 1; 34 httpPortPref.value = 1234; 35 36 httpPref.value = "bad://hostname"; 37 let beforeAcceptCalled = BrowserTestUtils.waitForEvent( 38 dialogElement, 39 "beforeaccept" 40 ); 41 dialogElement.acceptDialog(); 42 let event = await beforeAcceptCalled; 43 Assert.ok(event.defaultPrevented, "The dialog was not accepted"); 44 45 httpPref.value = "goodhostname"; 46 beforeAcceptCalled = BrowserTestUtils.waitForEvent( 47 dialogElement, 48 "beforeaccept" 49 ); 50 dialogElement.acceptDialog(); 51 event = await beforeAcceptCalled; 52 Assert.ok(!event.defaultPrevented, "The dialog was accepted"); 53 54 gBrowser.removeCurrentTab(); 55 });