OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_BROWSER_NET_TEST_URL_FETCHER_FACTORY_H_ | 5 #ifndef CHROME_BROWSER_NET_TEST_URL_FETCHER_FACTORY_H_ |
6 #define CHROME_BROWSER_NET_TEST_URL_FETCHER_FACTORY_H_ | 6 #define CHROME_BROWSER_NET_TEST_URL_FETCHER_FACTORY_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
| 9 #include <string> |
9 | 10 |
10 #include "chrome/browser/net/url_fetcher.h" | 11 #include "chrome/browser/net/url_fetcher.h" |
11 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
12 | 13 |
13 // TestURLFetcher and TestURLFetcherFactory are used for testing consumers of | 14 // TestURLFetcher and TestURLFetcherFactory are used for testing consumers of |
14 // URLFetcher. TestURLFetcherFactory is a URLFetcher::Factory that creates | 15 // URLFetcher. TestURLFetcherFactory is a URLFetcher::Factory that creates |
15 // TestURLFetchers. TestURLFetcher::Start is overriden to do nothing. It is | 16 // TestURLFetchers. TestURLFetcher::Start is overriden to do nothing. It is |
16 // expected that you'll grab the delegate from the TestURLFetcher and invoke | 17 // expected that you'll grab the delegate from the TestURLFetcher and invoke |
17 // the callback method when appropriate. In this way it's easy to mock a | 18 // the callback method when appropriate. In this way it's easy to mock a |
18 // URLFetcher. | 19 // URLFetcher. |
(...skipping 22 matching lines...) Expand all Loading... |
41 Delegate* delegate() const { return URLFetcher::delegate(); } | 42 Delegate* delegate() const { return URLFetcher::delegate(); } |
42 | 43 |
43 // Overriden to do nothing. It is assumed the caller will notify the delegate. | 44 // Overriden to do nothing. It is assumed the caller will notify the delegate. |
44 virtual void Start() {} | 45 virtual void Start() {} |
45 | 46 |
46 // URL we were created with. Because of how we're using URLFetcher url() | 47 // URL we were created with. Because of how we're using URLFetcher url() |
47 // always returns an empty URL. Chances are you'll want to use original_url() | 48 // always returns an empty URL. Chances are you'll want to use original_url() |
48 // in your tests. | 49 // in your tests. |
49 const GURL& original_url() const { return original_url_; } | 50 const GURL& original_url() const { return original_url_; } |
50 | 51 |
| 52 // Returns the data uploaded on this URLFetcher. |
| 53 const std::string& upload_data() const { return URLFetcher::upload_data(); } |
| 54 |
51 private: | 55 private: |
52 const GURL original_url_; | 56 const GURL original_url_; |
53 | 57 |
54 DISALLOW_COPY_AND_ASSIGN(TestURLFetcher); | 58 DISALLOW_COPY_AND_ASSIGN(TestURLFetcher); |
55 }; | 59 }; |
56 | 60 |
57 // Simple URLFetcher::Factory method that creates TestURLFetchers. All fetchers | 61 // Simple URLFetcher::Factory method that creates TestURLFetchers. All fetchers |
58 // are registered in a map by the id passed to the create method. | 62 // are registered in a map by the id passed to the create method. |
59 class TestURLFetcherFactory : public URLFetcher::Factory { | 63 class TestURLFetcherFactory : public URLFetcher::Factory { |
60 public: | 64 public: |
61 TestURLFetcherFactory() {} | 65 TestURLFetcherFactory() {} |
62 | 66 |
63 virtual URLFetcher* CreateURLFetcher(int id, | 67 virtual URLFetcher* CreateURLFetcher(int id, |
64 const GURL& url, | 68 const GURL& url, |
65 URLFetcher::RequestType request_type, | 69 URLFetcher::RequestType request_type, |
66 URLFetcher::Delegate* d); | 70 URLFetcher::Delegate* d); |
67 | 71 |
68 TestURLFetcher* GetFetcherByID(int id) const; | 72 TestURLFetcher* GetFetcherByID(int id) const; |
69 | 73 |
70 private: | 74 private: |
71 // Maps from id passed to create to the returned URLFetcher. | 75 // Maps from id passed to create to the returned URLFetcher. |
72 typedef std::map<int, TestURLFetcher*> Fetchers; | 76 typedef std::map<int, TestURLFetcher*> Fetchers; |
73 Fetchers fetchers_; | 77 Fetchers fetchers_; |
74 | 78 |
75 DISALLOW_COPY_AND_ASSIGN(TestURLFetcherFactory); | 79 DISALLOW_COPY_AND_ASSIGN(TestURLFetcherFactory); |
76 }; | 80 }; |
77 | 81 |
78 #endif // CHROME_BROWSER_NET_TEST_URL_FETCHER_FACTORY_H_ | 82 #endif // CHROME_BROWSER_NET_TEST_URL_FETCHER_FACTORY_H_ |
OLD | NEW |