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 { HttpServer
} = ChromeUtils
.importESModule(
9 "resource://testing-common/httpd.sys.mjs"
12 const gDashboard
= Cc
["@mozilla.org/network/dashboard;1"].getService(
16 const gServerSocket
= Cc
["@mozilla.org/network/server-socket;1"].createInstance(
19 const gHttpServer
= new HttpServer();
21 add_test(function test_http() {
22 gDashboard
.requestHttpConnections(function (data
) {
24 for (let i
= 0; i
< data
.connections
.length
; i
++) {
25 if (data
.connections
[i
].host
== "localhost") {
30 Assert
.equal(found
, true);
36 add_test(function test_dns() {
37 gDashboard
.requestDNSInfo(function (data
) {
39 for (let i
= 0; i
< data
.entries
.length
; i
++) {
40 if (data
.entries
[i
].hostname
== "localhost") {
45 Assert
.equal(found
, true);
48 gHttpServer
.stop(do_test_finished
);
54 add_test(function test_sockets() {
55 // TODO: enable this test in bug 1581892.
56 if (mozinfo
.socketprocess_networking
) {
57 info("skip test_sockets");
62 let sts
= Cc
["@mozilla.org/network/socket-transport-service;1"].getService(
63 Ci
.nsISocketTransportService
65 let threadManager
= Cc
["@mozilla.org/thread-manager;1"].getService();
67 let transport
= sts
.createTransport(
75 onTransportStatus(aTransport
, aStatus
) {
76 if (aStatus
== Ci
.nsISocketTransport
.STATUS_CONNECTED_TO
) {
77 gDashboard
.requestSockets(function (data
) {
78 gServerSocket
.close();
80 for (let i
= 0; i
< data
.sockets
.length
; i
++) {
81 if (data
.sockets
[i
].host
== "127.0.0.1") {
86 Assert
.equal(found
, true);
93 transport
.setEventSink(listener
, threadManager
.currentThread
);
95 transport
.openOutputStream(Ci
.nsITransport
.OPEN_BLOCKING
, 0, 0);
99 Services
.prefs
.setBoolPref(
100 "network.cookieJarSettings.unblocked_for_testing",
104 // We always resolve localhost as it's hardcoded without the following pref:
105 Services
.prefs
.setBoolPref("network.proxy.allow_hijacking_localhost", true);
107 gHttpServer
.start(-1);
109 let uri
= Services
.io
.newURI(
110 "http://localhost:" + gHttpServer
.identity
.primaryPort
112 let channel
= NetUtil
.newChannel({ uri
, loadUsingSystemPrincipal
: true });
116 gServerSocket
.init(-1, true, -1);
117 Services
.prefs
.clearUserPref("network.proxy.allow_hijacking_localhost");