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 17 matching lines...) Expand all Loading... |
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) { | 33 void TestURLFetcher::set_status(const net::URLRequestStatus& status) { |
34 fake_status_ = status; | 34 fake_status_ = status; |
35 } | 35 } |
36 | 36 |
37 void TestURLFetcher::SetResponseString(const std::string& response) { | 37 void TestURLFetcher::SetResponseString(const std::string& response) { |
38 response_destination_ = STRING; | 38 SetResponseDestinationForTesting(STRING); |
39 fake_response_string_ = response; | 39 fake_response_string_ = response; |
40 } | 40 } |
41 | 41 |
42 void TestURLFetcher::SetResponseFilePath(const FilePath& path) { | 42 void TestURLFetcher::SetResponseFilePath(const FilePath& path) { |
43 response_destination_ = TEMP_FILE; | 43 SetResponseDestinationForTesting(TEMP_FILE); |
44 fake_response_file_path_ = path; | 44 fake_response_file_path_ = path; |
45 } | 45 } |
46 | 46 |
47 bool TestURLFetcher::GetResponseAsString( | 47 bool TestURLFetcher::GetResponseAsString( |
48 std::string* out_response_string) const { | 48 std::string* out_response_string) const { |
49 if (response_destination_ != STRING) | 49 if (GetResponseDestinationForTesting() != STRING) |
50 return false; | 50 return false; |
51 | 51 |
52 *out_response_string = fake_response_string_; | 52 *out_response_string = fake_response_string_; |
53 return true; | 53 return true; |
54 } | 54 } |
55 | 55 |
56 bool TestURLFetcher::GetResponseAsFilePath( | 56 bool TestURLFetcher::GetResponseAsFilePath( |
57 bool take_ownership, FilePath* out_response_path) const { | 57 bool take_ownership, FilePath* out_response_path) const { |
58 if (response_destination_ != TEMP_FILE) | 58 if (GetResponseDestinationForTesting() != TEMP_FILE) |
59 return false; | 59 return false; |
60 | 60 |
61 *out_response_path = fake_response_file_path_; | 61 *out_response_path = fake_response_file_path_; |
62 return true; | 62 return true; |
63 } | 63 } |
64 | 64 |
65 TestURLFetcherFactory::TestURLFetcherFactory() {} | 65 TestURLFetcherFactory::TestURLFetcherFactory() {} |
66 | 66 |
67 TestURLFetcherFactory::~TestURLFetcherFactory() {} | 67 TestURLFetcherFactory::~TestURLFetcherFactory() {} |
68 | 68 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 void FakeURLFetcherFactory::SetFakeResponse(const std::string& url, | 168 void FakeURLFetcherFactory::SetFakeResponse(const std::string& url, |
169 const std::string& response_data, | 169 const std::string& response_data, |
170 bool success) { | 170 bool success) { |
171 // Overwrite existing URL if it already exists. | 171 // Overwrite existing URL if it already exists. |
172 fake_responses_[GURL(url)] = std::make_pair(response_data, success); | 172 fake_responses_[GURL(url)] = std::make_pair(response_data, success); |
173 } | 173 } |
174 | 174 |
175 void FakeURLFetcherFactory::ClearFakeReponses() { | 175 void FakeURLFetcherFactory::ClearFakeReponses() { |
176 fake_responses_.clear(); | 176 fake_responses_.clear(); |
177 } | 177 } |
OLD | NEW |