michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: var ioService = Cc["@mozilla.org/network/io-service;1"]. michael@0: getService(Ci.nsIIOService); michael@0: michael@0: var prefs = Cc["@mozilla.org/preferences-service;1"]. michael@0: getService(Ci.nsIPrefBranch); michael@0: michael@0: var url = "ws://dnsleak.example.com"; michael@0: michael@0: var dnsRequestObserver = { michael@0: register: function() { michael@0: this.obs = Cc["@mozilla.org/observer-service;1"]. michael@0: getService(Ci.nsIObserverService); michael@0: this.obs.addObserver(this, "dns-resolution-request", false); michael@0: }, michael@0: michael@0: unregister: function() { michael@0: if (this.obs) { michael@0: this.obs.removeObserver(this, "dns-resolution-request"); michael@0: } michael@0: }, michael@0: michael@0: observe: function(subject, topic, data) { michael@0: if (topic == "dns-resolution-request") { michael@0: do_print(data); michael@0: if (data.indexOf("dnsleak.example.com") > -1) { michael@0: try { michael@0: do_check_true(false); michael@0: } catch (e) {} michael@0: } michael@0: } michael@0: } michael@0: }; michael@0: michael@0: var listener = { michael@0: onAcknowledge: function(aContext, aSize) {}, michael@0: onBinaryMessageAvailable: function(aContext, aMsg) {}, michael@0: onMessageAvailable: function(aContext, aMsg) {}, michael@0: onServerClose: function(aContext, aCode, aReason) {}, michael@0: onStart: function(aContext) {}, michael@0: onStop: function(aContext, aStatusCode) { michael@0: prefs.clearUserPref("network.proxy.socks"); michael@0: prefs.clearUserPref("network.proxy.socks_port"); michael@0: prefs.clearUserPref("network.proxy.type"); michael@0: prefs.clearUserPref("network.proxy.socks_remote_dns"); michael@0: prefs.clearUserPref("network.dns.notifyResolution"); michael@0: dnsRequestObserver.unregister(); michael@0: do_test_finished(); michael@0: } michael@0: }; michael@0: michael@0: function run_test() { michael@0: dnsRequestObserver.register(); michael@0: prefs.setBoolPref("network.dns.notifyResolution", true); michael@0: prefs.setCharPref("network.proxy.socks", "127.0.0.1"); michael@0: prefs.setIntPref("network.proxy.socks_port", 9000); michael@0: prefs.setIntPref("network.proxy.type", 1); michael@0: prefs.setBoolPref("network.proxy.socks_remote_dns", true); michael@0: var chan = Cc["@mozilla.org/network/protocol;1?name=ws"]. michael@0: createInstance(Components.interfaces.nsIWebSocketChannel); michael@0: var uri = ioService.newURI(url, null, null); michael@0: chan.asyncOpen(uri, url, listener, null); michael@0: do_test_pending(); michael@0: } michael@0: