browser/components/preferences/tests/browser_connection_bug388287.js

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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 function test() {
michael@0 8 waitForExplicitFinish();
michael@0 9 let connectionTests = runConnectionTestsGen();
michael@0 10 connectionTests.next();
michael@0 11 const connectionURL = "chrome://browser/content/preferences/connection.xul";
michael@0 12 const preferencesURL = "chrome://browser/content/preferences/preferences.xul";
michael@0 13 let closeable = false;
michael@0 14 let final = false;
michael@0 15 let prefWin;
michael@0 16
michael@0 17 // The changed preferences need to be backed up and restored because this mochitest
michael@0 18 // changes them setting from the default
michael@0 19 let oldNetworkProxyType = Services.prefs.getIntPref("network.proxy.type");
michael@0 20 registerCleanupFunction(function() {
michael@0 21 Services.prefs.setIntPref("network.proxy.type", oldNetworkProxyType);
michael@0 22 Services.prefs.clearUserPref("network.proxy.share_proxy_settings");
michael@0 23 for (let proxyType of ["http", "ssl", "ftp", "socks"]) {
michael@0 24 Services.prefs.clearUserPref("network.proxy." + proxyType);
michael@0 25 Services.prefs.clearUserPref("network.proxy." + proxyType + "_port");
michael@0 26 if (proxyType == "http") {
michael@0 27 continue;
michael@0 28 }
michael@0 29 Services.prefs.clearUserPref("network.proxy.backup." + proxyType);
michael@0 30 Services.prefs.clearUserPref("network.proxy.backup." + proxyType + "_port");
michael@0 31 }
michael@0 32 try {
michael@0 33 Services.ww.unregisterNotification(observer);
michael@0 34 } catch(e) {
michael@0 35 // Do nothing, if the test was successful the above line should fail silently.
michael@0 36 }
michael@0 37 });
michael@0 38
michael@0 39 // this observer is registered after the pref tab loads
michael@0 40 let observer = {
michael@0 41 observe: function(aSubject, aTopic, aData) {
michael@0 42 if (aTopic == "domwindowopened") {
michael@0 43 // when the connection window loads, proceed forward in test
michael@0 44 let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow);
michael@0 45 win.addEventListener("load", function winLoadListener() {
michael@0 46 win.removeEventListener("load", winLoadListener);
michael@0 47 if (win.location.href == connectionURL) {
michael@0 48 // If this is a connection window, run the next test
michael@0 49 connectionTests.next(win);
michael@0 50 } else if (win.location.href == preferencesURL) {
michael@0 51 // If this is the preferences window, initiate the tests by showing the connection pane
michael@0 52 prefWin = win;
michael@0 53 prefWin.gAdvancedPane.showConnections();
michael@0 54
michael@0 55 // Since the above method immediately triggers the observer chain,
michael@0 56 // the cleanup below won't happen until all the tests finish successfully.
michael@0 57 prefWin.close();
michael@0 58 Services.prefs.setIntPref("network.proxy.type",0);
michael@0 59 finish();
michael@0 60 }
michael@0 61 });
michael@0 62 } else if (aTopic == "domwindowclosed") {
michael@0 63 // Check if the window should have closed, and respawn another window for further testing
michael@0 64 let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow);
michael@0 65 if (win.location.href == connectionURL) {
michael@0 66 ok(closeable, "Connection dialog closed");
michael@0 67
michael@0 68 // Last close event, don't respawn
michael@0 69 if(final){
michael@0 70 Services.ww.unregisterNotification(observer);
michael@0 71 return;
michael@0 72 }
michael@0 73
michael@0 74 // Open another connection pane for the next test
michael@0 75 prefWin.gAdvancedPane.showConnections();
michael@0 76 }
michael@0 77 }
michael@0 78 }
michael@0 79 }
michael@0 80
michael@0 81 // The actual tests to run, in a generator
michael@0 82 function* runConnectionTestsGen() {
michael@0 83 let doc, connectionWin, proxyTypePref, sharePref, httpPref, httpPortPref, ftpPref, ftpPortPref;
michael@0 84
michael@0 85 // Convenient function to reset the variables for the new window
michael@0 86 function setDoc(win){
michael@0 87 doc = win.document;
michael@0 88 connectionWin = win;
michael@0 89 proxyTypePref = doc.getElementById("network.proxy.type");
michael@0 90 sharePref = doc.getElementById("network.proxy.share_proxy_settings");
michael@0 91 httpPref = doc.getElementById("network.proxy.http");
michael@0 92 httpPortPref = doc.getElementById("network.proxy.http_port");
michael@0 93 ftpPref = doc.getElementById("network.proxy.ftp");
michael@0 94 ftpPortPref = doc.getElementById("network.proxy.ftp_port");
michael@0 95 }
michael@0 96
michael@0 97 // This batch of tests should not close the dialog
michael@0 98 setDoc(yield null);
michael@0 99
michael@0 100 // Testing HTTP port 0 with share on
michael@0 101 proxyTypePref.value = 1;
michael@0 102 sharePref.value = true;
michael@0 103 httpPref.value = "localhost";
michael@0 104 httpPortPref.value = 0;
michael@0 105 doc.documentElement.acceptDialog();
michael@0 106
michael@0 107 // Testing HTTP port 0 + FTP port 80 with share off
michael@0 108 sharePref.value = false;
michael@0 109 ftpPref.value = "localhost";
michael@0 110 ftpPortPref.value = 80;
michael@0 111 doc.documentElement.acceptDialog();
michael@0 112
michael@0 113 // Testing HTTP port 80 + FTP port 0 with share off
michael@0 114 httpPortPref.value = 80;
michael@0 115 ftpPortPref.value = 0;
michael@0 116 doc.documentElement.acceptDialog();
michael@0 117
michael@0 118 // From now on, the dialog should close since we are giving it legitimate inputs.
michael@0 119 // The test will timeout if the onbeforeaccept kicks in erroneously.
michael@0 120 closeable = true;
michael@0 121
michael@0 122 // Both ports 80, share on
michael@0 123 httpPortPref.value = 80;
michael@0 124 ftpPortPref.value = 80;
michael@0 125 doc.documentElement.acceptDialog();
michael@0 126
michael@0 127 // HTTP 80, FTP 0, with share on
michael@0 128 setDoc(yield null);
michael@0 129 proxyTypePref.value = 1;
michael@0 130 sharePref.value = true;
michael@0 131 ftpPref.value = "localhost";
michael@0 132 httpPref.value = "localhost";
michael@0 133 httpPortPref.value = 80;
michael@0 134 ftpPortPref.value = 0;
michael@0 135 doc.documentElement.acceptDialog();
michael@0 136
michael@0 137 // HTTP host empty, port 0 with share on
michael@0 138 setDoc(yield null);
michael@0 139 proxyTypePref.value = 1;
michael@0 140 sharePref.value = true;
michael@0 141 httpPref.value = "";
michael@0 142 httpPortPref.value = 0;
michael@0 143 doc.documentElement.acceptDialog();
michael@0 144
michael@0 145 // HTTP 0, but in no proxy mode
michael@0 146 setDoc(yield null);
michael@0 147 proxyTypePref.value = 0;
michael@0 148 sharePref.value = true;
michael@0 149 httpPref.value = "localhost";
michael@0 150 httpPortPref.value = 0;
michael@0 151
michael@0 152 final = true; // This is the final test, don't spawn another connection window
michael@0 153 doc.documentElement.acceptDialog();
michael@0 154 yield null;
michael@0 155 }
michael@0 156
michael@0 157 Services.ww.registerNotification(observer);
michael@0 158 openDialog(preferencesURL, "Preferences",
michael@0 159 "chrome,titlebar,toolbar,centerscreen,dialog=no", "paneAdvanced");
michael@0 160 }

mercurial