xref: /aosp_15_r20/external/cronet/net/test/url_request/url_request_hanging_read_job.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2016 The Chromium Authors
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_TEST_URL_REQUEST_URL_REQUEST_HANGING_READ_JOB_H_
6 #define NET_TEST_URL_REQUEST_URL_REQUEST_HANGING_READ_JOB_H_
7 
8 #include "base/memory/weak_ptr.h"
9 #include "net/url_request/url_request_job.h"
10 
11 namespace net {
12 
13 class URLRequest;
14 
15 // A URLRequestJob that hangs when try to read response body.
16 class URLRequestHangingReadJob : public URLRequestJob {
17  public:
18   explicit URLRequestHangingReadJob(URLRequest* request);
19 
20   URLRequestHangingReadJob(const URLRequestHangingReadJob&) = delete;
21   URLRequestHangingReadJob& operator=(const URLRequestHangingReadJob&) = delete;
22 
23   ~URLRequestHangingReadJob() override;
24 
25   void Start() override;
26   int ReadRawData(IOBuffer* buf, int buf_size) override;
27   void GetResponseInfo(HttpResponseInfo* info) override;
28 
29   // Adds the testing URLs to the URLRequestFilter.
30   static void AddUrlHandler();
31 
32   static GURL GetMockHttpUrl();
33   static GURL GetMockHttpsUrl();
34 
35  private:
36   void GetResponseInfoConst(HttpResponseInfo* info) const;
37 
38   void StartAsync();
39 
40   const int content_length_ = 10;  // non-zero content-length
41   base::WeakPtrFactory<URLRequestHangingReadJob> weak_factory_{this};
42 };
43 
44 }  // namespace net
45 
46 #endif  // NET_TEST_URL_REQUEST_URL_REQUEST_HANGING_READ_JOB_H_
47