Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 7 | |
michael@0 | 8 | function test() { |
michael@0 | 9 | waitForExplicitFinish(); |
michael@0 | 10 | |
michael@0 | 11 | // network.proxy.type needs to be backed up and restored because mochitest |
michael@0 | 12 | // changes this setting from the default |
michael@0 | 13 | let oldNetworkProxyType = Services.prefs.getIntPref("network.proxy.type"); |
michael@0 | 14 | registerCleanupFunction(function() { |
michael@0 | 15 | Services.prefs.setIntPref("network.proxy.type", oldNetworkProxyType); |
michael@0 | 16 | Services.prefs.clearUserPref("network.proxy.no_proxies_on"); |
michael@0 | 17 | Services.prefs.clearUserPref("browser.preferences.instantApply"); |
michael@0 | 18 | }); |
michael@0 | 19 | |
michael@0 | 20 | let connectionURL = "chrome://browser/content/preferences/connection.xul"; |
michael@0 | 21 | let windowWatcher = Services.ww; |
michael@0 | 22 | |
michael@0 | 23 | // instantApply must be true, otherwise connection dialog won't save |
michael@0 | 24 | // when opened from in-content prefs |
michael@0 | 25 | Services.prefs.setBoolPref("browser.preferences.instantApply", true); |
michael@0 | 26 | |
michael@0 | 27 | // this observer is registered after the pref tab loads |
michael@0 | 28 | let observer = { |
michael@0 | 29 | observe: function(aSubject, aTopic, aData) { |
michael@0 | 30 | if (aTopic == "domwindowopened") { |
michael@0 | 31 | // when connection window loads, run tests and acceptDialog() |
michael@0 | 32 | let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow); |
michael@0 | 33 | win.addEventListener("load", function winLoadListener() { |
michael@0 | 34 | win.removeEventListener("load", winLoadListener, false); |
michael@0 | 35 | if (win.location.href == connectionURL) { |
michael@0 | 36 | ok(true, "connection window opened"); |
michael@0 | 37 | runConnectionTests(win); |
michael@0 | 38 | win.document.documentElement.acceptDialog(); |
michael@0 | 39 | } |
michael@0 | 40 | }, false); |
michael@0 | 41 | } else if (aTopic == "domwindowclosed") { |
michael@0 | 42 | // finish up when connection window closes |
michael@0 | 43 | let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow); |
michael@0 | 44 | if (win.location.href == connectionURL) { |
michael@0 | 45 | windowWatcher.unregisterNotification(observer); |
michael@0 | 46 | ok(true, "connection window closed"); |
michael@0 | 47 | // runConnectionTests will have changed this pref - make sure it was |
michael@0 | 48 | // sanitized correctly when the dialog was accepted |
michael@0 | 49 | is(Services.prefs.getCharPref("network.proxy.no_proxies_on"), |
michael@0 | 50 | ".a.com,.b.com,.c.com", "no_proxies_on pref has correct value"); |
michael@0 | 51 | gBrowser.removeCurrentTab(); |
michael@0 | 52 | finish(); |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | } |
michael@0 | 56 | }; |
michael@0 | 57 | |
michael@0 | 58 | /* |
michael@0 | 59 | The connection dialog alone won't save onaccept since it uses type="child", |
michael@0 | 60 | so it has to be opened as a sub dialog of the main pref tab. |
michael@0 | 61 | Open the main tab here. |
michael@0 | 62 | */ |
michael@0 | 63 | open_preferences(function tabOpened(aContentWindow) { |
michael@0 | 64 | is(gBrowser.currentURI.spec, "about:preferences", "about:preferences loaded"); |
michael@0 | 65 | windowWatcher.registerNotification(observer); |
michael@0 | 66 | gBrowser.contentWindow.gAdvancedPane.showConnections(); |
michael@0 | 67 | }); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | // run a bunch of tests on the window containing connection.xul |
michael@0 | 71 | function runConnectionTests(win) { |
michael@0 | 72 | let doc = win.document; |
michael@0 | 73 | let networkProxyNone = doc.getElementById("networkProxyNone"); |
michael@0 | 74 | let networkProxyNonePref = doc.getElementById("network.proxy.no_proxies_on"); |
michael@0 | 75 | let networkProxyTypePref = doc.getElementById("network.proxy.type"); |
michael@0 | 76 | |
michael@0 | 77 | // make sure the networkProxyNone textbox is formatted properly |
michael@0 | 78 | is(networkProxyNone.getAttribute("multiline"), "true", |
michael@0 | 79 | "networkProxyNone textbox is multiline"); |
michael@0 | 80 | is(networkProxyNone.getAttribute("rows"), "2", |
michael@0 | 81 | "networkProxyNone textbox has two rows"); |
michael@0 | 82 | |
michael@0 | 83 | // check if sanitizing the given input for the no_proxies_on pref results in |
michael@0 | 84 | // expected string |
michael@0 | 85 | function testSanitize(input, expected, errorMessage) { |
michael@0 | 86 | networkProxyNonePref.value = input; |
michael@0 | 87 | win.gConnectionsDialog.sanitizeNoProxiesPref(); |
michael@0 | 88 | is(networkProxyNonePref.value, expected, errorMessage); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | // change this pref so proxy exceptions are actually configurable |
michael@0 | 92 | networkProxyTypePref.value = 1; |
michael@0 | 93 | is(networkProxyNone.disabled, false, "networkProxyNone textbox is enabled"); |
michael@0 | 94 | |
michael@0 | 95 | testSanitize(".a.com", ".a.com", |
michael@0 | 96 | "sanitize doesn't mess up single filter"); |
michael@0 | 97 | testSanitize(".a.com, .b.com, .c.com", ".a.com, .b.com, .c.com", |
michael@0 | 98 | "sanitize doesn't mess up multiple comma/space sep filters"); |
michael@0 | 99 | testSanitize(".a.com\n.b.com", ".a.com,.b.com", |
michael@0 | 100 | "sanitize turns line break into comma"); |
michael@0 | 101 | testSanitize(".a.com,\n.b.com", ".a.com,.b.com", |
michael@0 | 102 | "sanitize doesn't add duplicate comma after comma"); |
michael@0 | 103 | testSanitize(".a.com\n,.b.com", ".a.com,.b.com", |
michael@0 | 104 | "sanitize doesn't add duplicate comma before comma"); |
michael@0 | 105 | testSanitize(".a.com,\n,.b.com", ".a.com,,.b.com", |
michael@0 | 106 | "sanitize doesn't add duplicate comma surrounded by commas"); |
michael@0 | 107 | testSanitize(".a.com, \n.b.com", ".a.com, .b.com", |
michael@0 | 108 | "sanitize doesn't add comma after comma/space"); |
michael@0 | 109 | testSanitize(".a.com\n .b.com", ".a.com, .b.com", |
michael@0 | 110 | "sanitize adds comma before space"); |
michael@0 | 111 | testSanitize(".a.com\n\n\n;;\n;\n.b.com", ".a.com,.b.com", |
michael@0 | 112 | "sanitize only adds one comma per substring of bad chars"); |
michael@0 | 113 | testSanitize(".a.com,,.b.com", ".a.com,,.b.com", |
michael@0 | 114 | "duplicate commas from user are untouched"); |
michael@0 | 115 | testSanitize(".a.com\n.b.com\n.c.com,\n.d.com,\n.e.com", |
michael@0 | 116 | ".a.com,.b.com,.c.com,.d.com,.e.com", |
michael@0 | 117 | "sanitize replaces things globally"); |
michael@0 | 118 | |
michael@0 | 119 | // will check that this was sanitized properly after window closes |
michael@0 | 120 | networkProxyNonePref.value = ".a.com;.b.com\n.c.com"; |
michael@0 | 121 | } |