Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / net / test / url_request / url_request_failed_job.h
blob0413111c87c9516e3384ea22ced6925afc999783
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
3 // found in the LICENSE file.
5 #ifndef NET_TEST_URL_REQUEST_URL_REQUEST_FAILED_JOB_H_
6 #define NET_TEST_URL_REQUEST_URL_REQUEST_FAILED_JOB_H_
8 #include <string>
10 #include "base/compiler_specific.h"
11 #include "base/memory/weak_ptr.h"
12 #include "net/url_request/url_request_job.h"
13 #include "url/gurl.h"
15 namespace net {
17 // This class simulates a URLRequestJob failing with a given error code at
18 // a particular phase while trying to connect.
19 class URLRequestFailedJob : public URLRequestJob {
20 public:
21 // A Java counterpart will be generated for this enum.
22 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net.test
23 enum FailurePhase {
24 START = 0,
25 READ_SYNC = 1,
26 READ_ASYNC = 2,
27 MAX_FAILURE_PHASE = 3,
30 URLRequestFailedJob(URLRequest* request,
31 NetworkDelegate* network_delegate,
32 FailurePhase phase,
33 int net_error);
35 // Same as above, except that the job fails at FailurePhase.START.
36 URLRequestFailedJob(URLRequest* request,
37 NetworkDelegate* network_delegate,
38 int net_error);
40 // URLRequestJob implementation:
41 void Start() override;
42 bool ReadRawData(IOBuffer* buf, int buf_size, int* bytes_read) override;
43 int GetResponseCode() const override;
44 void GetResponseInfo(HttpResponseInfo* info) override;
46 // Adds the testing URLs to the URLRequestFilter.
47 static void AddUrlHandler();
48 static void AddUrlHandlerForHostname(const std::string& hostname);
50 // Given a net error code, constructs a mock URL that will return that error
51 // asynchronously when started. |net_error| must be a valid net error code
52 // other than net::OK. Passing net::ERR_IO_PENDING for |net_error| causes the
53 // resulting request to hang.
54 static GURL GetMockHttpUrl(int net_error);
55 static GURL GetMockHttpsUrl(int net_error);
57 // Constructs a mock URL that reports |net_error| at given |phase| of the
58 // request. |net_error| must be a valid net error code other than net::OK.
59 // Passing net::ERR_IO_PENDING for |net_error| causes the resulting request to
60 // hang.
61 static GURL GetMockHttpUrlWithFailurePhase(FailurePhase phase, int net_error);
63 // Given a net error code and a host name, constructs a mock URL that will
64 // return that error asynchronously when started. |net_error| must be a valid
65 // net error code other than net::OK. Passing net::ERR_IO_PENDING for
66 // |net_error| causes the resulting request to hang.
67 static GURL GetMockHttpUrlForHostname(int net_error,
68 const std::string& hostname);
69 static GURL GetMockHttpsUrlForHostname(int net_error,
70 const std::string& hostname);
72 protected:
73 ~URLRequestFailedJob() override;
75 private:
76 HttpResponseInfo response_info_;
77 const FailurePhase phase_;
78 const int net_error_;
80 base::WeakPtrFactory<URLRequestFailedJob> weak_factory_;
82 DISALLOW_COPY_AND_ASSIGN(URLRequestFailedJob);
85 } // namespace net
87 #endif // NET_TEST_URL_REQUEST_URL_REQUEST_FAILED_JOB_H_