Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / netwerk / test / unit / test_about_networking.js
blobb8b864c5a06e3fa502eafd6e0935807b7f81d683
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/. */
6 "use strict";
8 const { HttpServer } = ChromeUtils.importESModule(
9 "resource://testing-common/httpd.sys.mjs"
12 const gDashboard = Cc["@mozilla.org/network/dashboard;1"].getService(
13 Ci.nsIDashboard
16 const gServerSocket = Cc["@mozilla.org/network/server-socket;1"].createInstance(
17 Ci.nsIServerSocket
19 const gHttpServer = new HttpServer();
21 add_test(function test_http() {
22 gDashboard.requestHttpConnections(function (data) {
23 let found = false;
24 for (let i = 0; i < data.connections.length; i++) {
25 if (data.connections[i].host == "localhost") {
26 found = true;
27 break;
30 Assert.equal(found, true);
32 run_next_test();
33 });
34 });
36 add_test(function test_dns() {
37 gDashboard.requestDNSInfo(function (data) {
38 let found = false;
39 for (let i = 0; i < data.entries.length; i++) {
40 if (data.entries[i].hostname == "localhost") {
41 found = true;
42 break;
45 Assert.equal(found, true);
47 do_test_pending();
48 gHttpServer.stop(do_test_finished);
50 run_next_test();
51 });
52 });
54 add_test(function test_sockets() {
55 // TODO: enable this test in bug 1581892.
56 if (mozinfo.socketprocess_networking) {
57 info("skip test_sockets");
58 run_next_test();
59 return;
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(
68 [],
69 "127.0.0.1",
70 gServerSocket.port,
71 null,
72 null
74 let listener = {
75 onTransportStatus(aTransport, aStatus) {
76 if (aStatus == Ci.nsISocketTransport.STATUS_CONNECTED_TO) {
77 gDashboard.requestSockets(function (data) {
78 gServerSocket.close();
79 let found = false;
80 for (let i = 0; i < data.sockets.length; i++) {
81 if (data.sockets[i].host == "127.0.0.1") {
82 found = true;
83 break;
86 Assert.equal(found, true);
88 run_next_test();
89 });
93 transport.setEventSink(listener, threadManager.currentThread);
95 transport.openOutputStream(Ci.nsITransport.OPEN_BLOCKING, 0, 0);
96 });
98 function run_test() {
99 Services.prefs.setBoolPref(
100 "network.cookieJarSettings.unblocked_for_testing",
101 true
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 });
114 channel.open();
116 gServerSocket.init(-1, true, -1);
117 Services.prefs.clearUserPref("network.proxy.allow_hijacking_localhost");
119 run_next_test();