Chromium Code Reviews| Index: net/test/url_request/url_request_mock_data_job.h |
| diff --git a/net/test/url_request/url_request_mock_data_job.h b/net/test/url_request/url_request_mock_data_job.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c1c5106007d805ab582091dcca87c6932e6f3126 |
| --- /dev/null |
| +++ b/net/test/url_request/url_request_mock_data_job.h |
| @@ -0,0 +1,78 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
mmenke
2014/12/09 21:00:04
-(c), 2012->2014
mef
2014/12/09 22:21:00
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef NET_URL_REQUEST_URL_REQUEST_MOCK_DATA_JOB_H_ |
| +#define NET_URL_REQUEST_URL_REQUEST_MOCK_DATA_JOB_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/strings/string_piece.h" |
| +#include "net/base/completion_callback.h" |
| +#include "net/base/net_export.h" |
| +#include "net/url_request/url_request_job.h" |
| + |
| +namespace base { |
| +class RefCountedMemory; |
| +} |
| + |
| +namespace net { |
| + |
| +class URLRequest; |
| + |
| +// Mock data job, which synchronously returns data repeated multiple times. |
| +class NET_EXPORT URLRequestMockDataJob : public URLRequestJob { |
|
mmenke
2014/12/09 21:00:04
Maybe MockData -> MockSyncData (Here and elsewhere
mef
2014/12/09 22:21:00
I thought that it may come in handy for async test
|
| + public: |
| + URLRequestMockDataJob(URLRequest* request, |
| + NetworkDelegate* network_delegate, |
| + const std::string& data, |
| + unsigned data_repeat_count); |
| + |
| + void Start() override; |
| + bool ReadRawData(IOBuffer* buf, int buf_size, int* bytes_read) override; |
| + bool GetMimeType(std::string* mime_type) const override; |
| + bool GetCharset(std::string* charset) override; |
| + |
| + // Adds the testing URLs to the URLRequestFilter. |
| + static void AddUrlHandler(); |
| + static void AddUrlHandlerForHostname(const std::string& hostname); |
| + |
| + // Given data and repeat cound, constructs a mock URL that will return that |
| + // data repeated |repeat_count| times when started. |data| must be safe for |
| + // URL. |
| + static GURL GetMockHttpUrl(const std::string& data, int repeat_count); |
| + static GURL GetMockHttpsUrl(const std::string& data, int repeat_count); |
| + |
| + // URLRequestFailedJob must be added as a handler for |hostname| for |
| + // the returned URL to return |net_error|. |
| + static GURL GetMockHttpUrlForHostname(const std::string& hostname, |
| + const std::string& data, |
| + int repeat_count); |
| + static GURL GetMockHttpsUrlForHostname(const std::string& hostname, |
| + const std::string& data, |
| + int repeat_count); |
| + |
| + protected: |
| + ~URLRequestMockDataJob() override; |
| + |
| + void StartAsync(); |
|
mmenke
2014/12/09 21:00:04
Suggest just making these private, for now.
mef
2014/12/09 22:21:00
Done.
|
| + |
| + private: |
| + static URLRequestJob* Factory(URLRequest* request, |
| + NetworkDelegate* network_delegate, |
| + const std::string& scheme); |
| + |
| + void OnGetDataCompleted(int result); |
| + |
| + std::string mime_type_; |
| + std::string charset_; |
|
mmenke
2014/12/09 21:00:04
We don't need these, as they're never initialized.
mef
2014/12/09 22:20:59
Done.
|
| + std::string data_; |
| + int64 data_offset_; |
| + base::WeakPtrFactory<URLRequestMockDataJob> weak_factory_; |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_ |