| 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 "chrome/test/base/testing_pref_service.h" | 7 #include "chrome/test/base/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/base/mock_cert_verifier.h" | 9 #include "net/base/mock_cert_verifier.h" |
| 10 #include "net/base/mock_host_resolver.h" | 10 #include "net/base/mock_host_resolver.h" |
| 11 #include "net/base/ssl_config_service_defaults.h" | 11 #include "net/base/ssl_config_service_defaults.h" |
| 12 #include "net/cookies/cookie_monster.h" | 12 #include "net/cookies/cookie_monster.h" |
| 13 #include "net/ftp/ftp_network_layer.h" | 13 #include "net/ftp/ftp_network_layer.h" |
| 14 #include "net/http/http_auth_handler_factory.h" | 14 #include "net/http/http_auth_handler_factory.h" |
| 15 #include "net/http/http_network_layer.h" | 15 #include "net/http/http_network_layer.h" |
| 16 #include "net/http/http_network_session.h" | 16 #include "net/http/http_network_session.h" |
| 17 #include "net/http/http_server_properties_impl.h" | 17 #include "net/http/http_server_properties_impl.h" |
| 18 #include "net/proxy/proxy_config_service_fixed.h" | 18 #include "net/proxy/proxy_config_service_fixed.h" |
| 19 #include "net/proxy/proxy_service.h" | 19 #include "net/proxy/proxy_service.h" |
| 20 #include "net/test/test_server.h" | 20 #include "net/test/test_server.h" |
| 21 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "testing/platform_test.h" | 23 #include "testing/platform_test.h" |
| 24 #include "v8/include/v8.h" |
| 24 | 25 |
| 25 using content::BrowserThread; | 26 using content::BrowserThread; |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 // This is a testing delegate which simply counts how many times each of | 30 // This is a testing delegate which simply counts how many times each of |
| 30 // the delegate's methods were invoked. | 31 // the delegate's methods were invoked. |
| 31 class ConnectionTesterDelegate : public ConnectionTester::Delegate { | 32 class ConnectionTesterDelegate : public ConnectionTester::Delegate { |
| 32 public: | 33 public: |
| 33 ConnectionTesterDelegate() | 34 ConnectionTesterDelegate() |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 proxy_script_fetcher_context_->set_cookie_store( | 144 proxy_script_fetcher_context_->set_cookie_store( |
| 144 new net::CookieMonster(NULL, NULL)); | 145 new net::CookieMonster(NULL, NULL)); |
| 145 } | 146 } |
| 146 }; | 147 }; |
| 147 | 148 |
| 148 TEST_F(ConnectionTesterTest, RunAllTests) { | 149 TEST_F(ConnectionTesterTest, RunAllTests) { |
| 149 ASSERT_TRUE(test_server_.Start()); | 150 ASSERT_TRUE(test_server_.Start()); |
| 150 | 151 |
| 151 ConnectionTester tester(&test_delegate_, | 152 ConnectionTester tester(&test_delegate_, |
| 152 proxy_script_fetcher_context_.get(), | 153 proxy_script_fetcher_context_.get(), |
| 153 NULL); | 154 NULL, |
| 155 v8::Isolate::GetCurrent()); |
| 154 | 156 |
| 155 // Start the test suite on URL "echoall". | 157 // Start the test suite on URL "echoall". |
| 156 // TODO(eroman): Is this URL right? | 158 // TODO(eroman): Is this URL right? |
| 157 tester.RunAllTests(test_server_.GetURL("echoall")); | 159 tester.RunAllTests(test_server_.GetURL("echoall")); |
| 158 | 160 |
| 159 // Wait for all the tests to complete. | 161 // Wait for all the tests to complete. |
| 160 MessageLoop::current()->Run(); | 162 MessageLoop::current()->Run(); |
| 161 | 163 |
| 162 const int kNumExperiments = | 164 const int kNumExperiments = |
| 163 ConnectionTester::PROXY_EXPERIMENT_COUNT * | 165 ConnectionTester::PROXY_EXPERIMENT_COUNT * |
| 164 ConnectionTester::HOST_RESOLVER_EXPERIMENT_COUNT; | 166 ConnectionTester::HOST_RESOLVER_EXPERIMENT_COUNT; |
| 165 | 167 |
| 166 EXPECT_EQ(1, test_delegate_.start_connection_test_suite_count()); | 168 EXPECT_EQ(1, test_delegate_.start_connection_test_suite_count()); |
| 167 EXPECT_EQ(kNumExperiments, | 169 EXPECT_EQ(kNumExperiments, |
| 168 test_delegate_.start_connection_test_experiment_count()); | 170 test_delegate_.start_connection_test_experiment_count()); |
| 169 EXPECT_EQ(kNumExperiments, | 171 EXPECT_EQ(kNumExperiments, |
| 170 test_delegate_.completed_connection_test_experiment_count()); | 172 test_delegate_.completed_connection_test_experiment_count()); |
| 171 EXPECT_EQ(1, test_delegate_.completed_connection_test_suite_count()); | 173 EXPECT_EQ(1, test_delegate_.completed_connection_test_suite_count()); |
| 172 } | 174 } |
| 173 | 175 |
| 174 TEST_F(ConnectionTesterTest, DeleteWhileInProgress) { | 176 TEST_F(ConnectionTesterTest, DeleteWhileInProgress) { |
| 175 ASSERT_TRUE(test_server_.Start()); | 177 ASSERT_TRUE(test_server_.Start()); |
| 176 | 178 |
| 177 scoped_ptr<ConnectionTester> tester( | 179 scoped_ptr<ConnectionTester> tester( |
| 178 new ConnectionTester(&test_delegate_, | 180 new ConnectionTester(&test_delegate_, |
| 179 proxy_script_fetcher_context_.get(), | 181 proxy_script_fetcher_context_.get(), |
| 180 NULL)); | 182 NULL, |
| 183 v8::Isolate::GetCurrent())); |
| 181 | 184 |
| 182 // Start the test suite on URL "echoall". | 185 // Start the test suite on URL "echoall". |
| 183 // TODO(eroman): Is this URL right? | 186 // TODO(eroman): Is this URL right? |
| 184 tester->RunAllTests(test_server_.GetURL("echoall")); | 187 tester->RunAllTests(test_server_.GetURL("echoall")); |
| 185 | 188 |
| 186 // Don't run the message loop at all. Otherwise the experiment's request may | 189 // Don't run the message loop at all. Otherwise the experiment's request may |
| 187 // complete and post a task to run the next experiment before we quit the | 190 // complete and post a task to run the next experiment before we quit the |
| 188 // message loop. | 191 // message loop. |
| 189 | 192 |
| 190 EXPECT_EQ(1, test_delegate_.start_connection_test_suite_count()); | 193 EXPECT_EQ(1, test_delegate_.start_connection_test_suite_count()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 201 // any pending tasks instead of running them. This causes a problem with | 204 // any pending tasks instead of running them. This causes a problem with |
| 202 // net::ClientSocketPoolBaseHelper, since the "Group" holds a pointer | 205 // net::ClientSocketPoolBaseHelper, since the "Group" holds a pointer |
| 203 // |backup_task| that it will try to deref during the destructor, but | 206 // |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 | 207 // depending on the order that pending tasks were deleted in, it might |
| 205 // already be invalid! See http://crbug.com/43291. | 208 // already be invalid! See http://crbug.com/43291. |
| 206 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 209 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 207 MessageLoop::current()->Run(); | 210 MessageLoop::current()->Run(); |
| 208 } | 211 } |
| 209 | 212 |
| 210 } // namespace | 213 } // namespace |
| OLD | NEW |