| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/net/network_stats.h" | 7 #include "chrome/browser/net/network_stats.h" |
| 8 #include "net/base/host_resolver.h" | 8 #include "net/base/host_resolver.h" |
| 9 #include "net/base/mock_host_resolver.h" | 9 #include "net/base/mock_host_resolver.h" |
| 10 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // Flush the message loop to make application verifiers happy. | 22 // Flush the message loop to make application verifiers happy. |
| 23 message_loop_.RunAllPending(); | 23 message_loop_.RunAllPending(); |
| 24 } | 24 } |
| 25 MessageLoopForIO message_loop_; | 25 MessageLoopForIO message_loop_; |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 class NetworkStatsTestUDP : public NetworkStatsTest { | 28 class NetworkStatsTestUDP : public NetworkStatsTest { |
| 29 public: | 29 public: |
| 30 NetworkStatsTestUDP() | 30 NetworkStatsTestUDP() |
| 31 : test_server_(net::TestServer::TYPE_UDP_ECHO, | 31 : test_server_(net::TestServer::TYPE_UDP_ECHO, |
| 32 net::TestServer::kLocalhost, |
| 32 FilePath(FILE_PATH_LITERAL("net/data"))) { | 33 FilePath(FILE_PATH_LITERAL("net/data"))) { |
| 33 } | 34 } |
| 34 | 35 |
| 35 protected: | 36 protected: |
| 36 void RunUDPEchoTest(int bytes) { | 37 void RunUDPEchoTest(int bytes) { |
| 37 net::TestCompletionCallback cb; | 38 net::TestCompletionCallback cb; |
| 38 | 39 |
| 39 scoped_ptr<net::MockHostResolver> host_resolver( | 40 scoped_ptr<net::MockHostResolver> host_resolver( |
| 40 new net::MockHostResolver()); | 41 new net::MockHostResolver()); |
| 41 | 42 |
| 42 UDPStatsClient* udp_stats_client = new UDPStatsClient(); | 43 UDPStatsClient* udp_stats_client = new UDPStatsClient(); |
| 43 EXPECT_TRUE(udp_stats_client->Start(host_resolver.get(), | 44 EXPECT_TRUE(udp_stats_client->Start(host_resolver.get(), |
| 44 test_server_.host_port_pair(), | 45 test_server_.host_port_pair(), |
| 45 bytes, | 46 bytes, |
| 46 cb.callback())); | 47 cb.callback())); |
| 47 int rv = cb.WaitForResult(); | 48 int rv = cb.WaitForResult(); |
| 48 // Check there were no errors during connect/write/read to echo UDP server. | 49 // Check there were no errors during connect/write/read to echo UDP server. |
| 49 EXPECT_EQ(0, rv); | 50 EXPECT_EQ(0, rv); |
| 50 } | 51 } |
| 51 | 52 |
| 52 net::TestServer test_server_; | 53 net::TestServer test_server_; |
| 53 }; | 54 }; |
| 54 | 55 |
| 55 class NetworkStatsTestTCP : public NetworkStatsTest { | 56 class NetworkStatsTestTCP : public NetworkStatsTest { |
| 56 public: | 57 public: |
| 57 NetworkStatsTestTCP() | 58 NetworkStatsTestTCP() |
| 58 : test_server_(net::TestServer::TYPE_TCP_ECHO, | 59 : test_server_(net::TestServer::TYPE_TCP_ECHO, |
| 60 net::TestServer::kLocalhost, |
| 59 FilePath(FILE_PATH_LITERAL("net/data"))) { | 61 FilePath(FILE_PATH_LITERAL("net/data"))) { |
| 60 } | 62 } |
| 61 | 63 |
| 62 protected: | 64 protected: |
| 63 void RunTCPEchoTest(int bytes) { | 65 void RunTCPEchoTest(int bytes) { |
| 64 net::TestCompletionCallback cb; | 66 net::TestCompletionCallback cb; |
| 65 | 67 |
| 66 scoped_ptr<net::MockHostResolver> host_resolver( | 68 scoped_ptr<net::MockHostResolver> host_resolver( |
| 67 new net::MockHostResolver()); | 69 new net::MockHostResolver()); |
| 68 | 70 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 93 ASSERT_TRUE(test_server_.Start()); | 95 ASSERT_TRUE(test_server_.Start()); |
| 94 RunTCPEchoTest(50); | 96 RunTCPEchoTest(50); |
| 95 } | 97 } |
| 96 | 98 |
| 97 TEST_F(NetworkStatsTestTCP, TCPEcho_1K_Of_Data) { | 99 TEST_F(NetworkStatsTestTCP, TCPEcho_1K_Of_Data) { |
| 98 ASSERT_TRUE(test_server_.Start()); | 100 ASSERT_TRUE(test_server_.Start()); |
| 99 RunTCPEchoTest(1024); | 101 RunTCPEchoTest(1024); |
| 100 } | 102 } |
| 101 | 103 |
| 102 } // namespace chrome_browser_net | 104 } // namespace chrome_browser_net |
| OLD | NEW |