OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_LOADER_MOCK_RESOURCE_LOADER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_MOCK_RESOURCE_LOADER_H_ |
6 #define CONTENT_BROWSER_LOADER_MOCK_RESOURCE_LOADER_H_ | 6 #define CONTENT_BROWSER_LOADER_MOCK_RESOURCE_LOADER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/run_loop.h" | |
13 #include "base/strings/string_piece.h" | |
12 #include "content/browser/loader/resource_controller.h" | 14 #include "content/browser/loader/resource_controller.h" |
15 #include "net/base/io_buffer.h" | |
13 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
14 | 17 |
15 class GURL; | 18 class GURL; |
16 | 19 |
17 namespace net { | 20 namespace net { |
18 struct RedirectInfo; | 21 struct RedirectInfo; |
19 class URLRequestStatus; | 22 class URLRequestStatus; |
20 } | 23 } |
21 | 24 |
22 namespace content { | 25 namespace content { |
(...skipping 25 matching lines...) Expand all Loading... | |
48 }; | 51 }; |
49 | 52 |
50 // These all run the corresponding methods on ResourceHandler, along with | 53 // These all run the corresponding methods on ResourceHandler, along with |
51 // basic sanity checks for the behavior of the handler. Each check returns the | 54 // basic sanity checks for the behavior of the handler. Each check returns the |
52 // current status of the ResourceLoader. | 55 // current status of the ResourceLoader. |
53 Status OnWillStart(const GURL& url); | 56 Status OnWillStart(const GURL& url); |
54 Status OnRequestRedirected(const net::RedirectInfo& redirect_info, | 57 Status OnRequestRedirected(const net::RedirectInfo& redirect_info, |
55 ResourceResponse* response); | 58 ResourceResponse* response); |
56 Status OnResponseStarted(ResourceResponse* response); | 59 Status OnResponseStarted(ResourceResponse* response); |
57 Status OnWillRead(int min_size); | 60 Status OnWillRead(int min_size); |
58 Status OnReadCompleted(int bytes_read); | 61 Status OnReadCompleted(base::StringPiece bytes); |
59 Status OnResponseCompleted(const net::URLRequestStatus& status); | 62 Status OnResponseCompleted(const net::URLRequestStatus& status); |
60 | 63 |
64 // Simulates an out-of-band cancel from some source other than the | |
65 // ResourceHandler |this| was created with (like a putative higher layer | |
Randy Smith (Not in Mondays)
2016/12/21 16:47:37
Higher layer? Maybe this is just a vocabulary iss
mmenke
2017/01/05 18:50:25
Actually, I was just thinking in terms of the Mojo
| |
66 // ResourceHandler). The difference between this and OnResponseCompleted() is | |
67 // that this has fewer sanity checks. | |
68 Status OnResponseCompletedFromExternalOutOfBandCancel( | |
69 const net::URLRequestStatus& status); | |
70 | |
71 // Waits until status() is IDLE or CANCELED. If that's already the case, does | |
72 // nothing. | |
73 void WaitUntilIdleOrCanceled(); | |
74 | |
61 Status status() const { return status_; } | 75 Status status() const { return status_; } |
62 | 76 |
63 // Network error passed to the first CancelWithError() / Cancel() call, which | 77 // Network error passed to the first CancelWithError() / Cancel() call, which |
64 // is the one the real code uses in the case of multiple cancels. | 78 // is the one the real code uses in the case of multiple cancels. |
65 int error_code() const { return error_code_; } | 79 int error_code() const { return error_code_; } |
66 | 80 |
81 net::IOBuffer* io_buffer() const { return io_buffer_.get(); } | |
82 int io_buffer_size() const { return io_buffer_size_; } | |
83 | |
84 void ReleaseIOBuffer(); | |
85 | |
67 private: | 86 private: |
68 // ResourceController implementation. | 87 // ResourceController implementation. |
69 void Cancel() override; | 88 void Cancel() override; |
70 void CancelAndIgnore() override; | 89 void CancelAndIgnore() override; |
71 void CancelWithError(int error_code) override; | 90 void CancelWithError(int error_code) override; |
72 void Resume() override; | 91 void Resume() override; |
73 | 92 |
74 ResourceHandler* const resource_handler_; | 93 ResourceHandler* const resource_handler_; |
75 | 94 |
76 Status status_ = Status::IDLE; | 95 Status status_ = Status::IDLE; |
77 int error_code_ = net::OK; | 96 int error_code_ = net::OK; |
78 | 97 |
98 scoped_refptr<net::IOBuffer> io_buffer_; | |
99 int io_buffer_size_ = 0; | |
100 | |
101 std::unique_ptr<base::RunLoop> canceled_or_idle_run_loop_; | |
102 | |
79 DISALLOW_COPY_AND_ASSIGN(MockResourceLoader); | 103 DISALLOW_COPY_AND_ASSIGN(MockResourceLoader); |
80 }; | 104 }; |
81 | 105 |
82 } // namespace content | 106 } // namespace content |
83 | 107 |
84 #endif // CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_WRAPPER_H_ | 108 #endif // CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_WRAPPER_H_ |
OLD | NEW |