| 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/threading/thread.h" | 10 #include "base/threading/thread.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 92 |
| 93 // Creates a URLFetcher, using the program's main thread to do IO. | 93 // Creates a URLFetcher, using the program's main thread to do IO. |
| 94 virtual void CreateFetcher(const GURL& url, int max_retries); | 94 virtual void CreateFetcher(const GURL& url, int max_retries); |
| 95 | 95 |
| 96 // CloudPrintURLFetcher::Delegate | 96 // CloudPrintURLFetcher::Delegate |
| 97 CloudPrintURLFetcher::ResponseAction HandleRawResponse( | 97 CloudPrintURLFetcher::ResponseAction HandleRawResponse( |
| 98 const net::URLFetcher* source, | 98 const net::URLFetcher* source, |
| 99 const GURL& url, | 99 const GURL& url, |
| 100 const net::URLRequestStatus& status, | 100 const net::URLRequestStatus& status, |
| 101 int response_code, | 101 int response_code, |
| 102 const net::ResponseCookies& cookies, | |
| 103 const std::string& data) override; | 102 const std::string& data) override; |
| 104 | 103 |
| 105 CloudPrintURLFetcher::ResponseAction OnRequestAuthError() override { | 104 CloudPrintURLFetcher::ResponseAction OnRequestAuthError() override { |
| 106 ADD_FAILURE(); | 105 ADD_FAILURE(); |
| 107 return CloudPrintURLFetcher::STOP_PROCESSING; | 106 return CloudPrintURLFetcher::STOP_PROCESSING; |
| 108 } | 107 } |
| 109 | 108 |
| 110 std::string GetAuthHeader() override { return std::string(); } | 109 std::string GetAuthHeader() override { return std::string(); } |
| 111 | 110 |
| 112 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner() { | 111 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner() { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 public: | 143 public: |
| 145 CloudPrintURLFetcherBasicTest() | 144 CloudPrintURLFetcherBasicTest() |
| 146 : handle_raw_response_(false), handle_raw_data_(false) {} | 145 : handle_raw_response_(false), handle_raw_data_(false) {} |
| 147 | 146 |
| 148 // CloudPrintURLFetcher::Delegate | 147 // CloudPrintURLFetcher::Delegate |
| 149 CloudPrintURLFetcher::ResponseAction HandleRawResponse( | 148 CloudPrintURLFetcher::ResponseAction HandleRawResponse( |
| 150 const net::URLFetcher* source, | 149 const net::URLFetcher* source, |
| 151 const GURL& url, | 150 const GURL& url, |
| 152 const net::URLRequestStatus& status, | 151 const net::URLRequestStatus& status, |
| 153 int response_code, | 152 int response_code, |
| 154 const net::ResponseCookies& cookies, | |
| 155 const std::string& data) override; | 153 const std::string& data) override; |
| 156 | 154 |
| 157 CloudPrintURLFetcher::ResponseAction HandleRawData( | 155 CloudPrintURLFetcher::ResponseAction HandleRawData( |
| 158 const net::URLFetcher* source, | 156 const net::URLFetcher* source, |
| 159 const GURL& url, | 157 const GURL& url, |
| 160 const std::string& data) override; | 158 const std::string& data) override; |
| 161 | 159 |
| 162 CloudPrintURLFetcher::ResponseAction HandleJSONData( | 160 CloudPrintURLFetcher::ResponseAction HandleJSONData( |
| 163 const net::URLFetcher* source, | 161 const net::URLFetcher* source, |
| 164 const GURL& url, | 162 const GURL& url, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 fetcher_->StartGetRequest(CloudPrintURLFetcher::REQUEST_MAX, url, this, | 225 fetcher_->StartGetRequest(CloudPrintURLFetcher::REQUEST_MAX, url, this, |
| 228 max_retries_, std::string()); | 226 max_retries_, std::string()); |
| 229 } | 227 } |
| 230 | 228 |
| 231 CloudPrintURLFetcher::ResponseAction | 229 CloudPrintURLFetcher::ResponseAction |
| 232 CloudPrintURLFetcherTest::HandleRawResponse( | 230 CloudPrintURLFetcherTest::HandleRawResponse( |
| 233 const net::URLFetcher* source, | 231 const net::URLFetcher* source, |
| 234 const GURL& url, | 232 const GURL& url, |
| 235 const net::URLRequestStatus& status, | 233 const net::URLRequestStatus& status, |
| 236 int response_code, | 234 int response_code, |
| 237 const net::ResponseCookies& cookies, | |
| 238 const std::string& data) { | 235 const std::string& data) { |
| 239 EXPECT_TRUE(status.is_success()); | 236 EXPECT_TRUE(status.is_success()); |
| 240 EXPECT_EQ(200, response_code); // HTTP OK | 237 EXPECT_EQ(200, response_code); // HTTP OK |
| 241 EXPECT_FALSE(data.empty()); | 238 EXPECT_FALSE(data.empty()); |
| 242 return CloudPrintURLFetcher::CONTINUE_PROCESSING; | 239 return CloudPrintURLFetcher::CONTINUE_PROCESSING; |
| 243 } | 240 } |
| 244 | 241 |
| 245 CloudPrintURLFetcher::ResponseAction | 242 CloudPrintURLFetcher::ResponseAction |
| 246 CloudPrintURLFetcherBasicTest::HandleRawResponse( | 243 CloudPrintURLFetcherBasicTest::HandleRawResponse( |
| 247 const net::URLFetcher* source, | 244 const net::URLFetcher* source, |
| 248 const GURL& url, | 245 const GURL& url, |
| 249 const net::URLRequestStatus& status, | 246 const net::URLRequestStatus& status, |
| 250 int response_code, | 247 int response_code, |
| 251 const net::ResponseCookies& cookies, | |
| 252 const std::string& data) { | 248 const std::string& data) { |
| 253 EXPECT_TRUE(status.is_success()); | 249 EXPECT_TRUE(status.is_success()); |
| 254 EXPECT_EQ(200, response_code); // HTTP OK | 250 EXPECT_EQ(200, response_code); // HTTP OK |
| 255 EXPECT_FALSE(data.empty()); | 251 EXPECT_FALSE(data.empty()); |
| 256 | 252 |
| 257 if (handle_raw_response_) { | 253 if (handle_raw_response_) { |
| 258 // If the current message loop is not the IO loop, it will be shut down when | 254 // If the current message loop is not the IO loop, it will be shut down when |
| 259 // the main loop returns and this thread subsequently goes out of scope. | 255 // the main loop returns and this thread subsequently goes out of scope. |
| 260 io_task_runner()->PostTask(FROM_HERE, | 256 io_task_runner()->PostTask(FROM_HERE, |
| 261 base::MessageLoop::QuitWhenIdleClosure()); | 257 base::MessageLoop::QuitWhenIdleClosure()); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 test_server.AddDefaultHandlers(base::FilePath(kDocRoot)); | 363 test_server.AddDefaultHandlers(base::FilePath(kDocRoot)); |
| 368 ASSERT_TRUE(test_server.Start()); | 364 ASSERT_TRUE(test_server.Start()); |
| 369 | 365 |
| 370 GURL url(test_server.GetURL("/defaultresponse")); | 366 GURL url(test_server.GetURL("/defaultresponse")); |
| 371 CreateFetcher(url, 11); | 367 CreateFetcher(url, 11); |
| 372 | 368 |
| 373 base::MessageLoop::current()->Run(); | 369 base::MessageLoop::current()->Run(); |
| 374 } | 370 } |
| 375 | 371 |
| 376 } // namespace cloud_print | 372 } // namespace cloud_print |
| OLD | NEW |