| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "chrome/browser/net/network_stats.h" | 8 #include "chrome/browser/net/network_stats.h" |
| 9 #include "net/base/host_resolver.h" | 9 #include "net/base/host_resolver.h" |
| 10 #include "net/base/mock_host_resolver.h" | 10 #include "net/base/mock_host_resolver.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 class NetworkStatsTestUDP : public NetworkStatsTest { | 30 class NetworkStatsTestUDP : public NetworkStatsTest { |
| 31 public: | 31 public: |
| 32 NetworkStatsTestUDP() | 32 NetworkStatsTestUDP() |
| 33 : test_server_(net::TestServer::TYPE_UDP_ECHO, | 33 : test_server_(net::TestServer::TYPE_UDP_ECHO, |
| 34 net::TestServer::kLocalhost, | 34 net::TestServer::kLocalhost, |
| 35 FilePath(FILE_PATH_LITERAL("net/data"))) { | 35 FilePath(FILE_PATH_LITERAL("net/data"))) { |
| 36 } | 36 } |
| 37 | 37 |
| 38 protected: | 38 protected: |
| 39 void RunUDPEchoTest(int bytes, int packets) { | 39 void RunUDPEchoTest(int bytes, int packets, bool has_proxy) { |
| 40 net::TestCompletionCallback cb; | 40 net::TestCompletionCallback cb; |
| 41 | 41 |
| 42 scoped_ptr<net::MockHostResolver> host_resolver( | 42 scoped_ptr<net::MockHostResolver> host_resolver( |
| 43 new net::MockHostResolver()); | 43 new net::MockHostResolver()); |
| 44 | 44 |
| 45 // We will use HISTOGRAM_PORT_MAX as the PortIndex enum for testing | 45 // We will use HISTOGRAM_PORT_MAX as the PortIndex enum for testing |
| 46 // purposes. | 46 // purposes. |
| 47 UDPStatsClient* udp_stats_client = new UDPStatsClient(); | 47 UDPStatsClient* udp_stats_client = new UDPStatsClient(); |
| 48 EXPECT_TRUE(udp_stats_client->Start(host_resolver.get(), | 48 EXPECT_TRUE(udp_stats_client->Start(host_resolver.get(), |
| 49 test_server_.host_port_pair(), | 49 test_server_.host_port_pair(), |
| 50 NetworkStats::HISTOGRAM_PORT_MAX, | 50 NetworkStats::HISTOGRAM_PORT_MAX, |
| 51 has_proxy, |
| 51 bytes, | 52 bytes, |
| 52 packets, | 53 packets, |
| 53 cb.callback())); | 54 cb.callback())); |
| 54 int rv = cb.WaitForResult(); | 55 int rv = cb.WaitForResult(); |
| 55 // Check there were no errors during connect/write/read to echo UDP server. | 56 // Check there were no errors during connect/write/read to echo UDP server. |
| 56 EXPECT_EQ(0, rv); | 57 EXPECT_EQ(0, rv); |
| 57 } | 58 } |
| 58 | 59 |
| 59 net::TestServer test_server_; | 60 net::TestServer test_server_; |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 class NetworkStatsTestTCP : public NetworkStatsTest { | 63 class NetworkStatsTestTCP : public NetworkStatsTest { |
| 63 public: | 64 public: |
| 64 NetworkStatsTestTCP() | 65 NetworkStatsTestTCP() |
| 65 : test_server_(net::TestServer::TYPE_TCP_ECHO, | 66 : test_server_(net::TestServer::TYPE_TCP_ECHO, |
| 66 net::TestServer::kLocalhost, | 67 net::TestServer::kLocalhost, |
| 67 FilePath(FILE_PATH_LITERAL("net/data"))) { | 68 FilePath(FILE_PATH_LITERAL("net/data"))) { |
| 68 } | 69 } |
| 69 | 70 |
| 70 protected: | 71 protected: |
| 71 void RunTCPEchoTest(int bytes, int packets) { | 72 void RunTCPEchoTest(int bytes, int packets, bool has_proxy) { |
| 72 net::TestCompletionCallback cb; | 73 net::TestCompletionCallback cb; |
| 73 | 74 |
| 74 scoped_ptr<net::MockHostResolver> host_resolver( | 75 scoped_ptr<net::MockHostResolver> host_resolver( |
| 75 new net::MockHostResolver()); | 76 new net::MockHostResolver()); |
| 76 | 77 |
| 77 // We will use HISTOGRAM_PORT_MAX as the PortIndex enum for testing | 78 // We will use HISTOGRAM_PORT_MAX as the PortIndex enum for testing |
| 78 // purposes. | 79 // purposes. |
| 79 TCPStatsClient* tcp_stats_client = new TCPStatsClient(); | 80 TCPStatsClient* tcp_stats_client = new TCPStatsClient(); |
| 80 EXPECT_TRUE(tcp_stats_client->Start(host_resolver.get(), | 81 EXPECT_TRUE(tcp_stats_client->Start(host_resolver.get(), |
| 81 test_server_.host_port_pair(), | 82 test_server_.host_port_pair(), |
| 82 NetworkStats::HISTOGRAM_PORT_MAX, | 83 NetworkStats::HISTOGRAM_PORT_MAX, |
| 84 has_proxy, |
| 83 bytes, | 85 bytes, |
| 84 packets, | 86 packets, |
| 85 cb.callback())); | 87 cb.callback())); |
| 86 int rv = cb.WaitForResult(); | 88 int rv = cb.WaitForResult(); |
| 87 // Check there were no errors during connect/write/read to echo TCP server. | 89 // Check there were no errors during connect/write/read to echo TCP server. |
| 88 EXPECT_EQ(0, rv); | 90 EXPECT_EQ(0, rv); |
| 89 } | 91 } |
| 90 | 92 |
| 91 net::TestServer test_server_; | 93 net::TestServer test_server_; |
| 92 }; | 94 }; |
| 93 | 95 |
| 94 TEST_F(NetworkStatsTestUDP, UDPEcho_100B_Of_Data) { | 96 TEST_F(NetworkStatsTestUDP, UDPEcho100BytesHasProxy) { |
| 95 ASSERT_TRUE(test_server_.Start()); | 97 ASSERT_TRUE(test_server_.Start()); |
| 96 RunUDPEchoTest(100, 1); | 98 RunUDPEchoTest(100, 1, true); |
| 97 } | 99 } |
| 98 | 100 |
| 99 TEST_F(NetworkStatsTestUDP, UDPEcho_1K_Of_Data) { | 101 TEST_F(NetworkStatsTestUDP, UDPEcho100BytesNoProxy) { |
| 100 ASSERT_TRUE(test_server_.Start()); | 102 ASSERT_TRUE(test_server_.Start()); |
| 101 RunUDPEchoTest(1024, 1); | 103 RunUDPEchoTest(100, 1, false); |
| 102 } | 104 } |
| 103 | 105 |
| 104 TEST_F(NetworkStatsTestUDP, UDPEchoMultiplePackets) { | 106 TEST_F(NetworkStatsTestUDP, UDPEcho1KBytesHasProxy) { |
| 105 ASSERT_TRUE(test_server_.Start()); | 107 ASSERT_TRUE(test_server_.Start()); |
| 106 RunUDPEchoTest(1024, 4); | 108 RunUDPEchoTest(1024, 1, true); |
| 107 } | 109 } |
| 108 | 110 |
| 109 TEST_F(NetworkStatsTestTCP, TCPEcho_100B_Of_Data) { | 111 TEST_F(NetworkStatsTestUDP, UDPEcho1KBytesNoProxy) { |
| 110 ASSERT_TRUE(test_server_.Start()); | 112 ASSERT_TRUE(test_server_.Start()); |
| 111 RunTCPEchoTest(100, 1); | 113 RunUDPEchoTest(1024, 1, false); |
| 112 } | 114 } |
| 113 | 115 |
| 114 TEST_F(NetworkStatsTestTCP, TCPEcho_1K_Of_Data) { | 116 TEST_F(NetworkStatsTestUDP, UDPEchoMultiplePacketsHasProxy) { |
| 115 ASSERT_TRUE(test_server_.Start()); | 117 ASSERT_TRUE(test_server_.Start()); |
| 116 RunTCPEchoTest(1024, 1); | 118 RunUDPEchoTest(1024, 4, true); |
| 119 } |
| 120 |
| 121 TEST_F(NetworkStatsTestUDP, UDPEchoMultiplePacketsNoProxy) { |
| 122 ASSERT_TRUE(test_server_.Start()); |
| 123 RunUDPEchoTest(1024, 4, false); |
| 124 } |
| 125 |
| 126 TEST_F(NetworkStatsTestTCP, TCPEcho100BytesHasProxy) { |
| 127 ASSERT_TRUE(test_server_.Start()); |
| 128 RunTCPEchoTest(100, 1, true); |
| 129 } |
| 130 |
| 131 TEST_F(NetworkStatsTestTCP, TCPEcho100BytesNoProxy) { |
| 132 ASSERT_TRUE(test_server_.Start()); |
| 133 RunTCPEchoTest(100, 1, false); |
| 134 } |
| 135 |
| 136 TEST_F(NetworkStatsTestTCP, TCPEcho1KBytesHasProxy) { |
| 137 ASSERT_TRUE(test_server_.Start()); |
| 138 RunTCPEchoTest(1024, 1, true); |
| 139 } |
| 140 |
| 141 TEST_F(NetworkStatsTestTCP, TCPEcho1KBytesNoProxy) { |
| 142 ASSERT_TRUE(test_server_.Start()); |
| 143 RunTCPEchoTest(1024, 1, false); |
| 117 } | 144 } |
| 118 | 145 |
| 119 TEST_F(NetworkStatsTestTCP, VerifyBytes) { | 146 TEST_F(NetworkStatsTestTCP, VerifyBytes) { |
| 120 static const uint32 KBytesToSend = 100; | 147 static const uint32 KBytesToSend = 100; |
| 121 static const uint32 packets_to_send = 1; | 148 static const uint32 packets_to_send = 1; |
| 122 static const uint32 packet_number = 1; | 149 static const uint32 packet_number = 1; |
| 123 TCPStatsClient network_stats; | 150 TCPStatsClient network_stats; |
| 124 net::TestCompletionCallback cb; | 151 net::TestCompletionCallback cb; |
| 125 network_stats.Initialize(KBytesToSend, | 152 network_stats.Initialize(KBytesToSend, |
| 126 NetworkStats::HISTOGRAM_PORT_MAX, | 153 NetworkStats::HISTOGRAM_PORT_MAX, |
| 154 true, |
| 127 packets_to_send, | 155 packets_to_send, |
| 128 cb.callback()); | 156 cb.callback()); |
| 129 | 157 |
| 130 std::string message; | 158 std::string message; |
| 131 EXPECT_EQ(NetworkStats::ZERO_LENGTH_ERROR, | 159 EXPECT_EQ(NetworkStats::ZERO_LENGTH_ERROR, |
| 132 network_stats.VerifyBytes(message)); | 160 network_stats.VerifyBytes(message)); |
| 133 | 161 |
| 134 std::string version = base::StringPrintf("%02d", 1); | 162 std::string version = base::StringPrintf("%02d", 1); |
| 135 std::string invalid_checksum = base::StringPrintf("%010d", 0); | 163 std::string invalid_checksum = base::StringPrintf("%010d", 0); |
| 136 std::string payload_size = base::StringPrintf("%07d", KBytesToSend); | 164 std::string payload_size = base::StringPrintf("%07d", KBytesToSend); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 &rtt_histogram_name1, | 301 &rtt_histogram_name1, |
| 274 &status_histogram_name1, | 302 &status_histogram_name1, |
| 275 &packet_loss_histogram_name1); | 303 &packet_loss_histogram_name1); |
| 276 EXPECT_EQ("", rtt_histogram_name1); | 304 EXPECT_EQ("", rtt_histogram_name1); |
| 277 EXPECT_EQ("NetConnectivity.UDP.Status.6121.100B", status_histogram_name1); | 305 EXPECT_EQ("NetConnectivity.UDP.Status.6121.100B", status_histogram_name1); |
| 278 EXPECT_EQ("NetConnectivity.UDP.PacketLoss6.6121.100B", | 306 EXPECT_EQ("NetConnectivity.UDP.PacketLoss6.6121.100B", |
| 279 packet_loss_histogram_name1); | 307 packet_loss_histogram_name1); |
| 280 } | 308 } |
| 281 | 309 |
| 282 } // namespace chrome_browser_net | 310 } // namespace chrome_browser_net |
| OLD | NEW |