| 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/message_loop_proxy.h" | 7 #include "base/message_loop/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" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 : public net::TestURLRequestContextGetter { | 31 : public net::TestURLRequestContextGetter { |
| 32 public: | 32 public: |
| 33 explicit TrackingTestURLRequestContextGetter( | 33 explicit TrackingTestURLRequestContextGetter( |
| 34 base::MessageLoopProxy* io_message_loop_proxy, | 34 base::MessageLoopProxy* io_message_loop_proxy, |
| 35 net::URLRequestThrottlerManager* throttler_manager) | 35 net::URLRequestThrottlerManager* throttler_manager) |
| 36 : TestURLRequestContextGetter(io_message_loop_proxy), | 36 : TestURLRequestContextGetter(io_message_loop_proxy), |
| 37 throttler_manager_(throttler_manager) { | 37 throttler_manager_(throttler_manager) { |
| 38 g_request_context_getter_instances++; | 38 g_request_context_getter_instances++; |
| 39 } | 39 } |
| 40 | 40 |
| 41 virtual net::TestURLRequestContext* GetURLRequestContext() OVERRIDE { | 41 virtual net::TestURLRequestContext* GetURLRequestContext() override { |
| 42 if (!context_.get()) { | 42 if (!context_.get()) { |
| 43 context_.reset(new net::TestURLRequestContext(true)); | 43 context_.reset(new net::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<net::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() OVERRIDE { | 68 virtual net::URLRequestContextGetter* GetRequestContextGetter() override { |
| 69 return new TrackingTestURLRequestContextGetter( | 69 return new TrackingTestURLRequestContextGetter( |
| 70 io_message_loop_proxy_.get(), throttler_manager()); | 70 io_message_loop_proxy_.get(), throttler_manager()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 net::URLRequestThrottlerManager* throttler_manager() { | 73 net::URLRequestThrottlerManager* throttler_manager() { |
| 74 return &throttler_manager_; | 74 return &throttler_manager_; |
| 75 } | 75 } |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 virtual ~TestCloudPrintURLFetcher() {} | 78 virtual ~TestCloudPrintURLFetcher() {} |
| (...skipping 13 matching lines...) Expand all Loading... |
| 92 // Creates a URLFetcher, using the program's main thread to do IO. | 92 // Creates a URLFetcher, using the program's main thread to do IO. |
| 93 virtual void CreateFetcher(const GURL& url, int max_retries); | 93 virtual void CreateFetcher(const GURL& url, int max_retries); |
| 94 | 94 |
| 95 // CloudPrintURLFetcher::Delegate | 95 // CloudPrintURLFetcher::Delegate |
| 96 virtual CloudPrintURLFetcher::ResponseAction HandleRawResponse( | 96 virtual CloudPrintURLFetcher::ResponseAction HandleRawResponse( |
| 97 const net::URLFetcher* source, | 97 const net::URLFetcher* source, |
| 98 const GURL& url, | 98 const GURL& url, |
| 99 const net::URLRequestStatus& status, | 99 const net::URLRequestStatus& status, |
| 100 int response_code, | 100 int response_code, |
| 101 const net::ResponseCookies& cookies, | 101 const net::ResponseCookies& cookies, |
| 102 const std::string& data) OVERRIDE; | 102 const std::string& data) override; |
| 103 | 103 |
| 104 virtual CloudPrintURLFetcher::ResponseAction OnRequestAuthError() OVERRIDE { | 104 virtual CloudPrintURLFetcher::ResponseAction OnRequestAuthError() override { |
| 105 ADD_FAILURE(); | 105 ADD_FAILURE(); |
| 106 return CloudPrintURLFetcher::STOP_PROCESSING; | 106 return CloudPrintURLFetcher::STOP_PROCESSING; |
| 107 } | 107 } |
| 108 | 108 |
| 109 virtual std::string GetAuthHeader() OVERRIDE { | 109 virtual std::string GetAuthHeader() override { |
| 110 return std::string(); | 110 return std::string(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy() { | 113 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy() { |
| 114 return io_message_loop_proxy_; | 114 return io_message_loop_proxy_; |
| 115 } | 115 } |
| 116 | 116 |
| 117 protected: | 117 protected: |
| 118 virtual void SetUp() { | 118 virtual void SetUp() { |
| 119 testing::Test::SetUp(); | 119 testing::Test::SetUp(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 145 public: | 145 public: |
| 146 CloudPrintURLFetcherBasicTest() | 146 CloudPrintURLFetcherBasicTest() |
| 147 : handle_raw_response_(false), handle_raw_data_(false) { } | 147 : handle_raw_response_(false), handle_raw_data_(false) { } |
| 148 // CloudPrintURLFetcher::Delegate | 148 // CloudPrintURLFetcher::Delegate |
| 149 virtual CloudPrintURLFetcher::ResponseAction HandleRawResponse( | 149 virtual CloudPrintURLFetcher::ResponseAction HandleRawResponse( |
| 150 const net::URLFetcher* source, | 150 const net::URLFetcher* source, |
| 151 const GURL& url, | 151 const GURL& url, |
| 152 const net::URLRequestStatus& status, | 152 const net::URLRequestStatus& status, |
| 153 int response_code, | 153 int response_code, |
| 154 const net::ResponseCookies& cookies, | 154 const net::ResponseCookies& cookies, |
| 155 const std::string& data) OVERRIDE; | 155 const std::string& data) override; |
| 156 | 156 |
| 157 virtual CloudPrintURLFetcher::ResponseAction HandleRawData( | 157 virtual CloudPrintURLFetcher::ResponseAction HandleRawData( |
| 158 const net::URLFetcher* source, | 158 const net::URLFetcher* source, |
| 159 const GURL& url, | 159 const GURL& url, |
| 160 const std::string& data) OVERRIDE; | 160 const std::string& data) override; |
| 161 | 161 |
| 162 virtual CloudPrintURLFetcher::ResponseAction HandleJSONData( | 162 virtual CloudPrintURLFetcher::ResponseAction HandleJSONData( |
| 163 const net::URLFetcher* source, | 163 const net::URLFetcher* source, |
| 164 const GURL& url, | 164 const GURL& url, |
| 165 base::DictionaryValue* json_data, | 165 base::DictionaryValue* json_data, |
| 166 bool succeeded) OVERRIDE; | 166 bool succeeded) override; |
| 167 | 167 |
| 168 void SetHandleRawResponse(bool handle_raw_response) { | 168 void SetHandleRawResponse(bool handle_raw_response) { |
| 169 handle_raw_response_ = handle_raw_response; | 169 handle_raw_response_ = handle_raw_response; |
| 170 } | 170 } |
| 171 void SetHandleRawData(bool handle_raw_data) { | 171 void SetHandleRawData(bool handle_raw_data) { |
| 172 handle_raw_data_ = handle_raw_data; | 172 handle_raw_data_ = handle_raw_data; |
| 173 } | 173 } |
| 174 private: | 174 private: |
| 175 bool handle_raw_response_; | 175 bool handle_raw_response_; |
| 176 bool handle_raw_data_; | 176 bool handle_raw_data_; |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 // Version of CloudPrintURLFetcherTest that tests overload protection. | 179 // Version of CloudPrintURLFetcherTest that tests overload protection. |
| 180 class CloudPrintURLFetcherOverloadTest : public CloudPrintURLFetcherTest { | 180 class CloudPrintURLFetcherOverloadTest : public CloudPrintURLFetcherTest { |
| 181 public: | 181 public: |
| 182 CloudPrintURLFetcherOverloadTest() : response_count_(0) { | 182 CloudPrintURLFetcherOverloadTest() : response_count_(0) { |
| 183 } | 183 } |
| 184 | 184 |
| 185 // CloudPrintURLFetcher::Delegate | 185 // CloudPrintURLFetcher::Delegate |
| 186 virtual CloudPrintURLFetcher::ResponseAction HandleRawData( | 186 virtual CloudPrintURLFetcher::ResponseAction HandleRawData( |
| 187 const net::URLFetcher* source, | 187 const net::URLFetcher* source, |
| 188 const GURL& url, | 188 const GURL& url, |
| 189 const std::string& data) OVERRIDE; | 189 const std::string& data) override; |
| 190 | 190 |
| 191 private: | 191 private: |
| 192 int response_count_; | 192 int response_count_; |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 // Version of CloudPrintURLFetcherTest that tests backoff protection. | 195 // Version of CloudPrintURLFetcherTest that tests backoff protection. |
| 196 class CloudPrintURLFetcherRetryBackoffTest : public CloudPrintURLFetcherTest { | 196 class CloudPrintURLFetcherRetryBackoffTest : public CloudPrintURLFetcherTest { |
| 197 public: | 197 public: |
| 198 CloudPrintURLFetcherRetryBackoffTest() : response_count_(0) { | 198 CloudPrintURLFetcherRetryBackoffTest() : response_count_(0) { |
| 199 } | 199 } |
| 200 | 200 |
| 201 // CloudPrintURLFetcher::Delegate | 201 // CloudPrintURLFetcher::Delegate |
| 202 virtual CloudPrintURLFetcher::ResponseAction HandleRawData( | 202 virtual CloudPrintURLFetcher::ResponseAction HandleRawData( |
| 203 const net::URLFetcher* source, | 203 const net::URLFetcher* source, |
| 204 const GURL& url, | 204 const GURL& url, |
| 205 const std::string& data) OVERRIDE; | 205 const std::string& data) override; |
| 206 | 206 |
| 207 virtual void OnRequestGiveUp() OVERRIDE; | 207 virtual void OnRequestGiveUp() override; |
| 208 | 208 |
| 209 private: | 209 private: |
| 210 int response_count_; | 210 int response_count_; |
| 211 }; | 211 }; |
| 212 | 212 |
| 213 | 213 |
| 214 void CloudPrintURLFetcherTest::CreateFetcher(const GURL& url, int max_retries) { | 214 void CloudPrintURLFetcherTest::CreateFetcher(const GURL& url, int max_retries) { |
| 215 fetcher_ = new TestCloudPrintURLFetcher(io_message_loop_proxy().get()); | 215 fetcher_ = new TestCloudPrintURLFetcher(io_message_loop_proxy().get()); |
| 216 | 216 |
| 217 // Registers an entry for test url. It only allows 3 requests to be sent | 217 // Registers an entry for test url. It only allows 3 requests to be sent |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 base::FilePath(kDocRoot)); | 370 base::FilePath(kDocRoot)); |
| 371 ASSERT_TRUE(test_server.Start()); | 371 ASSERT_TRUE(test_server.Start()); |
| 372 | 372 |
| 373 GURL url(test_server.GetURL("defaultresponse")); | 373 GURL url(test_server.GetURL("defaultresponse")); |
| 374 CreateFetcher(url, 11); | 374 CreateFetcher(url, 11); |
| 375 | 375 |
| 376 base::MessageLoop::current()->Run(); | 376 base::MessageLoop::current()->Run(); |
| 377 } | 377 } |
| 378 | 378 |
| 379 } // namespace cloud_print | 379 } // namespace cloud_print |
| OLD | NEW |