Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
michael@0 | 1 | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
michael@0 | 2 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 4 | |
michael@0 | 5 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 6 | |
michael@0 | 7 | // From browser/components/preferences/in-content/test/head.js |
michael@0 | 8 | function open_preferences(aCallback) { |
michael@0 | 9 | gBrowser.selectedTab = gBrowser.addTab("about:preferences"); |
michael@0 | 10 | let newTabBrowser = gBrowser.getBrowserForTab(gBrowser.selectedTab); |
michael@0 | 11 | newTabBrowser.addEventListener("Initialized", function () { |
michael@0 | 12 | newTabBrowser.removeEventListener("Initialized", arguments.callee, true); |
michael@0 | 13 | aCallback(gBrowser.contentWindow); |
michael@0 | 14 | }, true); |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | function test() { |
michael@0 | 18 | waitForExplicitFinish(); |
michael@0 | 19 | let connectionTests = runConnectionTestsGen(); |
michael@0 | 20 | connectionTests.next(); |
michael@0 | 21 | const connectionURL = "chrome://browser/content/preferences/connection.xul"; |
michael@0 | 22 | let closeable = false; |
michael@0 | 23 | let finalTest = false; |
michael@0 | 24 | let prefWin; |
michael@0 | 25 | |
michael@0 | 26 | // The changed preferences need to be backed up and restored because this mochitest |
michael@0 | 27 | // changes them setting from the default |
michael@0 | 28 | let oldNetworkProxyType = Services.prefs.getIntPref("network.proxy.type"); |
michael@0 | 29 | registerCleanupFunction(function() { |
michael@0 | 30 | Services.prefs.setIntPref("network.proxy.type", oldNetworkProxyType); |
michael@0 | 31 | Services.prefs.clearUserPref("network.proxy.share_proxy_settings"); |
michael@0 | 32 | for (let proxyType of ["http", "ssl", "ftp", "socks"]) { |
michael@0 | 33 | Services.prefs.clearUserPref("network.proxy." + proxyType); |
michael@0 | 34 | Services.prefs.clearUserPref("network.proxy." + proxyType + "_port"); |
michael@0 | 35 | if (proxyType == "http") { |
michael@0 | 36 | continue; |
michael@0 | 37 | } |
michael@0 | 38 | Services.prefs.clearUserPref("network.proxy.backup." + proxyType); |
michael@0 | 39 | Services.prefs.clearUserPref("network.proxy.backup." + proxyType + "_port"); |
michael@0 | 40 | } |
michael@0 | 41 | try { |
michael@0 | 42 | Services.ww.unregisterNotification(observer); |
michael@0 | 43 | } catch(e) { |
michael@0 | 44 | // Do nothing, if the test was successful the above line should fail silently. |
michael@0 | 45 | } |
michael@0 | 46 | }); |
michael@0 | 47 | |
michael@0 | 48 | // this observer is registered after the pref tab loads |
michael@0 | 49 | let observer = { |
michael@0 | 50 | observe: function(aSubject, aTopic, aData) { |
michael@0 | 51 | if (aTopic == "domwindowopened") { |
michael@0 | 52 | // when the connection window loads, proceed forward in test |
michael@0 | 53 | let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow); |
michael@0 | 54 | win.addEventListener("load", function winLoadListener() { |
michael@0 | 55 | win.removeEventListener("load", winLoadListener); |
michael@0 | 56 | if (win.location.href == connectionURL) { |
michael@0 | 57 | // If this is a connection window, run the next test |
michael@0 | 58 | connectionTests.next(win); |
michael@0 | 59 | } |
michael@0 | 60 | }); |
michael@0 | 61 | } else if (aTopic == "domwindowclosed") { |
michael@0 | 62 | // Check if the window should have closed, and respawn another window for further testing |
michael@0 | 63 | let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow); |
michael@0 | 64 | if (win.location.href == connectionURL) { |
michael@0 | 65 | ok(closeable, "Connection dialog closed"); |
michael@0 | 66 | |
michael@0 | 67 | // Last close event, don't respawn, and clean up |
michael@0 | 68 | if (finalTest) { |
michael@0 | 69 | Services.ww.unregisterNotification(observer); |
michael@0 | 70 | gBrowser.removeCurrentTab(); |
michael@0 | 71 | finish(); |
michael@0 | 72 | return; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | // Open another connection pane for the next test |
michael@0 | 76 | gBrowser.contentWindow.gAdvancedPane.showConnections(); |
michael@0 | 77 | } |
michael@0 | 78 | } |
michael@0 | 79 | } |
michael@0 | 80 | }; |
michael@0 | 81 | |
michael@0 | 82 | // The actual tests to run, in a generator |
michael@0 | 83 | function* runConnectionTestsGen() { |
michael@0 | 84 | let doc, connectionWin, proxyTypePref, sharePref, httpPref, httpPortPref, ftpPref, ftpPortPref; |
michael@0 | 85 | |
michael@0 | 86 | // Convenient function to reset the variables for the new window |
michael@0 | 87 | function setDoc(win) { |
michael@0 | 88 | doc = win.document; |
michael@0 | 89 | connectionWin = win; |
michael@0 | 90 | proxyTypePref = doc.getElementById("network.proxy.type"); |
michael@0 | 91 | sharePref = doc.getElementById("network.proxy.share_proxy_settings"); |
michael@0 | 92 | httpPref = doc.getElementById("network.proxy.http"); |
michael@0 | 93 | httpPortPref = doc.getElementById("network.proxy.http_port"); |
michael@0 | 94 | ftpPref = doc.getElementById("network.proxy.ftp"); |
michael@0 | 95 | ftpPortPref = doc.getElementById("network.proxy.ftp_port"); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | // This batch of tests should not close the dialog |
michael@0 | 99 | setDoc(yield null); |
michael@0 | 100 | |
michael@0 | 101 | // Testing HTTP port 0 with share on |
michael@0 | 102 | proxyTypePref.value = 1; |
michael@0 | 103 | sharePref.value = true; |
michael@0 | 104 | httpPref.value = "localhost"; |
michael@0 | 105 | httpPortPref.value = 0; |
michael@0 | 106 | doc.documentElement.acceptDialog(); |
michael@0 | 107 | |
michael@0 | 108 | // Testing HTTP port 0 + FTP port 80 with share off |
michael@0 | 109 | sharePref.value = false; |
michael@0 | 110 | ftpPref.value = "localhost"; |
michael@0 | 111 | ftpPortPref.value = 80; |
michael@0 | 112 | doc.documentElement.acceptDialog(); |
michael@0 | 113 | |
michael@0 | 114 | // Testing HTTP port 80 + FTP port 0 with share off |
michael@0 | 115 | httpPortPref.value = 80; |
michael@0 | 116 | ftpPortPref.value = 0; |
michael@0 | 117 | doc.documentElement.acceptDialog(); |
michael@0 | 118 | |
michael@0 | 119 | // From now on, the dialog should close since we are giving it legitimate inputs. |
michael@0 | 120 | // The test will timeout if the onbeforeaccept kicks in erroneously. |
michael@0 | 121 | closeable = true; |
michael@0 | 122 | |
michael@0 | 123 | // Both ports 80, share on |
michael@0 | 124 | httpPortPref.value = 80; |
michael@0 | 125 | ftpPortPref.value = 80; |
michael@0 | 126 | doc.documentElement.acceptDialog(); |
michael@0 | 127 | |
michael@0 | 128 | // HTTP 80, FTP 0, with share on |
michael@0 | 129 | setDoc(yield null); |
michael@0 | 130 | proxyTypePref.value = 1; |
michael@0 | 131 | sharePref.value = true; |
michael@0 | 132 | ftpPref.value = "localhost"; |
michael@0 | 133 | httpPref.value = "localhost"; |
michael@0 | 134 | httpPortPref.value = 80; |
michael@0 | 135 | ftpPortPref.value = 0; |
michael@0 | 136 | doc.documentElement.acceptDialog(); |
michael@0 | 137 | |
michael@0 | 138 | // HTTP host empty, port 0 with share on |
michael@0 | 139 | setDoc(yield null); |
michael@0 | 140 | proxyTypePref.value = 1; |
michael@0 | 141 | sharePref.value = true; |
michael@0 | 142 | httpPref.value = ""; |
michael@0 | 143 | httpPortPref.value = 0; |
michael@0 | 144 | doc.documentElement.acceptDialog(); |
michael@0 | 145 | |
michael@0 | 146 | // HTTP 0, but in no proxy mode |
michael@0 | 147 | setDoc(yield null); |
michael@0 | 148 | proxyTypePref.value = 0; |
michael@0 | 149 | sharePref.value = true; |
michael@0 | 150 | httpPref.value = "localhost"; |
michael@0 | 151 | httpPortPref.value = 0; |
michael@0 | 152 | |
michael@0 | 153 | // This is the final test, don't spawn another connection window |
michael@0 | 154 | finalTest = true; |
michael@0 | 155 | doc.documentElement.acceptDialog(); |
michael@0 | 156 | yield null; |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | /* |
michael@0 | 160 | The connection dialog alone won't save onaccept since it uses type="child", |
michael@0 | 161 | so it has to be opened as a sub dialog of the main pref tab. |
michael@0 | 162 | Open the main tab here. |
michael@0 | 163 | */ |
michael@0 | 164 | open_preferences(function tabOpened(aContentWindow) { |
michael@0 | 165 | Services.ww.registerNotification(observer); |
michael@0 | 166 | gBrowser.contentWindow.gAdvancedPane.showConnections(); |
michael@0 | 167 | }); |
michael@0 | 168 | } |