| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/location.h" | 6 #include "base/location.h" |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/service/cloud_print/cloud_print_url_fetcher.h" | 13 #include "chrome/service/cloud_print/cloud_print_url_fetcher.h" |
| 14 #include "chrome/service/service_process.h" | 14 #include "chrome/service/service_process.h" |
| 15 #include "net/test/spawned_test_server/spawned_test_server.h" | 15 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 16 #include "net/url_request/url_request_context_getter.h" | 16 #include "net/url_request/url_request_context_getter.h" |
| 17 #include "net/url_request/url_request_status.h" | 17 #include "net/url_request/url_request_status.h" |
| 18 #include "net/url_request/url_request_test_util.h" | 18 #include "net/url_request/url_request_test_util.h" |
| 19 #include "net/url_request/url_request_throttler_manager.h" | 19 #include "net/url_request/url_request_throttler_manager.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 22 | 22 |
| 23 using base::Time; | 23 using base::Time; |
| 24 using base::TimeDelta; | 24 using base::TimeDelta; |
| 25 | 25 |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 } | 323 } |
| 324 | 324 |
| 325 void CloudPrintURLFetcherRetryBackoffTest::OnRequestGiveUp() { | 325 void CloudPrintURLFetcherRetryBackoffTest::OnRequestGiveUp() { |
| 326 // It takes more than 200 ms to finish all 11 requests. | 326 // It takes more than 200 ms to finish all 11 requests. |
| 327 EXPECT_TRUE(Time::Now() - start_time_ >= TimeDelta::FromMilliseconds(200)); | 327 EXPECT_TRUE(Time::Now() - start_time_ >= TimeDelta::FromMilliseconds(200)); |
| 328 io_task_runner()->PostTask(FROM_HERE, | 328 io_task_runner()->PostTask(FROM_HERE, |
| 329 base::MessageLoop::QuitWhenIdleClosure()); | 329 base::MessageLoop::QuitWhenIdleClosure()); |
| 330 } | 330 } |
| 331 | 331 |
| 332 TEST_F(CloudPrintURLFetcherBasicTest, HandleRawResponse) { | 332 TEST_F(CloudPrintURLFetcherBasicTest, HandleRawResponse) { |
| 333 net::SpawnedTestServer test_server(net::SpawnedTestServer::TYPE_HTTP, | 333 net::EmbeddedTestServer test_server; |
| 334 net::SpawnedTestServer::kLocalhost, | 334 test_server.AddDefaultHandlers(base::FilePath(kDocRoot)); |
| 335 base::FilePath(kDocRoot)); | |
| 336 ASSERT_TRUE(test_server.Start()); | 335 ASSERT_TRUE(test_server.Start()); |
| 337 SetHandleRawResponse(true); | 336 SetHandleRawResponse(true); |
| 338 | 337 |
| 339 CreateFetcher(test_server.GetURL("echo"), 0); | 338 CreateFetcher(test_server.GetURL("/echo"), 0); |
| 340 base::MessageLoop::current()->Run(); | 339 base::MessageLoop::current()->Run(); |
| 341 } | 340 } |
| 342 | 341 |
| 343 TEST_F(CloudPrintURLFetcherBasicTest, HandleRawData) { | 342 TEST_F(CloudPrintURLFetcherBasicTest, HandleRawData) { |
| 344 net::SpawnedTestServer test_server(net::SpawnedTestServer::TYPE_HTTP, | 343 net::EmbeddedTestServer test_server; |
| 345 net::SpawnedTestServer::kLocalhost, | 344 test_server.AddDefaultHandlers(base::FilePath(kDocRoot)); |
| 346 base::FilePath(kDocRoot)); | |
| 347 ASSERT_TRUE(test_server.Start()); | 345 ASSERT_TRUE(test_server.Start()); |
| 348 | 346 |
| 349 SetHandleRawData(true); | 347 SetHandleRawData(true); |
| 350 CreateFetcher(test_server.GetURL("echo"), 0); | 348 CreateFetcher(test_server.GetURL("/echo"), 0); |
| 351 base::MessageLoop::current()->Run(); | 349 base::MessageLoop::current()->Run(); |
| 352 } | 350 } |
| 353 | 351 |
| 354 TEST_F(CloudPrintURLFetcherOverloadTest, Protect) { | 352 TEST_F(CloudPrintURLFetcherOverloadTest, Protect) { |
| 355 net::SpawnedTestServer test_server(net::SpawnedTestServer::TYPE_HTTP, | 353 net::EmbeddedTestServer test_server; |
| 356 net::SpawnedTestServer::kLocalhost, | 354 test_server.AddDefaultHandlers(base::FilePath(kDocRoot)); |
| 357 base::FilePath(kDocRoot)); | |
| 358 ASSERT_TRUE(test_server.Start()); | 355 ASSERT_TRUE(test_server.Start()); |
| 359 | 356 |
| 360 GURL url(test_server.GetURL("defaultresponse")); | 357 GURL url(test_server.GetURL("/defaultresponse")); |
| 361 CreateFetcher(url, 11); | 358 CreateFetcher(url, 11); |
| 362 | 359 |
| 363 base::MessageLoop::current()->Run(); | 360 base::MessageLoop::current()->Run(); |
| 364 } | 361 } |
| 365 | 362 |
| 366 TEST_F(CloudPrintURLFetcherRetryBackoffTest, GiveUp) { | 363 TEST_F(CloudPrintURLFetcherRetryBackoffTest, GiveUp) { |
| 367 net::SpawnedTestServer test_server(net::SpawnedTestServer::TYPE_HTTP, | 364 net::EmbeddedTestServer test_server; |
| 368 net::SpawnedTestServer::kLocalhost, | 365 test_server.AddDefaultHandlers(base::FilePath(kDocRoot)); |
| 369 base::FilePath(kDocRoot)); | |
| 370 ASSERT_TRUE(test_server.Start()); | 366 ASSERT_TRUE(test_server.Start()); |
| 371 | 367 |
| 372 GURL url(test_server.GetURL("defaultresponse")); | 368 GURL url(test_server.GetURL("/defaultresponse")); |
| 373 CreateFetcher(url, 11); | 369 CreateFetcher(url, 11); |
| 374 | 370 |
| 375 base::MessageLoop::current()->Run(); | 371 base::MessageLoop::current()->Run(); |
| 376 } | 372 } |
| 377 | 373 |
| 378 } // namespace cloud_print | 374 } // namespace cloud_print |
| OLD | NEW |