Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: chrome/browser/net/network_stats_unittest.cc

Issue 9430050: Remove usage of a deprecated TestServer constructor. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "net/test/test_server.h" 11 #include "net/test/test_server.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/platform_test.h" 13 #include "testing/platform_test.h"
14 14
15 namespace chrome_browser_net { 15 namespace chrome_browser_net {
16 16
17 class NetworkStatsTest : public PlatformTest { 17 template <typename T> class NetworkStatsTest : public PlatformTest {
eroman 2012/02/23 21:06:19 Could you propose this change separately? I would
18 public: 18 public:
19 NetworkStatsTest() {} 19 NetworkStatsTest()
20 : test_server_(T::server_type,
21 net::TestServer::kLocalhost,
22 FilePath(FILE_PATH_LITERAL("net/data"))) {
23 }
20 protected: 24 protected:
21 virtual void TearDown() { 25 virtual void TearDown() {
22 // Flush the message loop to make application verifiers happy. 26 // Flush the message loop to make application verifiers happy.
23 message_loop_.RunAllPending(); 27 message_loop_.RunAllPending();
24 } 28 }
25 MessageLoopForIO message_loop_;
26 };
27 29
28 class NetworkStatsTestUDP : public NetworkStatsTest { 30 void RunEchoTest(int bytes) {
29 public:
30 NetworkStatsTestUDP()
31 : test_server_(net::TestServer::TYPE_UDP_ECHO,
32 FilePath(FILE_PATH_LITERAL("net/data"))) {
33 }
34
35 protected:
36 void RunUDPEchoTest(int bytes) {
37 net::TestCompletionCallback cb; 31 net::TestCompletionCallback cb;
38 32
39 scoped_ptr<net::MockHostResolver> host_resolver( 33 scoped_ptr<net::MockHostResolver> host_resolver(
40 new net::MockHostResolver()); 34 new net::MockHostResolver());
41 35
42 UDPStatsClient* udp_stats_client = new UDPStatsClient(); 36 typename T::StatsClient* stats_client = new typename T::StatsClient();
43 EXPECT_TRUE(udp_stats_client->Start(host_resolver.get(), 37 EXPECT_TRUE(stats_client->Start(host_resolver.get(),
44 test_server_.host_port_pair(), 38 test_server_.host_port_pair(),
45 bytes, 39 bytes,
46 cb.callback())); 40 cb.callback()));
47 int rv = cb.WaitForResult(); 41 int rv = cb.WaitForResult();
48 // Check there were no errors during connect/write/read to echo UDP server. 42 // Check there were no errors during connect/write/read to echo server.
49 EXPECT_EQ(0, rv); 43 EXPECT_EQ(0, rv);
50 } 44 }
51 45
46 MessageLoopForIO message_loop_;
52 net::TestServer test_server_; 47 net::TestServer test_server_;
53 }; 48 };
54 49
55 class NetworkStatsTestTCP : public NetworkStatsTest { 50 struct NetworkStatsTestUDPTraits {
56 public: 51 typedef UDPStatsClient StatsClient;
57 NetworkStatsTestTCP() 52 static const net::TestServer::Type server_type =
58 : test_server_(net::TestServer::TYPE_TCP_ECHO, 53 net::TestServer::TYPE_UDP_ECHO;
59 FilePath(FILE_PATH_LITERAL("net/data"))) {
60 }
61
62 protected:
63 void RunTCPEchoTest(int bytes) {
64 net::TestCompletionCallback cb;
65
66 scoped_ptr<net::MockHostResolver> host_resolver(
67 new net::MockHostResolver());
68
69 TCPStatsClient* tcp_stats_client = new TCPStatsClient();
70 EXPECT_TRUE(tcp_stats_client->Start(host_resolver.get(),
71 test_server_.host_port_pair(),
72 bytes,
73 cb.callback()));
74 int rv = cb.WaitForResult();
75 // Check there were no errors during connect/write/read to echo TCP server.
76 EXPECT_EQ(0, rv);
77 }
78
79 net::TestServer test_server_;
80 }; 54 };
81 55
82 TEST_F(NetworkStatsTestUDP, UDPEcho_50B_Of_Data) { 56 struct NetworkStatsTestTCPTraits {
83 ASSERT_TRUE(test_server_.Start()); 57 typedef TCPStatsClient StatsClient;
84 RunUDPEchoTest(50); 58 static const net::TestServer::Type server_type =
59 net::TestServer::TYPE_TCP_ECHO;
60 };
61
62 typedef ::testing::Types<NetworkStatsTestUDPTraits, NetworkStatsTestTCPTraits>
63 NetworkStatsTestTypes;
64 TYPED_TEST_CASE(NetworkStatsTest, NetworkStatsTestTypes);
65
66 TYPED_TEST(NetworkStatsTest, Echo_50B_Of_Data) {
67 ASSERT_TRUE(this->test_server_.Start());
68 this->RunEchoTest(50);
85 } 69 }
86 70
87 TEST_F(NetworkStatsTestUDP, UDPEcho_1K_Of_Data) { 71 TYPED_TEST(NetworkStatsTest, Echo_1K_Of_Data) {
88 ASSERT_TRUE(test_server_.Start()); 72 ASSERT_TRUE(this->test_server_.Start());
89 RunUDPEchoTest(1024); 73 this->RunEchoTest(1024);
90 }
91
92 TEST_F(NetworkStatsTestTCP, TCPEcho_50B_Of_Data) {
93 ASSERT_TRUE(test_server_.Start());
94 RunTCPEchoTest(50);
95 }
96
97 TEST_F(NetworkStatsTestTCP, TCPEcho_1K_Of_Data) {
98 ASSERT_TRUE(test_server_.Start());
99 RunTCPEchoTest(1024);
100 } 74 }
101 75
102 } // namespace chrome_browser_net 76 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698