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

Side by Side Diff: net/url_request/test_url_fetcher_factory.h

Issue 667923003: Standardize usage of virtual/override/final in net/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_ 5 #ifndef NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_
6 #define NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_ 6 #define NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // Uploaded chunks can be retrieved with the |upload_chunks()| getter. 77 // Uploaded chunks can be retrieved with the |upload_chunks()| getter.
78 virtual void OnChunkUpload(int fetcher_id) = 0; 78 virtual void OnChunkUpload(int fetcher_id) = 0;
79 79
80 // Callback issued correspondingly to the destructor. 80 // Callback issued correspondingly to the destructor.
81 virtual void OnRequestEnd(int fetcher_id) = 0; 81 virtual void OnRequestEnd(int fetcher_id) = 0;
82 }; 82 };
83 83
84 TestURLFetcher(int id, 84 TestURLFetcher(int id,
85 const GURL& url, 85 const GURL& url,
86 URLFetcherDelegate* d); 86 URLFetcherDelegate* d);
87 virtual ~TestURLFetcher(); 87 ~TestURLFetcher() override;
88 88
89 // URLFetcher implementation 89 // URLFetcher implementation
90 virtual void SetUploadData(const std::string& upload_content_type, 90 void SetUploadData(const std::string& upload_content_type,
91 const std::string& upload_content) override; 91 const std::string& upload_content) override;
92 virtual void SetUploadFilePath( 92 void SetUploadFilePath(
93 const std::string& upload_content_type, 93 const std::string& upload_content_type,
94 const base::FilePath& file_path, 94 const base::FilePath& file_path,
95 uint64 range_offset, 95 uint64 range_offset,
96 uint64 range_length, 96 uint64 range_length,
97 scoped_refptr<base::TaskRunner> file_task_runner) override; 97 scoped_refptr<base::TaskRunner> file_task_runner) override;
98 virtual void SetChunkedUpload( 98 void SetChunkedUpload(const std::string& upload_content_type) override;
99 const std::string& upload_content_type) override;
100 // Overriden to cache the chunks uploaded. Caller can read back the uploaded 99 // Overriden to cache the chunks uploaded. Caller can read back the uploaded
101 // chunks with the upload_chunks() accessor. 100 // chunks with the upload_chunks() accessor.
102 virtual void AppendChunkToUpload(const std::string& data, 101 void AppendChunkToUpload(const std::string& data,
103 bool is_last_chunk) override; 102 bool is_last_chunk) override;
104 virtual void SetLoadFlags(int load_flags) override; 103 void SetLoadFlags(int load_flags) override;
105 virtual int GetLoadFlags() const override; 104 int GetLoadFlags() const override;
106 virtual void SetReferrer(const std::string& referrer) override; 105 void SetReferrer(const std::string& referrer) override;
107 virtual void SetReferrerPolicy( 106 void SetReferrerPolicy(URLRequest::ReferrerPolicy referrer_policy) override;
108 URLRequest::ReferrerPolicy referrer_policy) override; 107 void SetExtraRequestHeaders(
109 virtual void SetExtraRequestHeaders(
110 const std::string& extra_request_headers) override; 108 const std::string& extra_request_headers) override;
111 virtual void AddExtraRequestHeader(const std::string& header_line) override; 109 void AddExtraRequestHeader(const std::string& header_line) override;
112 virtual void SetRequestContext( 110 void SetRequestContext(
113 URLRequestContextGetter* request_context_getter) override; 111 URLRequestContextGetter* request_context_getter) override;
114 virtual void SetFirstPartyForCookies( 112 void SetFirstPartyForCookies(const GURL& first_party_for_cookies) override;
115 const GURL& first_party_for_cookies) override; 113 void SetURLRequestUserData(
116 virtual void SetURLRequestUserData(
117 const void* key, 114 const void* key,
118 const CreateDataCallback& create_data_callback) override; 115 const CreateDataCallback& create_data_callback) override;
119 virtual void SetStopOnRedirect(bool stop_on_redirect) override; 116 void SetStopOnRedirect(bool stop_on_redirect) override;
120 virtual void SetAutomaticallyRetryOn5xx(bool retry) override; 117 void SetAutomaticallyRetryOn5xx(bool retry) override;
121 virtual void SetMaxRetriesOn5xx(int max_retries) override; 118 void SetMaxRetriesOn5xx(int max_retries) override;
122 virtual int GetMaxRetriesOn5xx() const override; 119 int GetMaxRetriesOn5xx() const override;
123 virtual base::TimeDelta GetBackoffDelay() const override; 120 base::TimeDelta GetBackoffDelay() const override;
124 virtual void SetAutomaticallyRetryOnNetworkChanges(int max_retries) override; 121 void SetAutomaticallyRetryOnNetworkChanges(int max_retries) override;
125 virtual void SaveResponseToFileAtPath( 122 void SaveResponseToFileAtPath(
126 const base::FilePath& file_path, 123 const base::FilePath& file_path,
127 scoped_refptr<base::SequencedTaskRunner> file_task_runner) override; 124 scoped_refptr<base::SequencedTaskRunner> file_task_runner) override;
128 virtual void SaveResponseToTemporaryFile( 125 void SaveResponseToTemporaryFile(
129 scoped_refptr<base::SequencedTaskRunner> file_task_runner) override; 126 scoped_refptr<base::SequencedTaskRunner> file_task_runner) override;
130 virtual void SaveResponseWithWriter( 127 void SaveResponseWithWriter(
131 scoped_ptr<URLFetcherResponseWriter> response_writer) override; 128 scoped_ptr<URLFetcherResponseWriter> response_writer) override;
132 virtual HttpResponseHeaders* GetResponseHeaders() const override; 129 HttpResponseHeaders* GetResponseHeaders() const override;
133 virtual HostPortPair GetSocketAddress() const override; 130 HostPortPair GetSocketAddress() const override;
134 virtual bool WasFetchedViaProxy() const override; 131 bool WasFetchedViaProxy() const override;
135 virtual void Start() override; 132 void Start() override;
136 133
137 // URL we were created with. Because of how we're using URLFetcher GetURL() 134 // URL we were created with. Because of how we're using URLFetcher GetURL()
138 // always returns an empty URL. Chances are you'll want to use 135 // always returns an empty URL. Chances are you'll want to use
139 // GetOriginalURL() in your tests. 136 // GetOriginalURL() in your tests.
140 virtual const GURL& GetOriginalURL() const override; 137 const GURL& GetOriginalURL() const override;
141 virtual const GURL& GetURL() const override; 138 const GURL& GetURL() const override;
142 virtual const URLRequestStatus& GetStatus() const override; 139 const URLRequestStatus& GetStatus() const override;
143 virtual int GetResponseCode() const override; 140 int GetResponseCode() const override;
144 virtual const ResponseCookies& GetCookies() const override; 141 const ResponseCookies& GetCookies() const override;
145 virtual void ReceivedContentWasMalformed() override; 142 void ReceivedContentWasMalformed() override;
146 // Override response access functions to return fake data. 143 // Override response access functions to return fake data.
147 virtual bool GetResponseAsString( 144 bool GetResponseAsString(std::string* out_response_string) const override;
148 std::string* out_response_string) const override; 145 bool GetResponseAsFilePath(bool take_ownership,
149 virtual bool GetResponseAsFilePath( 146 base::FilePath* out_response_path) const override;
150 bool take_ownership, base::FilePath* out_response_path) const override;
151 147
152 void GetExtraRequestHeaders(HttpRequestHeaders* headers) const; 148 void GetExtraRequestHeaders(HttpRequestHeaders* headers) const;
153 149
154 // Sets owner of this class. Set it to a non-NULL value if you want 150 // Sets owner of this class. Set it to a non-NULL value if you want
155 // to automatically unregister this fetcher from the owning factory 151 // to automatically unregister this fetcher from the owning factory
156 // upon destruction. 152 // upon destruction.
157 void set_owner(TestURLFetcherFactory* owner) { owner_ = owner; } 153 void set_owner(TestURLFetcherFactory* owner) { owner_ = owner; }
158 154
159 // Unique ID in our factory. 155 // Unique ID in our factory.
160 int id() const { return id_; } 156 int id() const { return id_; }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 typedef TestURLFetcher::DelegateForTests TestURLFetcherDelegateForTests; 230 typedef TestURLFetcher::DelegateForTests TestURLFetcherDelegateForTests;
235 231
236 // Simple URLFetcherFactory method that creates TestURLFetchers. All fetchers 232 // Simple URLFetcherFactory method that creates TestURLFetchers. All fetchers
237 // are registered in a map by the id passed to the create method. 233 // are registered in a map by the id passed to the create method.
238 // Optionally, a fetcher may be automatically unregistered from the map upon 234 // Optionally, a fetcher may be automatically unregistered from the map upon
239 // its destruction. 235 // its destruction.
240 class TestURLFetcherFactory : public URLFetcherFactory, 236 class TestURLFetcherFactory : public URLFetcherFactory,
241 public ScopedURLFetcherFactory { 237 public ScopedURLFetcherFactory {
242 public: 238 public:
243 TestURLFetcherFactory(); 239 TestURLFetcherFactory();
244 virtual ~TestURLFetcherFactory(); 240 ~TestURLFetcherFactory() override;
245 241
246 virtual URLFetcher* CreateURLFetcher( 242 URLFetcher* CreateURLFetcher(int id,
247 int id, 243 const GURL& url,
248 const GURL& url, 244 URLFetcher::RequestType request_type,
249 URLFetcher::RequestType request_type, 245 URLFetcherDelegate* d) override;
250 URLFetcherDelegate* d) override;
251 TestURLFetcher* GetFetcherByID(int id) const; 246 TestURLFetcher* GetFetcherByID(int id) const;
252 void RemoveFetcherFromMap(int id); 247 void RemoveFetcherFromMap(int id);
253 void SetDelegateForTests(TestURLFetcherDelegateForTests* delegate_for_tests); 248 void SetDelegateForTests(TestURLFetcherDelegateForTests* delegate_for_tests);
254 void set_remove_fetcher_on_delete(bool remove_fetcher_on_delete) { 249 void set_remove_fetcher_on_delete(bool remove_fetcher_on_delete) {
255 remove_fetcher_on_delete_ = remove_fetcher_on_delete; 250 remove_fetcher_on_delete_ = remove_fetcher_on_delete;
256 } 251 }
257 252
258 private: 253 private:
259 // Maps from id passed to create to the returned URLFetcher. 254 // Maps from id passed to create to the returned URLFetcher.
260 typedef std::map<int, TestURLFetcher*> Fetchers; 255 typedef std::map<int, TestURLFetcher*> Fetchers;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 public: 287 public:
293 // Normal URL fetcher constructor but also takes in a pre-baked response. 288 // Normal URL fetcher constructor but also takes in a pre-baked response.
294 FakeURLFetcher(const GURL& url, 289 FakeURLFetcher(const GURL& url,
295 URLFetcherDelegate* d, 290 URLFetcherDelegate* d,
296 const std::string& response_data, 291 const std::string& response_data,
297 HttpStatusCode response_code, 292 HttpStatusCode response_code,
298 URLRequestStatus::Status status); 293 URLRequestStatus::Status status);
299 294
300 // Start the request. This will call the given delegate asynchronously 295 // Start the request. This will call the given delegate asynchronously
301 // with the pre-baked response as parameter. 296 // with the pre-baked response as parameter.
302 virtual void Start() override; 297 void Start() override;
303 298
304 virtual const GURL& GetURL() const override; 299 const GURL& GetURL() const override;
305 300
306 virtual ~FakeURLFetcher(); 301 ~FakeURLFetcher() override;
307 302
308 private: 303 private:
309 // This is the method which actually calls the delegate that is passed in the 304 // This is the method which actually calls the delegate that is passed in the
310 // constructor. 305 // constructor.
311 void RunDelegate(); 306 void RunDelegate();
312 307
313 base::WeakPtrFactory<FakeURLFetcher> weak_factory_; 308 base::WeakPtrFactory<FakeURLFetcher> weak_factory_;
314 309
315 DISALLOW_COPY_AND_ASSIGN(FakeURLFetcher); 310 DISALLOW_COPY_AND_ASSIGN(FakeURLFetcher);
316 }; 311 };
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // |default_factory|, which can be NULL, is a URLFetcherFactory that 384 // |default_factory|, which can be NULL, is a URLFetcherFactory that
390 // will be used to construct a URLFetcher in case the URL being created 385 // will be used to construct a URLFetcher in case the URL being created
391 // has no pre-baked response. If it is NULL, a URLFetcherImpl will be 386 // has no pre-baked response. If it is NULL, a URLFetcherImpl will be
392 // created in this case. 387 // created in this case.
393 // |creator| is a callback that returns will be called to create a 388 // |creator| is a callback that returns will be called to create a
394 // FakeURLFetcher if a response is found to a given URL. It can be 389 // FakeURLFetcher if a response is found to a given URL. It can be
395 // set to MakeFakeURLFetcher. 390 // set to MakeFakeURLFetcher.
396 FakeURLFetcherFactory(URLFetcherFactory* default_factory, 391 FakeURLFetcherFactory(URLFetcherFactory* default_factory,
397 const FakeURLFetcherCreator& creator); 392 const FakeURLFetcherCreator& creator);
398 393
399 virtual ~FakeURLFetcherFactory(); 394 ~FakeURLFetcherFactory() override;
400 395
401 // If no fake response is set for the given URL this method will delegate the 396 // If no fake response is set for the given URL this method will delegate the
402 // call to |default_factory_| if it is not NULL, or return NULL if it is 397 // call to |default_factory_| if it is not NULL, or return NULL if it is
403 // NULL. 398 // NULL.
404 // Otherwise, it will return a URLFetcher object which will respond with the 399 // Otherwise, it will return a URLFetcher object which will respond with the
405 // pre-baked response that the client has set by calling SetFakeResponse(). 400 // pre-baked response that the client has set by calling SetFakeResponse().
406 virtual URLFetcher* CreateURLFetcher( 401 URLFetcher* CreateURLFetcher(int id,
407 int id, 402 const GURL& url,
408 const GURL& url, 403 URLFetcher::RequestType request_type,
409 URLFetcher::RequestType request_type, 404 URLFetcherDelegate* d) override;
410 URLFetcherDelegate* d) override;
411 405
412 // Sets the fake response for a given URL. The |response_data| may be empty. 406 // Sets the fake response for a given URL. The |response_data| may be empty.
413 // The |response_code| may be any HttpStatusCode. For instance, HTTP_OK will 407 // The |response_code| may be any HttpStatusCode. For instance, HTTP_OK will
414 // return an HTTP/200 and HTTP_INTERNAL_SERVER_ERROR will return an HTTP/500. 408 // return an HTTP/200 and HTTP_INTERNAL_SERVER_ERROR will return an HTTP/500.
415 // The |status| argument may be any URLRequestStatus::Status value. Typically, 409 // The |status| argument may be any URLRequestStatus::Status value. Typically,
416 // requests that return a valid HttpStatusCode have the SUCCESS status, while 410 // requests that return a valid HttpStatusCode have the SUCCESS status, while
417 // requests that indicate a failure to connect to the server have the FAILED 411 // requests that indicate a failure to connect to the server have the FAILED
418 // status. 412 // status.
419 void SetFakeResponse(const GURL& url, 413 void SetFakeResponse(const GURL& url,
420 const std::string& response_data, 414 const std::string& response_data,
(...skipping 25 matching lines...) Expand all
446 DISALLOW_COPY_AND_ASSIGN(FakeURLFetcherFactory); 440 DISALLOW_COPY_AND_ASSIGN(FakeURLFetcherFactory);
447 }; 441 };
448 442
449 // This is an implementation of URLFetcherFactory that will create a 443 // This is an implementation of URLFetcherFactory that will create a
450 // URLFetcherImpl. It can be use in conjunction with a FakeURLFetcherFactory in 444 // URLFetcherImpl. It can be use in conjunction with a FakeURLFetcherFactory in
451 // integration tests to control the behavior of some requests but execute 445 // integration tests to control the behavior of some requests but execute
452 // all the other ones. 446 // all the other ones.
453 class URLFetcherImplFactory : public URLFetcherFactory { 447 class URLFetcherImplFactory : public URLFetcherFactory {
454 public: 448 public:
455 URLFetcherImplFactory(); 449 URLFetcherImplFactory();
456 virtual ~URLFetcherImplFactory(); 450 ~URLFetcherImplFactory() override;
457 451
458 // This method will create a real URLFetcher. 452 // This method will create a real URLFetcher.
459 virtual URLFetcher* CreateURLFetcher( 453 URLFetcher* CreateURLFetcher(int id,
460 int id, 454 const GURL& url,
461 const GURL& url, 455 URLFetcher::RequestType request_type,
462 URLFetcher::RequestType request_type, 456 URLFetcherDelegate* d) override;
463 URLFetcherDelegate* d) override;
464 }; 457 };
465 458
466 } // namespace net 459 } // namespace net
467 460
468 #endif // NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_ 461 #endif // NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_
OLDNEW
« no previous file with comments | « net/url_request/static_http_user_agent_settings.h ('k') | net/url_request/test_url_request_interceptor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698