michael@0: /* vim: set ts=8 sts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: let connectionTests = runConnectionTestsGen(); michael@0: connectionTests.next(); michael@0: const connectionURL = "chrome://browser/content/preferences/connection.xul"; michael@0: const preferencesURL = "chrome://browser/content/preferences/preferences.xul"; michael@0: let closeable = false; michael@0: let final = false; michael@0: let prefWin; michael@0: michael@0: // The changed preferences need to be backed up and restored because this mochitest michael@0: // changes them setting from the default michael@0: let oldNetworkProxyType = Services.prefs.getIntPref("network.proxy.type"); michael@0: registerCleanupFunction(function() { michael@0: Services.prefs.setIntPref("network.proxy.type", oldNetworkProxyType); michael@0: Services.prefs.clearUserPref("network.proxy.share_proxy_settings"); michael@0: for (let proxyType of ["http", "ssl", "ftp", "socks"]) { michael@0: Services.prefs.clearUserPref("network.proxy." + proxyType); michael@0: Services.prefs.clearUserPref("network.proxy." + proxyType + "_port"); michael@0: if (proxyType == "http") { michael@0: continue; michael@0: } michael@0: Services.prefs.clearUserPref("network.proxy.backup." + proxyType); michael@0: Services.prefs.clearUserPref("network.proxy.backup." + proxyType + "_port"); michael@0: } michael@0: try { michael@0: Services.ww.unregisterNotification(observer); michael@0: } catch(e) { michael@0: // Do nothing, if the test was successful the above line should fail silently. michael@0: } michael@0: }); michael@0: michael@0: // this observer is registered after the pref tab loads michael@0: let observer = { michael@0: observe: function(aSubject, aTopic, aData) { michael@0: if (aTopic == "domwindowopened") { michael@0: // when the connection window loads, proceed forward in test michael@0: let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow); michael@0: win.addEventListener("load", function winLoadListener() { michael@0: win.removeEventListener("load", winLoadListener); michael@0: if (win.location.href == connectionURL) { michael@0: // If this is a connection window, run the next test michael@0: connectionTests.next(win); michael@0: } else if (win.location.href == preferencesURL) { michael@0: // If this is the preferences window, initiate the tests by showing the connection pane michael@0: prefWin = win; michael@0: prefWin.gAdvancedPane.showConnections(); michael@0: michael@0: // Since the above method immediately triggers the observer chain, michael@0: // the cleanup below won't happen until all the tests finish successfully. michael@0: prefWin.close(); michael@0: Services.prefs.setIntPref("network.proxy.type",0); michael@0: finish(); michael@0: } michael@0: }); michael@0: } else if (aTopic == "domwindowclosed") { michael@0: // Check if the window should have closed, and respawn another window for further testing michael@0: let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow); michael@0: if (win.location.href == connectionURL) { michael@0: ok(closeable, "Connection dialog closed"); michael@0: michael@0: // Last close event, don't respawn michael@0: if(final){ michael@0: Services.ww.unregisterNotification(observer); michael@0: return; michael@0: } michael@0: michael@0: // Open another connection pane for the next test michael@0: prefWin.gAdvancedPane.showConnections(); michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: // The actual tests to run, in a generator michael@0: function* runConnectionTestsGen() { michael@0: let doc, connectionWin, proxyTypePref, sharePref, httpPref, httpPortPref, ftpPref, ftpPortPref; michael@0: michael@0: // Convenient function to reset the variables for the new window michael@0: function setDoc(win){ michael@0: doc = win.document; michael@0: connectionWin = win; michael@0: proxyTypePref = doc.getElementById("network.proxy.type"); michael@0: sharePref = doc.getElementById("network.proxy.share_proxy_settings"); michael@0: httpPref = doc.getElementById("network.proxy.http"); michael@0: httpPortPref = doc.getElementById("network.proxy.http_port"); michael@0: ftpPref = doc.getElementById("network.proxy.ftp"); michael@0: ftpPortPref = doc.getElementById("network.proxy.ftp_port"); michael@0: } michael@0: michael@0: // This batch of tests should not close the dialog michael@0: setDoc(yield null); michael@0: michael@0: // Testing HTTP port 0 with share on michael@0: proxyTypePref.value = 1; michael@0: sharePref.value = true; michael@0: httpPref.value = "localhost"; michael@0: httpPortPref.value = 0; michael@0: doc.documentElement.acceptDialog(); michael@0: michael@0: // Testing HTTP port 0 + FTP port 80 with share off michael@0: sharePref.value = false; michael@0: ftpPref.value = "localhost"; michael@0: ftpPortPref.value = 80; michael@0: doc.documentElement.acceptDialog(); michael@0: michael@0: // Testing HTTP port 80 + FTP port 0 with share off michael@0: httpPortPref.value = 80; michael@0: ftpPortPref.value = 0; michael@0: doc.documentElement.acceptDialog(); michael@0: michael@0: // From now on, the dialog should close since we are giving it legitimate inputs. michael@0: // The test will timeout if the onbeforeaccept kicks in erroneously. michael@0: closeable = true; michael@0: michael@0: // Both ports 80, share on michael@0: httpPortPref.value = 80; michael@0: ftpPortPref.value = 80; michael@0: doc.documentElement.acceptDialog(); michael@0: michael@0: // HTTP 80, FTP 0, with share on michael@0: setDoc(yield null); michael@0: proxyTypePref.value = 1; michael@0: sharePref.value = true; michael@0: ftpPref.value = "localhost"; michael@0: httpPref.value = "localhost"; michael@0: httpPortPref.value = 80; michael@0: ftpPortPref.value = 0; michael@0: doc.documentElement.acceptDialog(); michael@0: michael@0: // HTTP host empty, port 0 with share on michael@0: setDoc(yield null); michael@0: proxyTypePref.value = 1; michael@0: sharePref.value = true; michael@0: httpPref.value = ""; michael@0: httpPortPref.value = 0; michael@0: doc.documentElement.acceptDialog(); michael@0: michael@0: // HTTP 0, but in no proxy mode michael@0: setDoc(yield null); michael@0: proxyTypePref.value = 0; michael@0: sharePref.value = true; michael@0: httpPref.value = "localhost"; michael@0: httpPortPref.value = 0; michael@0: michael@0: final = true; // This is the final test, don't spawn another connection window michael@0: doc.documentElement.acceptDialog(); michael@0: yield null; michael@0: } michael@0: michael@0: Services.ww.registerNotification(observer); michael@0: openDialog(preferencesURL, "Preferences", michael@0: "chrome,titlebar,toolbar,centerscreen,dialog=no", "paneAdvanced"); michael@0: }