OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/login/mock_url_fetchers.h" | 5 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" |
6 | 6 |
| 7 #include <errno.h> |
| 8 |
7 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
8 #include "chrome/browser/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
| 11 #include "chrome/common/net/http_return.h" |
9 #include "chrome/common/net/url_fetcher.h" | 12 #include "chrome/common/net/url_fetcher.h" |
10 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
11 #include "net/url_request/url_request_status.h" | 14 #include "net/url_request/url_request_status.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
13 | 16 |
14 namespace chromeos { | 17 namespace chromeos { |
15 | 18 |
16 ExpectCanceledFetcher::ExpectCanceledFetcher( | 19 ExpectCanceledFetcher::ExpectCanceledFetcher( |
17 bool success, | 20 bool success, |
18 const GURL& url, | 21 const GURL& url, |
19 const std::string& results, | 22 const std::string& results, |
20 URLFetcher::RequestType request_type, | 23 URLFetcher::RequestType request_type, |
21 URLFetcher::Delegate* d) | 24 URLFetcher::Delegate* d) |
22 : URLFetcher(url, request_type, d) { | 25 : URLFetcher(url, request_type, d) { |
23 } | 26 } |
24 | 27 |
25 ExpectCanceledFetcher::~ExpectCanceledFetcher() { | 28 ExpectCanceledFetcher::~ExpectCanceledFetcher() { |
26 task_->Cancel(); | 29 task_->Cancel(); |
27 } | 30 } |
28 | 31 |
29 void ExpectCanceledFetcher::Start() { | 32 void ExpectCanceledFetcher::Start() { |
30 LOG(INFO) << "Delaying fetch completion in mock"; | |
31 task_ = NewRunnableFunction(&ExpectCanceledFetcher::CompleteFetch); | 33 task_ = NewRunnableFunction(&ExpectCanceledFetcher::CompleteFetch); |
32 ChromeThread::PostDelayedTask(ChromeThread::UI, | 34 ChromeThread::PostDelayedTask(ChromeThread::UI, |
33 FROM_HERE, | 35 FROM_HERE, |
34 task_, | 36 task_, |
35 100); | 37 100); |
36 } | 38 } |
37 | 39 |
38 // static | 40 // static |
39 void ExpectCanceledFetcher::CompleteFetch() { | 41 void ExpectCanceledFetcher::CompleteFetch() { |
40 ADD_FAILURE() << "Fetch completed in ExpectCanceledFetcher!"; | 42 ADD_FAILURE() << "Fetch completed in ExpectCanceledFetcher!"; |
41 MessageLoop::current()->Quit(); // Allow exiting even if we mess up. | 43 MessageLoop::current()->Quit(); // Allow exiting even if we mess up. |
42 } | 44 } |
43 | 45 |
44 GotCanceledFetcher::GotCanceledFetcher(bool success, | 46 GotCanceledFetcher::GotCanceledFetcher(bool success, |
45 const GURL& url, | 47 const GURL& url, |
46 const std::string& results, | 48 const std::string& results, |
47 URLFetcher::RequestType request_type, | 49 URLFetcher::RequestType request_type, |
48 URLFetcher::Delegate* d) | 50 URLFetcher::Delegate* d) |
49 : URLFetcher(url, request_type, d), | 51 : URLFetcher(url, request_type, d), |
50 url_(url) { | 52 url_(url) { |
51 LOG(INFO) << url_.spec(); | |
52 } | 53 } |
53 | 54 |
54 GotCanceledFetcher::~GotCanceledFetcher() {} | 55 GotCanceledFetcher::~GotCanceledFetcher() {} |
55 | 56 |
56 void GotCanceledFetcher::Start() { | 57 void GotCanceledFetcher::Start() { |
57 URLRequestStatus status; | 58 URLRequestStatus status; |
58 status.set_status(URLRequestStatus::CANCELED); | 59 status.set_status(URLRequestStatus::CANCELED); |
59 delegate()->OnURLFetchComplete(this, | 60 delegate()->OnURLFetchComplete(this, |
60 url_, | 61 url_, |
61 status, | 62 status, |
62 403, | 63 RC_FORBIDDEN, |
63 ResponseCookies(), | 64 ResponseCookies(), |
64 std::string()); | 65 std::string()); |
65 } | 66 } |
| 67 |
| 68 SuccessFetcher::SuccessFetcher(bool success, |
| 69 const GURL& url, |
| 70 const std::string& results, |
| 71 URLFetcher::RequestType request_type, |
| 72 URLFetcher::Delegate* d) |
| 73 : URLFetcher(url, request_type, d), |
| 74 url_(url) { |
| 75 } |
| 76 |
| 77 SuccessFetcher::~SuccessFetcher() {} |
| 78 |
| 79 void SuccessFetcher::Start() { |
| 80 delegate()->OnURLFetchComplete(this, |
| 81 url_, |
| 82 URLRequestStatus(URLRequestStatus::SUCCESS, 0), |
| 83 RC_REQUEST_OK, |
| 84 ResponseCookies(), |
| 85 std::string()); |
| 86 } |
| 87 |
| 88 FailFetcher::FailFetcher(bool success, |
| 89 const GURL& url, |
| 90 const std::string& results, |
| 91 URLFetcher::RequestType request_type, |
| 92 URLFetcher::Delegate* d) |
| 93 : URLFetcher(url, request_type, d), |
| 94 url_(url) { |
| 95 } |
| 96 |
| 97 FailFetcher::~FailFetcher() {} |
| 98 |
| 99 void FailFetcher::Start() { |
| 100 URLRequestStatus failed(URLRequestStatus::FAILED, ECONNRESET); |
| 101 delegate()->OnURLFetchComplete(this, |
| 102 url_, |
| 103 failed, |
| 104 RC_REQUEST_OK, |
| 105 ResponseCookies(), |
| 106 std::string()); |
| 107 } |
66 | 108 |
67 } // namespace chromeos | 109 } // namespace chromeos |
OLD | NEW |