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

Unified Diff: net/url_request/test_url_fetcher_factory.h

Issue 12211076: Refactored FakeURLFetcher to make it more flexible (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix linter errors Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/url_request/test_url_fetcher_factory.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/test_url_fetcher_factory.h
diff --git a/net/url_request/test_url_fetcher_factory.h b/net/url_request/test_url_fetcher_factory.h
index d7f0d305481c7e5588c96f8ffa907ea1b2a1ffab..9dae9e645393cec26b5e02c84f64452d464a7238 100644
--- a/net/url_request/test_url_fetcher_factory.h
+++ b/net/url_request/test_url_fetcher_factory.h
@@ -10,13 +10,17 @@
#include <string>
#include <utility>
+
akalin 2013/02/12 23:10:10 remove extra newline
Noam Samuel (WRONG ACCOUNT) 2013/02/13 00:25:52 Done.
+#include "base/callback.h"
#include "base/compiler_specific.h"
+#include "base/memory/weak_ptr.h"
#include "base/threading/non_thread_safe.h"
#include "googleurl/src/gurl.h"
#include "net/http/http_request_headers.h"
#include "net/url_request/url_fetcher_factory.h"
#include "net/url_request/url_request_status.h"
+
akalin 2013/02/12 23:10:10 remove extra newline
Noam Samuel (WRONG ACCOUNT) 2013/02/13 00:25:52 Done.
namespace net {
// Changes URLFetcher's Factory for the lifetime of the object.
@@ -287,13 +291,27 @@ class TestURLFetcherFactory : public URLFetcherFactory,
// SomeService service;
// service.Run(); // Will eventually request these two URLs.
+class FakeURLFetcher;
class FakeURLFetcherFactory : public URLFetcherFactory,
public ScopedURLFetcherFactory {
public:
+ typedef base::Callback< FakeURLFetcher*(
akalin 2013/02/12 23:10:10 no space after <
akalin 2013/02/12 23:10:10 add comment describing what the parameters are (si
akalin 2013/02/12 23:10:10 since the caller should take ownership of the retu
Noam Samuel (WRONG ACCOUNT) 2013/02/13 00:25:52 Done.
Noam Samuel (WRONG ACCOUNT) 2013/02/13 00:25:52 Since this callback is only called by the factory
Noam Samuel (WRONG ACCOUNT) 2013/02/13 00:25:52 Done.
akalin 2013/02/13 20:44:01 I'd argue that the factory method should also retu
+ const GURL&,
+ URLFetcherDelegate*,
+ const std::string&,
+ bool) > FakeURLFetcherCreator;
akalin 2013/02/12 23:10:10 no space before >
Noam Samuel (WRONG ACCOUNT) 2013/02/13 00:25:52 Done.
+
FakeURLFetcherFactory();
akalin 2013/02/12 23:10:10 see if you can get away with only having a single
Noam Samuel (WRONG ACCOUNT) 2013/02/13 00:25:52 Since the callback has an obvious but nontrivial d
akalin 2013/02/13 20:44:01 I suppose. Although I would at least like to get r
Noam Samuel (WRONG ACCOUNT) 2013/02/13 21:37:46 Added to latest patch set. If it's too cumbersome
// FakeURLFetcherFactory that will delegate creating URLFetcher for unknown
// url to the given factory.
explicit FakeURLFetcherFactory(URLFetcherFactory* default_factory);
+
+ // FakeURLFetcherFactory that will delegate creating URLFetcher for unknown
akalin 2013/02/12 23:10:10 this comment isn't a complete sentence and is hard
Noam Samuel (WRONG ACCOUNT) 2013/02/13 00:25:52 Done.
+ // url to the given factory (can be NULL) and will delegate creating for
+ // known url to given callback
+ FakeURLFetcherFactory(const FakeURLFetcherCreator& creator,
+ URLFetcherFactory* default_factory);
+
virtual ~FakeURLFetcherFactory();
// If no fake response is set for the given URL this method will delegate the
@@ -313,18 +331,55 @@ class FakeURLFetcherFactory : public URLFetcherFactory,
const std::string& response_data,
bool success);
+
akalin 2013/02/12 23:10:10 remove extra newline
Noam Samuel (WRONG ACCOUNT) 2013/02/13 00:25:52 Done.
// Clear all the fake responses that were previously set via
// SetFakeResponse().
void ClearFakeResponses();
private:
+ FakeURLFetcherCreator creator_;
akalin 2013/02/12 23:10:10 make it const
Noam Samuel (WRONG ACCOUNT) 2013/02/13 00:25:52 Done.
typedef std::map<GURL, std::pair<std::string, bool> > FakeResponseMap;
FakeResponseMap fake_responses_;
URLFetcherFactory* default_factory_;
akalin 2013/02/12 23:10:10 make this const, like URLFetcherFactory* const
Noam Samuel (WRONG ACCOUNT) 2013/02/13 00:25:52 Done.
+
+ static FakeURLFetcher* DefaultFakeURLFetcherCreator(
+ const GURL& url,
+ URLFetcherDelegate* delegate,
+ const std::string& response,
+ bool success);
DISALLOW_COPY_AND_ASSIGN(FakeURLFetcherFactory);
};
+
+
+// This class is used by the FakeURLFetcherFactory above.
akalin 2013/02/12 23:10:10 Try to describe what the FakeURLFetcher does witho
Noam Samuel (WRONG ACCOUNT) 2013/02/13 00:25:52 Done.
+class FakeURLFetcher : public TestURLFetcher {
akalin 2013/02/12 23:10:10 you can move this declaration up above FakeURLFetc
Noam Samuel (WRONG ACCOUNT) 2013/02/13 00:25:52 Done.
+ public:
+ // Normal URL fetcher constructor but also takes in a pre-baked response.
+ FakeURLFetcher(const GURL& url,
+ URLFetcherDelegate* d,
+ const std::string& response_data, bool success);
+
+ // Start the request. This will call the given delegate asynchronously
+ // with the pre-baked response as parameter.
+ virtual void Start() OVERRIDE;
+
+ virtual const GURL& GetURL() const OVERRIDE;
+
+ private:
+ virtual ~FakeURLFetcher();
+
+ // This is the method which actually calls the delegate that is passed in the
+ // constructor.
+ void RunDelegate();
+
+ base::WeakPtrFactory<FakeURLFetcher> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeURLFetcher);
+};
+
+
// This is an implementation of URLFetcherFactory that will create a
// URLFetcherImpl. It can be use in conjunction with a FakeURLFetcherFactory in
// integration tests to control the behavior of some requests but execute
« no previous file with comments | « no previous file | net/url_request/test_url_fetcher_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698