| 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 TestURLRequestContextGetter : public net::URLRequestContextGetter { | 29 class TrackingTestURLRequestContextGetter |
| 30 : public TestURLRequestContextGetter { |
| 30 public: | 31 public: |
| 31 explicit TestURLRequestContextGetter( | 32 explicit TrackingTestURLRequestContextGetter( |
| 32 base::MessageLoopProxy* io_message_loop_proxy) | 33 base::MessageLoopProxy* io_message_loop_proxy) |
| 33 : io_message_loop_proxy_(io_message_loop_proxy) { | 34 : TestURLRequestContextGetter(io_message_loop_proxy) { |
| 34 g_request_context_getter_instances++; | 35 g_request_context_getter_instances++; |
| 35 } | 36 } |
| 36 virtual net::URLRequestContext* GetURLRequestContext() { | |
| 37 if (!context_) | |
| 38 context_ = new TestURLRequestContext(); | |
| 39 return context_; | |
| 40 } | |
| 41 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { | |
| 42 return io_message_loop_proxy_; | |
| 43 } | |
| 44 | |
| 45 protected: | 37 protected: |
| 46 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | 38 virtual ~TrackingTestURLRequestContextGetter() { |
| 47 | |
| 48 private: | |
| 49 virtual ~TestURLRequestContextGetter() { | |
| 50 g_request_context_getter_instances--; | 39 g_request_context_getter_instances--; |
| 51 } | 40 } |
| 52 | |
| 53 scoped_refptr<net::URLRequestContext> context_; | |
| 54 }; | 41 }; |
| 55 | 42 |
| 56 class TestCloudPrintURLFetcher : public CloudPrintURLFetcher { | 43 class TestCloudPrintURLFetcher : public CloudPrintURLFetcher { |
| 57 public: | 44 public: |
| 58 explicit TestCloudPrintURLFetcher( | 45 explicit TestCloudPrintURLFetcher( |
| 59 base::MessageLoopProxy* io_message_loop_proxy) | 46 base::MessageLoopProxy* io_message_loop_proxy) |
| 60 : io_message_loop_proxy_(io_message_loop_proxy) { | 47 : io_message_loop_proxy_(io_message_loop_proxy) { |
| 61 } | 48 } |
| 62 | 49 |
| 63 virtual net::URLRequestContextGetter* GetRequestContextGetter() { | 50 virtual net::URLRequestContextGetter* GetRequestContextGetter() { |
| 64 return new TestURLRequestContextGetter(io_message_loop_proxy_.get()); | 51 return new TrackingTestURLRequestContextGetter( |
| 52 io_message_loop_proxy_.get()); |
| 65 } | 53 } |
| 66 private: | 54 private: |
| 67 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | 55 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
| 68 }; | 56 }; |
| 69 | 57 |
| 70 class CloudPrintURLFetcherTest : public testing::Test, | 58 class CloudPrintURLFetcherTest : public testing::Test, |
| 71 public CloudPrintURLFetcherDelegate { | 59 public CloudPrintURLFetcherDelegate { |
| 72 public: | 60 public: |
| 73 CloudPrintURLFetcherTest() : max_retries_(0), fetcher_(NULL) { } | 61 CloudPrintURLFetcherTest() : max_retries_(0), fetcher_(NULL) { } |
| 74 | 62 |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 manager->OverrideEntryForTests(url, entry); | 356 manager->OverrideEntryForTests(url, entry); |
| 369 | 357 |
| 370 CreateFetcher(url, 11); | 358 CreateFetcher(url, 11); |
| 371 | 359 |
| 372 MessageLoop::current()->Run(); | 360 MessageLoop::current()->Run(); |
| 373 | 361 |
| 374 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url); | 362 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url); |
| 375 } | 363 } |
| 376 | 364 |
| 377 } // namespace. | 365 } // namespace. |
| OLD | NEW |