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: const gDashboard = Cc['@mozilla.org/network/dashboard;1'] michael@0: .getService(Ci.nsIDashboard); michael@0: michael@0: function connectionFailed(status) { michael@0: let status_ok = [ michael@0: "NS_NET_STATUS_RESOLVING_HOST" michael@0: ,"NS_NET_STATUS_RESOLVED_HOST" michael@0: ,"NS_NET_STATUS_CONNECTING_TO" michael@0: ,"NS_NET_STATUS_CONNECTED_TO" michael@0: ]; michael@0: for (let i = 0; i < status_ok.length; i++) { michael@0: if (status == status_ok[i]) { michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: michael@0: function test_sockets(serverSocket) { michael@0: do_test_pending(); michael@0: gDashboard.requestSockets(function(data) { michael@0: let index = -1; michael@0: do_print("requestSockets: " + JSON.stringify(data.sockets)); michael@0: for (let i = 0; i < data.sockets.length; i++) { michael@0: if (data.sockets[i].host == "127.0.0.1") { michael@0: index = i; michael@0: break; michael@0: } michael@0: } michael@0: do_check_neq(index, -1); michael@0: do_check_eq(data.sockets[index].port, serverSocket.port); michael@0: do_check_eq(data.sockets[index].tcp, 1); michael@0: michael@0: do_test_finished(); michael@0: }); michael@0: } michael@0: michael@0: function run_test() { michael@0: let serverSocket = Components.classes["@mozilla.org/network/server-socket;1"] michael@0: .createInstance(Ci.nsIServerSocket); michael@0: serverSocket.init(-1, true, -1); michael@0: michael@0: do_test_pending(); michael@0: gDashboard.requestConnection("localhost", serverSocket.port, michael@0: "tcp", 15, function(connInfo) { michael@0: if (connInfo.status == "NS_NET_STATUS_CONNECTED_TO") { michael@0: do_test_pending(); michael@0: gDashboard.requestDNSInfo(function(data) { michael@0: let found = false; michael@0: do_print("requestDNSInfo: " + JSON.stringify(data.entries)); 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_finished(); michael@0: test_sockets(serverSocket); michael@0: }); michael@0: michael@0: do_test_finished(); michael@0: } michael@0: if (connectionFailed(connInfo.status)) { michael@0: do_throw(connInfo.status); michael@0: } michael@0: }); michael@0: } michael@0: