1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 const gDashboard
= Cc
["@mozilla.org/network/dashboard;1"].getService(
12 function connectionFailed(status
) {
14 "NS_NET_STATUS_RESOLVING_HOST",
15 "NS_NET_STATUS_RESOLVED_HOST",
16 "NS_NET_STATUS_CONNECTING_TO",
17 "NS_NET_STATUS_CONNECTED_TO",
19 for (let i
= 0; i
< status_ok
.length
; i
++) {
20 if (status
== status_ok
[i
]) {
28 function test_sockets(serverSocket
) {
29 // TODO: enable this test in bug 1581892.
30 if (mozinfo
.socketprocess_networking
) {
31 info("skip test_sockets");
37 gDashboard
.requestSockets(function (data
) {
39 info("requestSockets: " + JSON
.stringify(data
.sockets
));
40 for (let i
= 0; i
< data
.sockets
.length
; i
++) {
41 if (data
.sockets
[i
].host
== "127.0.0.1") {
46 Assert
.notEqual(index
, -1);
47 Assert
.equal(data
.sockets
[index
].port
, serverSocket
.port
);
48 Assert
.equal(data
.sockets
[index
].type
, "TCP");
55 var ps
= Services
.prefs
;
56 // disable network changed events to avoid the the risk of having the dns
57 // cache getting flushed behind our back
58 ps
.setBoolPref("network.notify.changed", false);
59 // Localhost is hardcoded to loopback and isn't cached, disable that with this pref
60 ps
.setBoolPref("network.proxy.allow_hijacking_localhost", true);
62 registerCleanupFunction(function () {
63 ps
.clearUserPref("network.notify.changed");
64 ps
.clearUserPref("network.proxy.allow_hijacking_localhost");
67 let serverSocket
= Cc
["@mozilla.org/network/server-socket;1"].createInstance(
70 serverSocket
.init(-1, true, -1);
73 gDashboard
.requestConnection(
79 if (connInfo
.status
== "NS_NET_STATUS_CONNECTED_TO") {
81 gDashboard
.requestDNSInfo(function (data
) {
83 info("requestDNSInfo: " + JSON
.stringify(data
.entries
));
84 for (let i
= 0; i
< data
.entries
.length
; i
++) {
85 if (data
.entries
[i
].hostname
== "localhost") {
90 Assert
.equal(found
, true);
93 test_sockets(serverSocket
);
98 if (connectionFailed(connInfo
.status
)) {
99 do_throw(connInfo
.status
);