Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1295)

Side by Side Diff: chrome/common/net/test_url_fetcher_factory.h

Issue 6250198: More out-of-lining of test code, along with a bunch of GMOCK objects. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Really fix the gyp files this time Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 const int id_; 69 const int id_;
70 const GURL original_url_; 70 const GURL original_url_;
71 71
72 DISALLOW_COPY_AND_ASSIGN(TestURLFetcher); 72 DISALLOW_COPY_AND_ASSIGN(TestURLFetcher);
73 }; 73 };
74 74
75 // Simple URLFetcher::Factory method that creates TestURLFetchers. All fetchers 75 // Simple URLFetcher::Factory method that creates TestURLFetchers. All fetchers
76 // are registered in a map by the id passed to the create method. 76 // are registered in a map by the id passed to the create method.
77 class TestURLFetcherFactory : public URLFetcher::Factory { 77 class TestURLFetcherFactory : public URLFetcher::Factory {
78 public: 78 public:
79 TestURLFetcherFactory() {} 79 TestURLFetcherFactory();
80 virtual ~TestURLFetcherFactory();
80 81
81 virtual URLFetcher* CreateURLFetcher(int id, 82 virtual URLFetcher* CreateURLFetcher(int id,
82 const GURL& url, 83 const GURL& url,
83 URLFetcher::RequestType request_type, 84 URLFetcher::RequestType request_type,
84 URLFetcher::Delegate* d); 85 URLFetcher::Delegate* d);
85 TestURLFetcher* GetFetcherByID(int id) const; 86 TestURLFetcher* GetFetcherByID(int id) const;
86 void RemoveFetcherFromMap(int id); 87 void RemoveFetcherFromMap(int id);
87 88
88 private: 89 private:
89 // Maps from id passed to create to the returned URLFetcher. 90 // Maps from id passed to create to the returned URLFetcher.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // // a simple html page and an HTTP/200 code. 122 // // a simple html page and an HTTP/200 code.
122 // factory.SetFakeResponse("http://b.com/asdf", 123 // factory.SetFakeResponse("http://b.com/asdf",
123 // "<html><body>hello world</body></html>", 124 // "<html><body>hello world</body></html>",
124 // true); 125 // true);
125 // 126 //
126 // SomeService service; 127 // SomeService service;
127 // service.Run(); // Will eventually request these two URLs. 128 // service.Run(); // Will eventually request these two URLs.
128 129
129 class FakeURLFetcherFactory : public URLFetcher::Factory { 130 class FakeURLFetcherFactory : public URLFetcher::Factory {
130 public: 131 public:
131 FakeURLFetcherFactory() {} 132 FakeURLFetcherFactory();
133 virtual ~FakeURLFetcherFactory();
132 134
133 // If no fake response is set for the given URL this method will return NULL. 135 // If no fake response is set for the given URL this method will return NULL.
134 // Otherwise, it will return a URLFetcher object which will respond with the 136 // Otherwise, it will return a URLFetcher object which will respond with the
135 // pre-baked response that the client has set by calling SetFakeResponse(). 137 // pre-baked response that the client has set by calling SetFakeResponse().
136 virtual URLFetcher* CreateURLFetcher(int id, 138 virtual URLFetcher* CreateURLFetcher(int id,
137 const GURL& url, 139 const GURL& url,
138 URLFetcher::RequestType request_type, 140 URLFetcher::RequestType request_type,
139 URLFetcher::Delegate* d); 141 URLFetcher::Delegate* d);
140 142
141 // Sets the fake response for a given URL. If success is true we will serve 143 // Sets the fake response for a given URL. If success is true we will serve
142 // an HTTP/200 and an HTTP/500 otherwise. The |response_data| may be empty. 144 // an HTTP/200 and an HTTP/500 otherwise. The |response_data| may be empty.
143 void SetFakeResponse(const std::string& url, 145 void SetFakeResponse(const std::string& url,
144 const std::string& response_data, 146 const std::string& response_data,
145 bool success); 147 bool success);
146 148
147 // Clear all the fake responses that were previously set via 149 // Clear all the fake responses that were previously set via
148 // SetFakeResponse(). 150 // SetFakeResponse().
149 void ClearFakeReponses(); 151 void ClearFakeReponses();
150 152
151 private: 153 private:
152 typedef std::map<GURL, std::pair<std::string, bool> > FakeResponseMap; 154 typedef std::map<GURL, std::pair<std::string, bool> > FakeResponseMap;
153 FakeResponseMap fake_responses_; 155 FakeResponseMap fake_responses_;
154 156
155 DISALLOW_COPY_AND_ASSIGN(FakeURLFetcherFactory); 157 DISALLOW_COPY_AND_ASSIGN(FakeURLFetcherFactory);
156 }; 158 };
157 159
158 #endif // CHROME_COMMON_NET_TEST_URL_FETCHER_FACTORY_H_ 160 #endif // CHROME_COMMON_NET_TEST_URL_FETCHER_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698