| OLD | NEW |
| 1 // Copyright (c) 2011 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 "content/common/test_url_fetcher_factory.h" | 5 #include "content/test/test_url_fetcher_factory.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "net/url_request/url_request_status.h" | 11 #include "net/url_request/url_request_status.h" |
| 12 | 12 |
| 13 ScopedURLFetcherFactory::ScopedURLFetcherFactory(URLFetcher::Factory* factory) { |
| 14 DCHECK(!URLFetcher::factory()); |
| 15 URLFetcher::set_factory(factory); |
| 16 } |
| 17 |
| 18 ScopedURLFetcherFactory::~ScopedURLFetcherFactory() { |
| 19 DCHECK(URLFetcher::factory()); |
| 20 URLFetcher::set_factory(NULL); |
| 21 } |
| 22 |
| 13 TestURLFetcher::TestURLFetcher(int id, | 23 TestURLFetcher::TestURLFetcher(int id, |
| 14 const GURL& url, | 24 const GURL& url, |
| 15 URLFetcher::RequestType request_type, | 25 URLFetcher::RequestType request_type, |
| 16 URLFetcher::Delegate* d) | 26 URLFetcher::Delegate* d) |
| 17 : URLFetcher(url, request_type, d), | 27 : URLFetcher(url, request_type, d), |
| 18 id_(id), | 28 id_(id), |
| 19 original_url_(url), | 29 original_url_(url), |
| 20 did_receive_last_chunk_(false) { | 30 did_receive_last_chunk_(false) { |
| 21 } | 31 } |
| 22 | 32 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 65 |
| 56 bool TestURLFetcher::GetResponseAsFilePath( | 66 bool TestURLFetcher::GetResponseAsFilePath( |
| 57 bool take_ownership, FilePath* out_response_path) const { | 67 bool take_ownership, FilePath* out_response_path) const { |
| 58 if (GetResponseDestinationForTesting() != TEMP_FILE) | 68 if (GetResponseDestinationForTesting() != TEMP_FILE) |
| 59 return false; | 69 return false; |
| 60 | 70 |
| 61 *out_response_path = fake_response_file_path_; | 71 *out_response_path = fake_response_file_path_; |
| 62 return true; | 72 return true; |
| 63 } | 73 } |
| 64 | 74 |
| 65 TestURLFetcherFactory::TestURLFetcherFactory() {} | 75 TestURLFetcherFactory::TestURLFetcherFactory() |
| 76 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 77 } |
| 66 | 78 |
| 67 TestURLFetcherFactory::~TestURLFetcherFactory() {} | 79 TestURLFetcherFactory::~TestURLFetcherFactory() {} |
| 68 | 80 |
| 69 URLFetcher* TestURLFetcherFactory::CreateURLFetcher( | 81 URLFetcher* TestURLFetcherFactory::CreateURLFetcher( |
| 70 int id, | 82 int id, |
| 71 const GURL& url, | 83 const GURL& url, |
| 72 URLFetcher::RequestType request_type, | 84 URLFetcher::RequestType request_type, |
| 73 URLFetcher::Delegate* d) { | 85 URLFetcher::Delegate* d) { |
| 74 TestURLFetcher* fetcher = new TestURLFetcher(id, url, request_type, d); | 86 TestURLFetcher* fetcher = new TestURLFetcher(id, url, request_type, d); |
| 75 fetchers_[id] = fetcher; | 87 fetchers_[id] = fetcher; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 GURL url_; | 151 GURL url_; |
| 140 std::string response_data_; | 152 std::string response_data_; |
| 141 bool success_; | 153 bool success_; |
| 142 | 154 |
| 143 // Method factory used to run the delegate. | 155 // Method factory used to run the delegate. |
| 144 ScopedRunnableMethodFactory<FakeURLFetcher> method_factory_; | 156 ScopedRunnableMethodFactory<FakeURLFetcher> method_factory_; |
| 145 | 157 |
| 146 DISALLOW_COPY_AND_ASSIGN(FakeURLFetcher); | 158 DISALLOW_COPY_AND_ASSIGN(FakeURLFetcher); |
| 147 }; | 159 }; |
| 148 | 160 |
| 149 FakeURLFetcherFactory::FakeURLFetcherFactory() {} | 161 FakeURLFetcherFactory::FakeURLFetcherFactory() |
| 162 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 163 } |
| 150 | 164 |
| 151 FakeURLFetcherFactory::FakeURLFetcherFactory( | 165 FakeURLFetcherFactory::FakeURLFetcherFactory( |
| 152 URLFetcher::Factory* default_factory) : default_factory_(default_factory) {} | 166 URLFetcher::Factory* default_factory) |
| 167 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 168 default_factory_(default_factory) { |
| 169 } |
| 153 | 170 |
| 154 FakeURLFetcherFactory::~FakeURLFetcherFactory() {} | 171 FakeURLFetcherFactory::~FakeURLFetcherFactory() {} |
| 155 | 172 |
| 156 URLFetcher* FakeURLFetcherFactory::CreateURLFetcher( | 173 URLFetcher* FakeURLFetcherFactory::CreateURLFetcher( |
| 157 int id, | 174 int id, |
| 158 const GURL& url, | 175 const GURL& url, |
| 159 URLFetcher::RequestType request_type, | 176 URLFetcher::RequestType request_type, |
| 160 URLFetcher::Delegate* d) { | 177 URLFetcher::Delegate* d) { |
| 161 FakeResponseMap::const_iterator it = fake_responses_.find(url); | 178 FakeResponseMap::const_iterator it = fake_responses_.find(url); |
| 162 if (it == fake_responses_.end()) { | 179 if (it == fake_responses_.end()) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 187 | 204 |
| 188 URLFetcherFactory::~URLFetcherFactory() {} | 205 URLFetcherFactory::~URLFetcherFactory() {} |
| 189 | 206 |
| 190 URLFetcher* URLFetcherFactory::CreateURLFetcher( | 207 URLFetcher* URLFetcherFactory::CreateURLFetcher( |
| 191 int id, | 208 int id, |
| 192 const GURL& url, | 209 const GURL& url, |
| 193 URLFetcher::RequestType request_type, | 210 URLFetcher::RequestType request_type, |
| 194 URLFetcher::Delegate* d) { | 211 URLFetcher::Delegate* d) { |
| 195 return new URLFetcher(url, request_type, d); | 212 return new URLFetcher(url, request_type, d); |
| 196 } | 213 } |
| OLD | NEW |