OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/basictypes.h" |
| 6 #include "base/message_loop.h" |
| 7 #include "chrome/browser/net/network_stats.h" |
| 8 #include "net/base/test_completion_callback.h" |
| 9 #include "net/test/test_server.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "testing/platform_test.h" |
| 12 |
| 13 namespace chrome_browser_net { |
| 14 |
| 15 class NetworkStatsTest : public PlatformTest { |
| 16 public: |
| 17 NetworkStatsTest() {} |
| 18 protected: |
| 19 virtual void TearDown() { |
| 20 // Flush the message loop to make Purify happy. |
| 21 message_loop_.RunAllPending(); |
| 22 } |
| 23 MessageLoopForIO message_loop_; |
| 24 }; |
| 25 |
| 26 class NetworkStatsTestUDP : public NetworkStatsTest { |
| 27 public: |
| 28 NetworkStatsTestUDP() |
| 29 : test_server_(net::TestServer::TYPE_UDP_ECHO, |
| 30 FilePath(FILE_PATH_LITERAL("net/data"))) { |
| 31 } |
| 32 |
| 33 protected: |
| 34 void RunUDPEchoTest(int bytes) { |
| 35 TestCompletionCallback cb; |
| 36 |
| 37 scoped_refptr<UDPStatsClient> udp_stats_client(new UDPStatsClient()); |
| 38 EXPECT_TRUE(udp_stats_client->Start(test_server_.host_port_pair().host(), |
| 39 test_server_.host_port_pair().port(), |
| 40 bytes, |
| 41 &cb)); |
| 42 int rv = cb.WaitForResult(); |
| 43 // Check there were no errors during connect/write/read to echo UDP server. |
| 44 EXPECT_EQ(0, rv); |
| 45 } |
| 46 |
| 47 net::TestServer test_server_; |
| 48 }; |
| 49 |
| 50 class NetworkStatsTestTCP : public NetworkStatsTest { |
| 51 public: |
| 52 NetworkStatsTestTCP() |
| 53 : test_server_(net::TestServer::TYPE_TCP_ECHO, |
| 54 FilePath(FILE_PATH_LITERAL("net/data"))) { |
| 55 } |
| 56 |
| 57 protected: |
| 58 void RunTCPEchoTest(int bytes) { |
| 59 TestCompletionCallback cb; |
| 60 |
| 61 scoped_refptr<TCPStatsClient> tcp_stats_client(new TCPStatsClient()); |
| 62 EXPECT_TRUE(tcp_stats_client->Start(test_server_.host_port_pair(), |
| 63 bytes, |
| 64 &cb)); |
| 65 int rv = cb.WaitForResult(); |
| 66 // Check there were no errors during connect/write/read to echo TCP server. |
| 67 EXPECT_EQ(0, rv); |
| 68 } |
| 69 |
| 70 net::TestServer test_server_; |
| 71 }; |
| 72 |
| 73 TEST_F(NetworkStatsTestUDP, UDPEcho_50B_Of_Data) { |
| 74 ASSERT_TRUE(test_server_.Start()); |
| 75 RunUDPEchoTest(50); |
| 76 } |
| 77 |
| 78 TEST_F(NetworkStatsTestUDP, UDPEcho_1K_Of_Data) { |
| 79 ASSERT_TRUE(test_server_.Start()); |
| 80 RunUDPEchoTest(1024); |
| 81 } |
| 82 |
| 83 TEST_F(NetworkStatsTestTCP, TCPEcho_50B_Of_Data) { |
| 84 ASSERT_TRUE(test_server_.Start()); |
| 85 RunTCPEchoTest(50); |
| 86 } |
| 87 |
| 88 TEST_F(NetworkStatsTestTCP, TCPEcho_1K_Of_Data) { |
| 89 ASSERT_TRUE(test_server_.Start()); |
| 90 RunTCPEchoTest(1024); |
| 91 } |
| 92 |
| 93 } // namespace chrome_browser_net |
OLD | NEW |