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 "chrome/browser/net/connection_tester.h" | 5 #include "chrome/browser/net/connection_tester.h" |
6 | 6 |
7 #include "base/prefs/testing_pref_service.h" | 7 #include "base/prefs/testing_pref_service.h" |
8 #include "content/public/test/test_browser_thread.h" | 8 #include "content/public/test/test_browser_thread.h" |
9 #include "net/cert/mock_cert_verifier.h" | 9 #include "net/cert/mock_cert_verifier.h" |
10 #include "net/cookies/cookie_monster.h" | 10 #include "net/cookies/cookie_monster.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 } | 47 } |
48 | 48 |
49 virtual void OnCompletedConnectionTestExperiment( | 49 virtual void OnCompletedConnectionTestExperiment( |
50 const ConnectionTester::Experiment& experiment, | 50 const ConnectionTester::Experiment& experiment, |
51 int result) OVERRIDE { | 51 int result) OVERRIDE { |
52 completed_connection_test_experiment_count_++; | 52 completed_connection_test_experiment_count_++; |
53 } | 53 } |
54 | 54 |
55 virtual void OnCompletedConnectionTestSuite() OVERRIDE { | 55 virtual void OnCompletedConnectionTestSuite() OVERRIDE { |
56 completed_connection_test_suite_count_++; | 56 completed_connection_test_suite_count_++; |
57 MessageLoop::current()->Quit(); | 57 base::MessageLoop::current()->Quit(); |
58 } | 58 } |
59 | 59 |
60 int start_connection_test_suite_count() const { | 60 int start_connection_test_suite_count() const { |
61 return start_connection_test_suite_count_; | 61 return start_connection_test_suite_count_; |
62 } | 62 } |
63 | 63 |
64 int start_connection_test_experiment_count() const { | 64 int start_connection_test_experiment_count() const { |
65 return start_connection_test_experiment_count_; | 65 return start_connection_test_experiment_count_; |
66 } | 66 } |
67 | 67 |
(...skipping 12 matching lines...) Expand all Loading... |
80 int completed_connection_test_suite_count_; | 80 int completed_connection_test_suite_count_; |
81 }; | 81 }; |
82 | 82 |
83 // The test fixture is responsible for: | 83 // The test fixture is responsible for: |
84 // - Making sure each test has an IO loop running | 84 // - Making sure each test has an IO loop running |
85 // - Catching any host resolve requests and mapping them to localhost | 85 // - Catching any host resolve requests and mapping them to localhost |
86 // (so the test doesn't use any external network dependencies). | 86 // (so the test doesn't use any external network dependencies). |
87 class ConnectionTesterTest : public PlatformTest { | 87 class ConnectionTesterTest : public PlatformTest { |
88 public: | 88 public: |
89 ConnectionTesterTest() | 89 ConnectionTesterTest() |
90 : message_loop_(MessageLoop::TYPE_IO), | 90 : message_loop_(base::MessageLoop::TYPE_IO), |
91 io_thread_(BrowserThread::IO, &message_loop_), | 91 io_thread_(BrowserThread::IO, &message_loop_), |
92 test_server_(net::SpawnedTestServer::TYPE_HTTP, | 92 test_server_(net::SpawnedTestServer::TYPE_HTTP, |
93 net::SpawnedTestServer::kLocalhost, | 93 net::SpawnedTestServer::kLocalhost, |
94 // Nothing is read in this directory. | 94 // Nothing is read in this directory. |
95 base::FilePath(FILE_PATH_LITERAL("chrome"))), | 95 base::FilePath(FILE_PATH_LITERAL("chrome"))), |
96 proxy_script_fetcher_context_(new net::URLRequestContext) { | 96 proxy_script_fetcher_context_(new net::URLRequestContext) { |
97 InitializeRequestContext(); | 97 InitializeRequestContext(); |
98 } | 98 } |
99 | 99 |
100 protected: | 100 protected: |
101 // Destroy last the MessageLoop last to give a chance for objects like | 101 // Destroy last the MessageLoop last to give a chance for objects like |
102 // ObserverListThreadSave to shut down properly. For example, | 102 // ObserverListThreadSave to shut down properly. For example, |
103 // SSLClientAuthCache calls RemoveObserver when destroyed, but if the | 103 // SSLClientAuthCache calls RemoveObserver when destroyed, but if the |
104 // MessageLoop is already destroyed, then the RemoveObserver will be a | 104 // MessageLoop is already destroyed, then the RemoveObserver will be a |
105 // no-op, and the ObserverList will contain invalid entries. | 105 // no-op, and the ObserverList will contain invalid entries. |
106 MessageLoop message_loop_; | 106 base::MessageLoop message_loop_; |
107 content::TestBrowserThread io_thread_; | 107 content::TestBrowserThread io_thread_; |
108 net::SpawnedTestServer test_server_; | 108 net::SpawnedTestServer test_server_; |
109 ConnectionTesterDelegate test_delegate_; | 109 ConnectionTesterDelegate test_delegate_; |
110 net::MockHostResolver host_resolver_; | 110 net::MockHostResolver host_resolver_; |
111 scoped_ptr<net::CertVerifier> cert_verifier_; | 111 scoped_ptr<net::CertVerifier> cert_verifier_; |
112 scoped_ptr<net::ProxyService> proxy_service_; | 112 scoped_ptr<net::ProxyService> proxy_service_; |
113 scoped_refptr<net::SSLConfigService> ssl_config_service_; | 113 scoped_refptr<net::SSLConfigService> ssl_config_service_; |
114 scoped_ptr<net::HttpTransactionFactory> http_transaction_factory_; | 114 scoped_ptr<net::HttpTransactionFactory> http_transaction_factory_; |
115 net::HttpAuthHandlerRegistryFactory http_auth_handler_factory_; | 115 net::HttpAuthHandlerRegistryFactory http_auth_handler_factory_; |
116 net::HttpServerPropertiesImpl http_server_properties_impl_; | 116 net::HttpServerPropertiesImpl http_server_properties_impl_; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 150 |
151 ConnectionTester tester(&test_delegate_, | 151 ConnectionTester tester(&test_delegate_, |
152 proxy_script_fetcher_context_.get(), | 152 proxy_script_fetcher_context_.get(), |
153 NULL); | 153 NULL); |
154 | 154 |
155 // Start the test suite on URL "echoall". | 155 // Start the test suite on URL "echoall". |
156 // TODO(eroman): Is this URL right? | 156 // TODO(eroman): Is this URL right? |
157 tester.RunAllTests(test_server_.GetURL("echoall")); | 157 tester.RunAllTests(test_server_.GetURL("echoall")); |
158 | 158 |
159 // Wait for all the tests to complete. | 159 // Wait for all the tests to complete. |
160 MessageLoop::current()->Run(); | 160 base::MessageLoop::current()->Run(); |
161 | 161 |
162 const int kNumExperiments = | 162 const int kNumExperiments = |
163 ConnectionTester::PROXY_EXPERIMENT_COUNT * | 163 ConnectionTester::PROXY_EXPERIMENT_COUNT * |
164 ConnectionTester::HOST_RESOLVER_EXPERIMENT_COUNT; | 164 ConnectionTester::HOST_RESOLVER_EXPERIMENT_COUNT; |
165 | 165 |
166 EXPECT_EQ(1, test_delegate_.start_connection_test_suite_count()); | 166 EXPECT_EQ(1, test_delegate_.start_connection_test_suite_count()); |
167 EXPECT_EQ(kNumExperiments, | 167 EXPECT_EQ(kNumExperiments, |
168 test_delegate_.start_connection_test_experiment_count()); | 168 test_delegate_.start_connection_test_experiment_count()); |
169 EXPECT_EQ(kNumExperiments, | 169 EXPECT_EQ(kNumExperiments, |
170 test_delegate_.completed_connection_test_experiment_count()); | 170 test_delegate_.completed_connection_test_experiment_count()); |
(...skipping 25 matching lines...) Expand all Loading... |
196 tester.reset(); | 196 tester.reset(); |
197 | 197 |
198 // Drain the tasks on the message loop. | 198 // Drain the tasks on the message loop. |
199 // | 199 // |
200 // Note that we cannot simply stop the message loop, since that will delete | 200 // Note that we cannot simply stop the message loop, since that will delete |
201 // any pending tasks instead of running them. This causes a problem with | 201 // any pending tasks instead of running them. This causes a problem with |
202 // net::ClientSocketPoolBaseHelper, since the "Group" holds a pointer | 202 // net::ClientSocketPoolBaseHelper, since the "Group" holds a pointer |
203 // |backup_task| that it will try to deref during the destructor, but | 203 // |backup_task| that it will try to deref during the destructor, but |
204 // depending on the order that pending tasks were deleted in, it might | 204 // depending on the order that pending tasks were deleted in, it might |
205 // already be invalid! See http://crbug.com/43291. | 205 // already be invalid! See http://crbug.com/43291. |
206 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 206 base::MessageLoop::current()->PostTask(FROM_HERE, |
207 MessageLoop::current()->Run(); | 207 base::MessageLoop::QuitClosure()); |
| 208 base::MessageLoop::current()->Run(); |
208 } | 209 } |
209 | 210 |
210 } // namespace | 211 } // namespace |
OLD | NEW |