Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
1 /* -*- Mode: Javasript; indent-tab-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 Cu.import("resource://testing-common/httpd.js");
8 const gDashboard = Cc['@mozilla.org/network/dashboard;1']
9 .getService(Ci.nsIDashboard);
11 const gServerSocket = Components.classes["@mozilla.org/network/server-socket;1"]
12 .createInstance(Components.interfaces.nsIServerSocket);
13 const gHttpServer = new HttpServer();
15 add_test(function test_http() {
16 gDashboard.requestHttpConnections(function(data) {
17 let found = false;
18 for (let i = 0; i < data.connections.length; i++) {
19 if (data.connections[i].host == "localhost") {
20 found = true;
21 break;
22 }
23 }
24 do_check_eq(found, true);
26 run_next_test();
27 });
28 });
30 add_test(function test_dns() {
31 gDashboard.requestDNSInfo(function(data) {
32 let found = false;
33 for (let i = 0; i < data.entries.length; i++) {
34 if (data.entries[i].hostname == "localhost") {
35 found = true;
36 break;
37 }
38 }
39 do_check_eq(found, true);
41 do_test_pending();
42 gHttpServer.stop(do_test_finished);
44 run_next_test();
45 });
46 });
48 add_test(function test_sockets() {
49 let sts = Cc["@mozilla.org/network/socket-transport-service;1"]
50 .getService(Ci.nsISocketTransportService);
51 let threadManager = Cc["@mozilla.org/thread-manager;1"].getService();
53 let transport = sts.createTransport(null, 0, "127.0.0.1",
54 gServerSocket.port, null);
55 let listener = {
56 onTransportStatus: function(aTransport, aStatus, aProgress, aProgressMax) {
57 if (aStatus == Ci.nsISocketTransport.STATUS_CONNECTED_TO) {
58 gDashboard.requestSockets(function(data) {
59 gServerSocket.close();
60 let found = false;
61 for (let i = 0; i < data.sockets.length; i++) {
62 if (data.sockets[i].host == "127.0.0.1") {
63 found = true;
64 break;
65 }
66 }
67 do_check_eq(found, true);
69 run_next_test();
70 });
71 }
72 }
73 };
74 transport.setEventSink(listener, threadManager.currentThread);
76 transport.openOutputStream(Ci.nsITransport.OPEN_BLOCKING, 0, 0);
77 });
79 function run_test() {
80 let ioService = Cc["@mozilla.org/network/io-service;1"]
81 .getService(Ci.nsIIOService);
83 gHttpServer.start(-1);
85 let uri = ioService.newURI("http://localhost:" + gHttpServer.identity.primaryPort,
86 null, null);
87 let channel = ioService.newChannelFromURI(uri);
89 channel.open();
91 gServerSocket.init(-1, true, -1);
93 run_next_test();
94 }