OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/common/net/test_url_fetcher_factory.h" | 5 #include "chrome/common/net/test_url_fetcher_factory.h" |
| 6 |
6 #include <string> | 7 #include <string> |
7 | 8 |
8 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
10 #include "net/url_request/url_request_status.h" | 11 #include "net/url_request/url_request_status.h" |
11 | 12 |
12 TestURLFetcher::TestURLFetcher(int id, | 13 TestURLFetcher::TestURLFetcher(int id, |
13 const GURL& url, | 14 const GURL& url, |
14 URLFetcher::RequestType request_type, | 15 URLFetcher::RequestType request_type, |
15 URLFetcher::Delegate* d) | 16 URLFetcher::Delegate* d) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 method_factory_.NewRunnableMethod(&FakeURLFetcher::RunDelegate)); | 61 method_factory_.NewRunnableMethod(&FakeURLFetcher::RunDelegate)); |
61 } | 62 } |
62 | 63 |
63 private: | 64 private: |
64 virtual ~FakeURLFetcher() { | 65 virtual ~FakeURLFetcher() { |
65 } | 66 } |
66 | 67 |
67 // This is the method which actually calls the delegate that is passed in the | 68 // This is the method which actually calls the delegate that is passed in the |
68 // constructor. | 69 // constructor. |
69 void RunDelegate() { | 70 void RunDelegate() { |
70 URLRequestStatus status; | 71 net::URLRequestStatus status; |
71 status.set_status(success_ ? URLRequestStatus::SUCCESS : | 72 status.set_status(success_ ? net::URLRequestStatus::SUCCESS : |
72 URLRequestStatus::FAILED); | 73 net::URLRequestStatus::FAILED); |
73 delegate()->OnURLFetchComplete(this, url_, status, success_ ? 200 : 500, | 74 delegate()->OnURLFetchComplete(this, url_, status, success_ ? 200 : 500, |
74 ResponseCookies(), response_data_); | 75 ResponseCookies(), response_data_); |
75 } | 76 } |
76 | 77 |
77 // Pre-baked response data and flag which indicates whether the request should | 78 // Pre-baked response data and flag which indicates whether the request should |
78 // be successful or not. | 79 // be successful or not. |
79 GURL url_; | 80 GURL url_; |
80 std::string response_data_; | 81 std::string response_data_; |
81 bool success_; | 82 bool success_; |
82 | 83 |
(...skipping 21 matching lines...) Expand all Loading... |
104 void FakeURLFetcherFactory::SetFakeResponse(const std::string& url, | 105 void FakeURLFetcherFactory::SetFakeResponse(const std::string& url, |
105 const std::string& response_data, | 106 const std::string& response_data, |
106 bool success) { | 107 bool success) { |
107 // Overwrite existing URL if it already exists. | 108 // Overwrite existing URL if it already exists. |
108 fake_responses_[GURL(url)] = std::make_pair(response_data, success); | 109 fake_responses_[GURL(url)] = std::make_pair(response_data, success); |
109 } | 110 } |
110 | 111 |
111 void FakeURLFetcherFactory::ClearFakeReponses() { | 112 void FakeURLFetcherFactory::ClearFakeReponses() { |
112 fake_responses_.clear(); | 113 fake_responses_.clear(); |
113 } | 114 } |
OLD | NEW |