| 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 #ifndef CHROME_COMMON_NET_TEST_URL_FETCHER_FACTORY_H_ | 5 #ifndef CHROME_COMMON_NET_TEST_URL_FETCHER_FACTORY_H_ |
| 6 #define CHROME_COMMON_NET_TEST_URL_FETCHER_FACTORY_H_ | 6 #define CHROME_COMMON_NET_TEST_URL_FETCHER_FACTORY_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> |
| 9 #include <map> | 10 #include <map> |
| 10 #include <string> | 11 #include <string> |
| 11 #include <utility> | 12 #include <utility> |
| 12 | 13 |
| 13 #include "chrome/common/net/url_fetcher.h" | 14 #include "chrome/common/net/url_fetcher.h" |
| 14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 15 | 16 |
| 16 // TestURLFetcher and TestURLFetcherFactory are used for testing consumers of | 17 // TestURLFetcher and TestURLFetcherFactory are used for testing consumers of |
| 17 // URLFetcher. TestURLFetcherFactory is a URLFetcher::Factory that creates | 18 // URLFetcher. TestURLFetcherFactory is a URLFetcher::Factory that creates |
| 18 // TestURLFetchers. TestURLFetcher::Start is overriden to do nothing. It is | 19 // TestURLFetchers. TestURLFetcher::Start is overriden to do nothing. It is |
| (...skipping 25 matching lines...) Expand all Loading... |
| 44 class TestURLFetcher : public URLFetcher { | 45 class TestURLFetcher : public URLFetcher { |
| 45 public: | 46 public: |
| 46 TestURLFetcher(int id, | 47 TestURLFetcher(int id, |
| 47 const GURL& url, | 48 const GURL& url, |
| 48 RequestType request_type, | 49 RequestType request_type, |
| 49 Delegate* d); | 50 Delegate* d); |
| 50 | 51 |
| 51 // Overriden to do nothing. It is assumed the caller will notify the delegate. | 52 // Overriden to do nothing. It is assumed the caller will notify the delegate. |
| 52 virtual void Start() {} | 53 virtual void Start() {} |
| 53 | 54 |
| 55 // Overriden to cache the chunks uploaded. Caller can read back the uploaded |
| 56 // chunks with the upload_data() accessor. |
| 57 virtual void AppendChunkToUpload(const std::string& data, bool is_last_chunk); |
| 58 |
| 54 // Unique ID in our factory. | 59 // Unique ID in our factory. |
| 55 int id() const { return id_; } | 60 int id() const { return id_; } |
| 56 | 61 |
| 57 // URL we were created with. Because of how we're using URLFetcher url() | 62 // URL we were created with. Because of how we're using URLFetcher url() |
| 58 // always returns an empty URL. Chances are you'll want to use original_url() | 63 // always returns an empty URL. Chances are you'll want to use original_url() |
| 59 // in your tests. | 64 // in your tests. |
| 60 const GURL& original_url() const { return original_url_; } | 65 const GURL& original_url() const { return original_url_; } |
| 61 | 66 |
| 62 // Returns the data uploaded on this URLFetcher. | 67 // Returns the data uploaded on this URLFetcher. |
| 63 const std::string& upload_data() const { return URLFetcher::upload_data(); } | 68 const std::string& upload_data() const { return URLFetcher::upload_data(); } |
| 64 | 69 |
| 70 // Returns the chunks of data uploaded on this URLFetcher. |
| 71 const std::list<std::string>& upload_chunks() const { return chunks_; } |
| 72 |
| 65 // Returns the delegate installed on the URLFetcher. | 73 // Returns the delegate installed on the URLFetcher. |
| 66 Delegate* delegate() const { return URLFetcher::delegate(); } | 74 Delegate* delegate() const { return URLFetcher::delegate(); } |
| 67 | 75 |
| 68 private: | 76 private: |
| 69 const int id_; | 77 const int id_; |
| 70 const GURL original_url_; | 78 const GURL original_url_; |
| 79 std::list<std::string> chunks_; |
| 80 bool did_receive_last_chunk_; |
| 71 | 81 |
| 72 DISALLOW_COPY_AND_ASSIGN(TestURLFetcher); | 82 DISALLOW_COPY_AND_ASSIGN(TestURLFetcher); |
| 73 }; | 83 }; |
| 74 | 84 |
| 75 // Simple URLFetcher::Factory method that creates TestURLFetchers. All fetchers | 85 // Simple URLFetcher::Factory method that creates TestURLFetchers. All fetchers |
| 76 // are registered in a map by the id passed to the create method. | 86 // are registered in a map by the id passed to the create method. |
| 77 class TestURLFetcherFactory : public URLFetcher::Factory { | 87 class TestURLFetcherFactory : public URLFetcher::Factory { |
| 78 public: | 88 public: |
| 79 TestURLFetcherFactory(); | 89 TestURLFetcherFactory(); |
| 80 virtual ~TestURLFetcherFactory(); | 90 virtual ~TestURLFetcherFactory(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 void ClearFakeReponses(); | 161 void ClearFakeReponses(); |
| 152 | 162 |
| 153 private: | 163 private: |
| 154 typedef std::map<GURL, std::pair<std::string, bool> > FakeResponseMap; | 164 typedef std::map<GURL, std::pair<std::string, bool> > FakeResponseMap; |
| 155 FakeResponseMap fake_responses_; | 165 FakeResponseMap fake_responses_; |
| 156 | 166 |
| 157 DISALLOW_COPY_AND_ASSIGN(FakeURLFetcherFactory); | 167 DISALLOW_COPY_AND_ASSIGN(FakeURLFetcherFactory); |
| 158 }; | 168 }; |
| 159 | 169 |
| 160 #endif // CHROME_COMMON_NET_TEST_URL_FETCHER_FACTORY_H_ | 170 #endif // CHROME_COMMON_NET_TEST_URL_FETCHER_FACTORY_H_ |
| OLD | NEW |