| 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/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
| 7 #include "base/message_loop_proxy.h" | 7 #include "base/message_loop_proxy.h" |
| 8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
| 9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/service/cloud_print/cloud_print_url_fetcher.h" | 11 #include "chrome/service/cloud_print/cloud_print_url_fetcher.h" |
| 12 #include "chrome/service/service_process.h" | 12 #include "chrome/service/service_process.h" |
| 13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 14 #include "net/test/test_server.h" | 14 #include "net/test/test_server.h" |
| 15 #include "net/url_request/url_request_context_getter.h" | 15 #include "net/url_request/url_request_context_getter.h" |
| 16 #include "net/url_request/url_request_status.h" | 16 #include "net/url_request/url_request_status.h" |
| 17 #include "net/url_request/url_request_test_util.h" | 17 #include "net/url_request/url_request_test_util.h" |
| 18 #include "net/url_request/url_request_throttler_manager.h" | 18 #include "net/url_request/url_request_throttler_manager.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 using base::Time; | 21 using base::Time; |
| 22 using base::TimeDelta; | 22 using base::TimeDelta; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); | 26 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); |
| 27 | 27 |
| 28 int g_request_context_getter_instances = 0; | 28 int g_request_context_getter_instances = 0; |
| 29 class TrackingTestURLRequestContextGetter | 29 class TrackingTestURLRequestContextGetter |
| 30 : public net::TestURLRequestContextGetter { | 30 : public TestURLRequestContextGetter { |
| 31 public: | 31 public: |
| 32 explicit TrackingTestURLRequestContextGetter( | 32 explicit TrackingTestURLRequestContextGetter( |
| 33 base::MessageLoopProxy* io_message_loop_proxy, | 33 base::MessageLoopProxy* io_message_loop_proxy, |
| 34 net::URLRequestThrottlerManager* throttler_manager) | 34 net::URLRequestThrottlerManager* throttler_manager) |
| 35 : TestURLRequestContextGetter(io_message_loop_proxy), | 35 : TestURLRequestContextGetter(io_message_loop_proxy), |
| 36 throttler_manager_(throttler_manager), | 36 throttler_manager_(throttler_manager), |
| 37 context_(NULL) { | 37 context_(NULL) { |
| 38 g_request_context_getter_instances++; | 38 g_request_context_getter_instances++; |
| 39 } | 39 } |
| 40 | 40 |
| 41 virtual net::TestURLRequestContext* GetURLRequestContext() OVERRIDE { | 41 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE { |
| 42 if (!context_.get()) { | 42 if (!context_.get()) { |
| 43 context_.reset(new net::TestURLRequestContext(true)); | 43 context_.reset(new TestURLRequestContext(true)); |
| 44 context_->set_throttler_manager(throttler_manager_); | 44 context_->set_throttler_manager(throttler_manager_); |
| 45 context_->Init(); | 45 context_->Init(); |
| 46 } | 46 } |
| 47 return context_.get(); | 47 return context_.get(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 protected: | 50 protected: |
| 51 virtual ~TrackingTestURLRequestContextGetter() { | 51 virtual ~TrackingTestURLRequestContextGetter() { |
| 52 g_request_context_getter_instances--; | 52 g_request_context_getter_instances--; |
| 53 } | 53 } |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 // Not owned here. | 56 // Not owned here. |
| 57 net::URLRequestThrottlerManager* throttler_manager_; | 57 net::URLRequestThrottlerManager* throttler_manager_; |
| 58 scoped_ptr<net::TestURLRequestContext> context_; | 58 scoped_ptr<TestURLRequestContext> context_; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 class TestCloudPrintURLFetcher : public CloudPrintURLFetcher { | 61 class TestCloudPrintURLFetcher : public CloudPrintURLFetcher { |
| 62 public: | 62 public: |
| 63 explicit TestCloudPrintURLFetcher( | 63 explicit TestCloudPrintURLFetcher( |
| 64 base::MessageLoopProxy* io_message_loop_proxy) | 64 base::MessageLoopProxy* io_message_loop_proxy) |
| 65 : io_message_loop_proxy_(io_message_loop_proxy) { | 65 : io_message_loop_proxy_(io_message_loop_proxy) { |
| 66 } | 66 } |
| 67 | 67 |
| 68 virtual net::URLRequestContextGetter* GetRequestContextGetter() { | 68 virtual net::URLRequestContextGetter* GetRequestContextGetter() { |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 FilePath(kDocRoot)); | 369 FilePath(kDocRoot)); |
| 370 ASSERT_TRUE(test_server.Start()); | 370 ASSERT_TRUE(test_server.Start()); |
| 371 | 371 |
| 372 GURL url(test_server.GetURL("defaultresponse")); | 372 GURL url(test_server.GetURL("defaultresponse")); |
| 373 CreateFetcher(url, 11); | 373 CreateFetcher(url, 11); |
| 374 | 374 |
| 375 MessageLoop::current()->Run(); | 375 MessageLoop::current()->Run(); |
| 376 } | 376 } |
| 377 | 377 |
| 378 } // namespace. | 378 } // namespace. |
| OLD | NEW |