Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / net / test / url_request / url_request_mock_data_job.h
blob3d84e371c35495e87fbdd5437c95aa11bd2162b4
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_URL_REQUEST_URL_REQUEST_MOCK_DATA_JOB_H_
6 #define NET_URL_REQUEST_URL_REQUEST_MOCK_DATA_JOB_H_
8 #include <string>
10 #include "base/memory/weak_ptr.h"
11 #include "net/base/net_export.h"
12 #include "net/url_request/url_request_job.h"
14 namespace net {
16 class URLRequest;
18 // Mock data job, which synchronously returns data repeated multiple times.
19 class URLRequestMockDataJob : public URLRequestJob {
20 public:
21 URLRequestMockDataJob(URLRequest* request,
22 NetworkDelegate* network_delegate,
23 const std::string& data,
24 int data_repeat_count);
26 void Start() override;
27 bool ReadRawData(IOBuffer* buf, int buf_size, int* bytes_read) override;
28 int GetResponseCode() const override;
29 void GetResponseInfo(HttpResponseInfo* info) override;
31 // Adds the testing URLs to the URLRequestFilter.
32 static void AddUrlHandler();
33 static void AddUrlHandlerForHostname(const std::string& hostname);
35 // Given data and repeat cound, constructs a mock URL that will return that
36 // data repeated |repeat_count| times when started. |data| must be safe for
37 // URL.
38 static GURL GetMockHttpUrl(const std::string& data, int repeat_count);
39 static GURL GetMockHttpsUrl(const std::string& data, int repeat_count);
41 // URLRequestFailedJob must be added as a handler for |hostname| for
42 // the returned URL to return |net_error|.
43 static GURL GetMockHttpUrlForHostname(const std::string& hostname,
44 const std::string& data,
45 int repeat_count);
46 static GURL GetMockHttpsUrlForHostname(const std::string& hostname,
47 const std::string& data,
48 int repeat_count);
50 private:
51 void GetResponseInfoConst(HttpResponseInfo* info) const;
52 ~URLRequestMockDataJob() override;
54 void StartAsync();
56 std::string data_;
57 size_t data_offset_;
58 base::WeakPtrFactory<URLRequestMockDataJob> weak_factory_;
61 } // namespace net
63 #endif // NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_