Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // 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.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_URL_REQUEST_URL_REQUEST_MOCK_DATA_JOB_H_ | |
| 6 #define NET_URL_REQUEST_URL_REQUEST_MOCK_DATA_JOB_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/strings/string_piece.h" | |
| 13 #include "net/base/completion_callback.h" | |
| 14 #include "net/base/net_export.h" | |
| 15 #include "net/url_request/url_request_job.h" | |
| 16 | |
| 17 namespace base { | |
| 18 class RefCountedMemory; | |
| 19 } | |
| 20 | |
| 21 namespace net { | |
| 22 | |
| 23 class URLRequest; | |
| 24 | |
| 25 // Mock data job, which synchronously returns data repeated multiple times. | |
| 26 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
| |
| 27 public: | |
| 28 URLRequestMockDataJob(URLRequest* request, | |
| 29 NetworkDelegate* network_delegate, | |
| 30 const std::string& data, | |
| 31 unsigned data_repeat_count); | |
| 32 | |
| 33 void Start() override; | |
| 34 bool ReadRawData(IOBuffer* buf, int buf_size, int* bytes_read) override; | |
| 35 bool GetMimeType(std::string* mime_type) const override; | |
| 36 bool GetCharset(std::string* charset) override; | |
| 37 | |
| 38 // Adds the testing URLs to the URLRequestFilter. | |
| 39 static void AddUrlHandler(); | |
| 40 static void AddUrlHandlerForHostname(const std::string& hostname); | |
| 41 | |
| 42 // Given data and repeat cound, constructs a mock URL that will return that | |
| 43 // data repeated |repeat_count| times when started. |data| must be safe for | |
| 44 // URL. | |
| 45 static GURL GetMockHttpUrl(const std::string& data, int repeat_count); | |
| 46 static GURL GetMockHttpsUrl(const std::string& data, int repeat_count); | |
| 47 | |
| 48 // URLRequestFailedJob must be added as a handler for |hostname| for | |
| 49 // the returned URL to return |net_error|. | |
| 50 static GURL GetMockHttpUrlForHostname(const std::string& hostname, | |
| 51 const std::string& data, | |
| 52 int repeat_count); | |
| 53 static GURL GetMockHttpsUrlForHostname(const std::string& hostname, | |
| 54 const std::string& data, | |
| 55 int repeat_count); | |
| 56 | |
| 57 protected: | |
| 58 ~URLRequestMockDataJob() override; | |
| 59 | |
| 60 void StartAsync(); | |
|
mmenke
2014/12/09 21:00:04
Suggest just making these private, for now.
mef
2014/12/09 22:21:00
Done.
| |
| 61 | |
| 62 private: | |
| 63 static URLRequestJob* Factory(URLRequest* request, | |
| 64 NetworkDelegate* network_delegate, | |
| 65 const std::string& scheme); | |
| 66 | |
| 67 void OnGetDataCompleted(int result); | |
| 68 | |
| 69 std::string mime_type_; | |
| 70 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.
| |
| 71 std::string data_; | |
| 72 int64 data_offset_; | |
| 73 base::WeakPtrFactory<URLRequestMockDataJob> weak_factory_; | |
| 74 }; | |
| 75 | |
| 76 } // namespace net | |
| 77 | |
| 78 #endif // NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_ | |
| OLD | NEW |