| 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 "chrome/common/net/test_url_fetcher_factory.h" | 5 #include "chrome/common/net/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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 TestURLFetcher::~TestURLFetcher() { | 23 TestURLFetcher::~TestURLFetcher() { |
| 24 } | 24 } |
| 25 | 25 |
| 26 void TestURLFetcher::AppendChunkToUpload(const std::string& data, | 26 void TestURLFetcher::AppendChunkToUpload(const std::string& data, |
| 27 bool is_last_chunk) { | 27 bool is_last_chunk) { |
| 28 DCHECK(!did_receive_last_chunk_); | 28 DCHECK(!did_receive_last_chunk_); |
| 29 did_receive_last_chunk_ = is_last_chunk; | 29 did_receive_last_chunk_ = is_last_chunk; |
| 30 chunks_.push_back(data); | 30 chunks_.push_back(data); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void TestURLFetcher::set_status(const net::URLRequestStatus& status) { |
| 34 fake_status_ = status; |
| 35 } |
| 36 |
| 37 void TestURLFetcher::SetResponseString(const std::string& response) { |
| 38 response_destination_ = STRING; |
| 39 fake_response_string_ = response; |
| 40 } |
| 41 |
| 42 void TestURLFetcher::SetResponseFilePath(const FilePath& path) { |
| 43 response_destination_ = TEMP_FILE; |
| 44 fake_response_file_path_ = path; |
| 45 } |
| 46 |
| 47 bool TestURLFetcher::GetResponseAsString( |
| 48 std::string* out_response_string) const { |
| 49 if (response_destination_ != STRING) |
| 50 return false; |
| 51 |
| 52 *out_response_string = fake_response_string_; |
| 53 return true; |
| 54 } |
| 55 |
| 56 bool TestURLFetcher::GetResponseAsFilePath( |
| 57 bool take_ownership, FilePath* out_response_path) const { |
| 58 if (response_destination_ != TEMP_FILE) |
| 59 return false; |
| 60 |
| 61 *out_response_path = fake_response_file_path_; |
| 62 return true; |
| 63 } |
| 64 |
| 33 TestURLFetcherFactory::TestURLFetcherFactory() {} | 65 TestURLFetcherFactory::TestURLFetcherFactory() {} |
| 34 | 66 |
| 35 TestURLFetcherFactory::~TestURLFetcherFactory() {} | 67 TestURLFetcherFactory::~TestURLFetcherFactory() {} |
| 36 | 68 |
| 37 URLFetcher* TestURLFetcherFactory::CreateURLFetcher( | 69 URLFetcher* TestURLFetcherFactory::CreateURLFetcher( |
| 38 int id, | 70 int id, |
| 39 const GURL& url, | 71 const GURL& url, |
| 40 URLFetcher::RequestType request_type, | 72 URLFetcher::RequestType request_type, |
| 41 URLFetcher::Delegate* d) { | 73 URLFetcher::Delegate* d) { |
| 42 TestURLFetcher* fetcher = new TestURLFetcher(id, url, request_type, d); | 74 TestURLFetcher* fetcher = new TestURLFetcher(id, url, request_type, d); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 void FakeURLFetcherFactory::SetFakeResponse(const std::string& url, | 156 void FakeURLFetcherFactory::SetFakeResponse(const std::string& url, |
| 125 const std::string& response_data, | 157 const std::string& response_data, |
| 126 bool success) { | 158 bool success) { |
| 127 // Overwrite existing URL if it already exists. | 159 // Overwrite existing URL if it already exists. |
| 128 fake_responses_[GURL(url)] = std::make_pair(response_data, success); | 160 fake_responses_[GURL(url)] = std::make_pair(response_data, success); |
| 129 } | 161 } |
| 130 | 162 |
| 131 void FakeURLFetcherFactory::ClearFakeReponses() { | 163 void FakeURLFetcherFactory::ClearFakeReponses() { |
| 132 fake_responses_.clear(); | 164 fake_responses_.clear(); |
| 133 } | 165 } |
| OLD | NEW |