netwerk/test/unit/test_dns_proxy_bypass.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:5c9fcb90acd8
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 var ioService = Cc["@mozilla.org/network/io-service;1"].
6 getService(Ci.nsIIOService);
7
8 var prefs = Cc["@mozilla.org/preferences-service;1"].
9 getService(Ci.nsIPrefBranch);
10
11 var url = "ws://dnsleak.example.com";
12
13 var dnsRequestObserver = {
14 register: function() {
15 this.obs = Cc["@mozilla.org/observer-service;1"].
16 getService(Ci.nsIObserverService);
17 this.obs.addObserver(this, "dns-resolution-request", false);
18 },
19
20 unregister: function() {
21 if (this.obs) {
22 this.obs.removeObserver(this, "dns-resolution-request");
23 }
24 },
25
26 observe: function(subject, topic, data) {
27 if (topic == "dns-resolution-request") {
28 do_print(data);
29 if (data.indexOf("dnsleak.example.com") > -1) {
30 try {
31 do_check_true(false);
32 } catch (e) {}
33 }
34 }
35 }
36 };
37
38 var listener = {
39 onAcknowledge: function(aContext, aSize) {},
40 onBinaryMessageAvailable: function(aContext, aMsg) {},
41 onMessageAvailable: function(aContext, aMsg) {},
42 onServerClose: function(aContext, aCode, aReason) {},
43 onStart: function(aContext) {},
44 onStop: function(aContext, aStatusCode) {
45 prefs.clearUserPref("network.proxy.socks");
46 prefs.clearUserPref("network.proxy.socks_port");
47 prefs.clearUserPref("network.proxy.type");
48 prefs.clearUserPref("network.proxy.socks_remote_dns");
49 prefs.clearUserPref("network.dns.notifyResolution");
50 dnsRequestObserver.unregister();
51 do_test_finished();
52 }
53 };
54
55 function run_test() {
56 dnsRequestObserver.register();
57 prefs.setBoolPref("network.dns.notifyResolution", true);
58 prefs.setCharPref("network.proxy.socks", "127.0.0.1");
59 prefs.setIntPref("network.proxy.socks_port", 9000);
60 prefs.setIntPref("network.proxy.type", 1);
61 prefs.setBoolPref("network.proxy.socks_remote_dns", true);
62 var chan = Cc["@mozilla.org/network/protocol;1?name=ws"].
63 createInstance(Components.interfaces.nsIWebSocketChannel);
64 var uri = ioService.newURI(url, null, null);
65 chan.asyncOpen(uri, url, listener, null);
66 do_test_pending();
67 }
68

mercurial