michael@0: /* -*- Mode: Javasript; indent-tab-mode: nil; js-indent-level: 2 -*- */ 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: Cu.import("resource://testing-common/httpd.js"); michael@0: michael@0: const gDashboard = Cc['@mozilla.org/network/dashboard;1'] michael@0: .getService(Ci.nsIDashboard); michael@0: michael@0: const gServerSocket = Components.classes["@mozilla.org/network/server-socket;1"] michael@0: .createInstance(Components.interfaces.nsIServerSocket); michael@0: const gHttpServer = new HttpServer(); michael@0: michael@0: add_test(function test_http() { michael@0: gDashboard.requestHttpConnections(function(data) { michael@0: let found = false; michael@0: for (let i = 0; i < data.connections.length; i++) { michael@0: if (data.connections[i].host == "localhost") { michael@0: found = true; michael@0: break; michael@0: } michael@0: } michael@0: do_check_eq(found, true); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: michael@0: add_test(function test_dns() { michael@0: gDashboard.requestDNSInfo(function(data) { michael@0: let found = false; michael@0: for (let i = 0; i < data.entries.length; i++) { michael@0: if (data.entries[i].hostname == "localhost") { michael@0: found = true; michael@0: break; michael@0: } michael@0: } michael@0: do_check_eq(found, true); michael@0: michael@0: do_test_pending(); michael@0: gHttpServer.stop(do_test_finished); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: michael@0: add_test(function test_sockets() { michael@0: let sts = Cc["@mozilla.org/network/socket-transport-service;1"] michael@0: .getService(Ci.nsISocketTransportService); michael@0: let threadManager = Cc["@mozilla.org/thread-manager;1"].getService(); michael@0: michael@0: let transport = sts.createTransport(null, 0, "127.0.0.1", michael@0: gServerSocket.port, null); michael@0: let listener = { michael@0: onTransportStatus: function(aTransport, aStatus, aProgress, aProgressMax) { michael@0: if (aStatus == Ci.nsISocketTransport.STATUS_CONNECTED_TO) { michael@0: gDashboard.requestSockets(function(data) { michael@0: gServerSocket.close(); michael@0: let found = false; michael@0: for (let i = 0; i < data.sockets.length; i++) { michael@0: if (data.sockets[i].host == "127.0.0.1") { michael@0: found = true; michael@0: break; michael@0: } michael@0: } michael@0: do_check_eq(found, true); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: } michael@0: } michael@0: }; michael@0: transport.setEventSink(listener, threadManager.currentThread); michael@0: michael@0: transport.openOutputStream(Ci.nsITransport.OPEN_BLOCKING, 0, 0); michael@0: }); michael@0: michael@0: function run_test() { michael@0: let ioService = Cc["@mozilla.org/network/io-service;1"] michael@0: .getService(Ci.nsIIOService); michael@0: michael@0: gHttpServer.start(-1); michael@0: michael@0: let uri = ioService.newURI("http://localhost:" + gHttpServer.identity.primaryPort, michael@0: null, null); michael@0: let channel = ioService.newChannelFromURI(uri); michael@0: michael@0: channel.open(); michael@0: michael@0: gServerSocket.init(-1, true, -1); michael@0: michael@0: run_next_test(); michael@0: } michael@0: