| 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 "net/proxy/dhcp_proxy_script_adapter_fetcher_win.h" | 5 #include "net/proxy/dhcp_proxy_script_adapter_fetcher_win.h" |
| 6 | 6 |
| 7 #include "base/run_loop.h" |
| 7 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
| 8 #include "base/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
| 9 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
| 10 #include "base/timer/elapsed_timer.h" | 11 #include "base/timer/elapsed_timer.h" |
| 11 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 12 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 13 #include "net/base/test_completion_callback.h" | 14 #include "net/base/test_completion_callback.h" |
| 14 #include "net/proxy/mock_proxy_script_fetcher.h" | 15 #include "net/proxy/mock_proxy_script_fetcher.h" |
| 15 #include "net/proxy/proxy_script_fetcher_impl.h" | 16 #include "net/proxy/proxy_script_fetcher_impl.h" |
| 16 #include "net/test/embedded_test_server/embedded_test_server.h" | 17 #include "net/test/embedded_test_server/embedded_test_server.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 void WaitForResult(int expected_error) { | 153 void WaitForResult(int expected_error) { |
| 153 EXPECT_EQ(expected_error, callback_.WaitForResult()); | 154 EXPECT_EQ(expected_error, callback_.WaitForResult()); |
| 154 } | 155 } |
| 155 | 156 |
| 156 void RunTest() { | 157 void RunTest() { |
| 157 fetcher_->Fetch("adapter name", callback_.callback()); | 158 fetcher_->Fetch("adapter name", callback_.callback()); |
| 158 } | 159 } |
| 159 | 160 |
| 160 void FinishTestAllowCleanup() { | 161 void FinishTestAllowCleanup() { |
| 161 fetcher_->FinishTest(); | 162 fetcher_->FinishTest(); |
| 162 base::MessageLoop::current()->RunUntilIdle(); | 163 base::RunLoop().RunUntilIdle(); |
| 163 } | 164 } |
| 164 | 165 |
| 165 TestCompletionCallback callback_; | 166 TestCompletionCallback callback_; |
| 166 std::unique_ptr<URLRequestContext> url_request_context_; | 167 std::unique_ptr<URLRequestContext> url_request_context_; |
| 167 scoped_refptr<base::SequencedWorkerPool> worker_pool_; | 168 scoped_refptr<base::SequencedWorkerPool> worker_pool_; |
| 168 std::unique_ptr<MockDhcpProxyScriptAdapterFetcher> fetcher_; | 169 std::unique_ptr<MockDhcpProxyScriptAdapterFetcher> fetcher_; |
| 169 base::string16 pac_text_; | 170 base::string16 pac_text_; |
| 170 }; | 171 }; |
| 171 | 172 |
| 172 TEST(DhcpProxyScriptAdapterFetcher, NormalCaseURLNotInDhcp) { | 173 TEST(DhcpProxyScriptAdapterFetcher, NormalCaseURLNotInDhcp) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 EXPECT_EQ(ERR_TIMED_OUT, client.fetcher_->GetResult()); | 211 EXPECT_EQ(ERR_TIMED_OUT, client.fetcher_->GetResult()); |
| 211 EXPECT_EQ(base::string16(L""), client.fetcher_->GetPacScript()); | 212 EXPECT_EQ(base::string16(L""), client.fetcher_->GetPacScript()); |
| 212 EXPECT_EQ(GURL(), client.fetcher_->GetPacURL()); | 213 EXPECT_EQ(GURL(), client.fetcher_->GetPacURL()); |
| 213 client.FinishTestAllowCleanup(); | 214 client.FinishTestAllowCleanup(); |
| 214 } | 215 } |
| 215 | 216 |
| 216 TEST(DhcpProxyScriptAdapterFetcher, CancelWhileDhcp) { | 217 TEST(DhcpProxyScriptAdapterFetcher, CancelWhileDhcp) { |
| 217 FetcherClient client; | 218 FetcherClient client; |
| 218 client.RunTest(); | 219 client.RunTest(); |
| 219 client.fetcher_->Cancel(); | 220 client.fetcher_->Cancel(); |
| 220 base::MessageLoop::current()->RunUntilIdle(); | 221 base::RunLoop().RunUntilIdle(); |
| 221 ASSERT_FALSE(client.fetcher_->DidFinish()); | 222 ASSERT_FALSE(client.fetcher_->DidFinish()); |
| 222 ASSERT_TRUE(client.fetcher_->WasCancelled()); | 223 ASSERT_TRUE(client.fetcher_->WasCancelled()); |
| 223 EXPECT_EQ(ERR_ABORTED, client.fetcher_->GetResult()); | 224 EXPECT_EQ(ERR_ABORTED, client.fetcher_->GetResult()); |
| 224 EXPECT_EQ(base::string16(L""), client.fetcher_->GetPacScript()); | 225 EXPECT_EQ(base::string16(L""), client.fetcher_->GetPacScript()); |
| 225 EXPECT_EQ(GURL(), client.fetcher_->GetPacURL()); | 226 EXPECT_EQ(GURL(), client.fetcher_->GetPacURL()); |
| 226 client.FinishTestAllowCleanup(); | 227 client.FinishTestAllowCleanup(); |
| 227 } | 228 } |
| 228 | 229 |
| 229 TEST(DhcpProxyScriptAdapterFetcher, CancelWhileFetcher) { | 230 TEST(DhcpProxyScriptAdapterFetcher, CancelWhileFetcher) { |
| 230 FetcherClient client; | 231 FetcherClient client; |
| 231 // This causes the mock fetcher not to pretend the | 232 // This causes the mock fetcher not to pretend the |
| 232 // fetcher finishes after a timeout. | 233 // fetcher finishes after a timeout. |
| 233 client.fetcher_->fetcher_delay_ms_ = -1; | 234 client.fetcher_->fetcher_delay_ms_ = -1; |
| 234 client.RunTest(); | 235 client.RunTest(); |
| 235 int max_loops = 4; | 236 int max_loops = 4; |
| 236 while (!client.fetcher_->IsWaitingForFetcher() && max_loops--) { | 237 while (!client.fetcher_->IsWaitingForFetcher() && max_loops--) { |
| 237 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); | 238 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); |
| 238 base::MessageLoop::current()->RunUntilIdle(); | 239 base::RunLoop().RunUntilIdle(); |
| 239 } | 240 } |
| 240 client.fetcher_->Cancel(); | 241 client.fetcher_->Cancel(); |
| 241 base::MessageLoop::current()->RunUntilIdle(); | 242 base::RunLoop().RunUntilIdle(); |
| 242 ASSERT_FALSE(client.fetcher_->DidFinish()); | 243 ASSERT_FALSE(client.fetcher_->DidFinish()); |
| 243 ASSERT_TRUE(client.fetcher_->WasCancelled()); | 244 ASSERT_TRUE(client.fetcher_->WasCancelled()); |
| 244 EXPECT_EQ(ERR_ABORTED, client.fetcher_->GetResult()); | 245 EXPECT_EQ(ERR_ABORTED, client.fetcher_->GetResult()); |
| 245 EXPECT_EQ(base::string16(L""), client.fetcher_->GetPacScript()); | 246 EXPECT_EQ(base::string16(L""), client.fetcher_->GetPacScript()); |
| 246 // GetPacURL() still returns the URL fetched in this case. | 247 // GetPacURL() still returns the URL fetched in this case. |
| 247 EXPECT_EQ(GURL(kPacUrl), client.fetcher_->GetPacURL()); | 248 EXPECT_EQ(GURL(kPacUrl), client.fetcher_->GetPacURL()); |
| 248 client.FinishTestAllowCleanup(); | 249 client.FinishTestAllowCleanup(); |
| 249 } | 250 } |
| 250 | 251 |
| 251 TEST(DhcpProxyScriptAdapterFetcher, CancelAtCompletion) { | 252 TEST(DhcpProxyScriptAdapterFetcher, CancelAtCompletion) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 EXPECT_EQ(BASE_URL, | 330 EXPECT_EQ(BASE_URL, |
| 330 DhcpProxyScriptAdapterFetcher::SanitizeDhcpApiString( | 331 DhcpProxyScriptAdapterFetcher::SanitizeDhcpApiString( |
| 331 BASE_URL "\0foo\0blat", kBaseUrlLen + 9)); | 332 BASE_URL "\0foo\0blat", kBaseUrlLen + 9)); |
| 332 } | 333 } |
| 333 | 334 |
| 334 #undef BASE_URL | 335 #undef BASE_URL |
| 335 | 336 |
| 336 } // namespace | 337 } // namespace |
| 337 | 338 |
| 338 } // namespace net | 339 } // namespace net |
| OLD | NEW |