Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(951)

Side by Side Diff: content/browser/loader/mock_resource_loader.h

Issue 2581393002: Update MojoAsyncResourceHandler tests to use MockResourceLoader. (Closed)
Patch Set: Oops, had another local change I forgot about Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/loader/DEPS ('k') | content/browser/loader/mock_resource_loader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/run_loop.h"
14 #include "base/strings/string_piece.h"
13 #include "content/browser/loader/resource_controller.h" 15 #include "content/browser/loader/resource_controller.h"
16 #include "net/base/io_buffer.h"
14 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
15 18
16 class GURL; 19 class GURL;
17 20
18 namespace net { 21 namespace net {
19 struct RedirectInfo; 22 struct RedirectInfo;
20 class URLRequestStatus; 23 class URLRequestStatus;
21 } 24 }
22 25
23 namespace content { 26 namespace content {
(...skipping 25 matching lines...) Expand all
49 }; 52 };
50 53
51 // These all run the corresponding methods on ResourceHandler, along with 54 // These all run the corresponding methods on ResourceHandler, along with
52 // basic sanity checks for the behavior of the handler. Each check returns the 55 // basic sanity checks for the behavior of the handler. Each check returns the
53 // current status of the ResourceLoader. 56 // current status of the ResourceLoader.
54 Status OnWillStart(const GURL& url); 57 Status OnWillStart(const GURL& url);
55 Status OnRequestRedirected(const net::RedirectInfo& redirect_info, 58 Status OnRequestRedirected(const net::RedirectInfo& redirect_info,
56 scoped_refptr<ResourceResponse> response); 59 scoped_refptr<ResourceResponse> response);
57 Status OnResponseStarted(scoped_refptr<ResourceResponse> response); 60 Status OnResponseStarted(scoped_refptr<ResourceResponse> response);
58 Status OnWillRead(int min_size); 61 Status OnWillRead(int min_size);
59 Status OnReadCompleted(int bytes_read); 62 Status OnReadCompleted(base::StringPiece bytes);
60 Status OnResponseCompleted(const net::URLRequestStatus& status); 63 Status OnResponseCompleted(const net::URLRequestStatus& status);
61 64
65 // Simulates an out-of-band cancel from some source other than the
66 // ResourceHandler |this| was created with (like another ResourceHandler). The
67 // difference between this and OnResponseCompleted() is that this has fewer
68 // sanity checks to validate the cancel was in-band.
69 Status OnResponseCompletedFromExternalOutOfBandCancel(
70 const net::URLRequestStatus& url_request_status);
71
72 // Waits until status() is IDLE or CANCELED. If that's already the case, does
73 // nothing.
74 void WaitUntilIdleOrCanceled();
75
62 Status status() const { return status_; } 76 Status status() const { return status_; }
63 77
64 // Network error passed to the first CancelWithError() / Cancel() call, which 78 // Network error passed to the first CancelWithError() / Cancel() call, which
65 // is the one the real code uses in the case of multiple cancels. 79 // is the one the real code uses in the case of multiple cancels.
66 int error_code() const { return error_code_; } 80 int error_code() const { return error_code_; }
67 81
82 // Returns IOBuffer returned by last call to OnWillRead. The IOBuffer is
83 // release on read complete, on response complete, and on cancel.
84 net::IOBuffer* io_buffer() const { return io_buffer_.get(); }
85 int io_buffer_size() const { return io_buffer_size_; }
86
68 private: 87 private:
69 // ResourceController implementation. 88 // ResourceController implementation.
70 void Cancel() override; 89 void Cancel() override;
71 void CancelAndIgnore() override; 90 void CancelAndIgnore() override;
72 void CancelWithError(int error_code) override; 91 void CancelWithError(int error_code) override;
73 void Resume() override; 92 void Resume() override;
74 93
75 ResourceHandler* const resource_handler_; 94 ResourceHandler* const resource_handler_;
76 95
77 Status status_ = Status::IDLE; 96 Status status_ = Status::IDLE;
78 int error_code_ = net::OK; 97 int error_code_ = net::OK;
79 98
99 scoped_refptr<net::IOBuffer> io_buffer_;
100 int io_buffer_size_ = 0;
101
102 std::unique_ptr<base::RunLoop> canceled_or_idle_run_loop_;
103
80 DISALLOW_COPY_AND_ASSIGN(MockResourceLoader); 104 DISALLOW_COPY_AND_ASSIGN(MockResourceLoader);
81 }; 105 };
82 106
83 } // namespace content 107 } // namespace content
84 108
85 #endif // CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_WRAPPER_H_ 109 #endif // CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_WRAPPER_H_
OLDNEW
« no previous file with comments | « content/browser/loader/DEPS ('k') | content/browser/loader/mock_resource_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698