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

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

Issue 2626663002: Update MimeSniffingResourceHandler tests to use MockResourceLoader. (Closed)
Patch Set: Merge 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
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 #include "content/browser/loader/mock_resource_loader.h" 5 #include "content/browser/loader/mock_resource_loader.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 17 matching lines...) Expand all
28 EXPECT_EQ(Status::IDLE, status_); 28 EXPECT_EQ(Status::IDLE, status_);
29 status_ = Status::CALLING_HANDLER; 29 status_ = Status::CALLING_HANDLER;
30 30
31 bool defer = false; 31 bool defer = false;
32 bool result = resource_handler_->OnWillStart(url, &defer); 32 bool result = resource_handler_->OnWillStart(url, &defer);
33 // The second case isn't really allowed, but a number of classes do it 33 // The second case isn't really allowed, but a number of classes do it
34 // anyways. 34 // anyways.
35 EXPECT_TRUE(status_ == Status::CALLING_HANDLER || 35 EXPECT_TRUE(status_ == Status::CALLING_HANDLER ||
36 (result == false && status_ == Status::CANCELED)); 36 (result == false && status_ == Status::CANCELED));
37 if (!result) { 37 if (!result) {
38 // In the case of double-cancels, keep the old error code.
39 // TODO(mmenke): Once there are no more double cancel cases, remove this
40 // code.
41 if (status_ != Status::CANCELED)
42 error_code_ = net::ERR_ABORTED;
38 status_ = Status::CANCELED; 43 status_ = Status::CANCELED;
39 } else if (defer) { 44 } else if (defer) {
40 status_ = Status::CALLBACK_PENDING; 45 status_ = Status::CALLBACK_PENDING;
41 } else { 46 } else {
42 status_ = Status::IDLE; 47 status_ = Status::IDLE;
43 } 48 }
44 return status_; 49 return status_;
45 } 50 }
46 51
47 MockResourceLoader::Status MockResourceLoader::OnRequestRedirected( 52 MockResourceLoader::Status MockResourceLoader::OnRequestRedirected(
48 const net::RedirectInfo& redirect_info, 53 const net::RedirectInfo& redirect_info,
49 scoped_refptr<ResourceResponse> response) { 54 scoped_refptr<ResourceResponse> response) {
50 EXPECT_EQ(Status::IDLE, status_); 55 EXPECT_EQ(Status::IDLE, status_);
51 status_ = Status::CALLING_HANDLER; 56 status_ = Status::CALLING_HANDLER;
52 57
53 bool defer = false; 58 bool defer = false;
54 // Note that |this| does not hold onto |response|, to match ResourceLoader's 59 // Note that |this| does not hold onto |response|, to match ResourceLoader's
55 // behavior. If |resource_handler_| wants to use |response| asynchronously, it 60 // behavior. If |resource_handler_| wants to use |response| asynchronously, it
56 // needs to hold onto its own pointer to it. 61 // needs to hold onto its own pointer to it.
57 bool result = resource_handler_->OnRequestRedirected(redirect_info, 62 bool result = resource_handler_->OnRequestRedirected(redirect_info,
58 response.get(), &defer); 63 response.get(), &defer);
59 // The second case isn't really allowed, but a number of classes do it 64 // The second case isn't really allowed, but a number of classes do it
60 // anyways. 65 // anyways.
61 EXPECT_TRUE(status_ == Status::CALLING_HANDLER || 66 EXPECT_TRUE(status_ == Status::CALLING_HANDLER ||
62 (result == false && status_ == Status::CANCELED)); 67 (result == false && status_ == Status::CANCELED));
63 if (!result) { 68 if (!result) {
69 // In the case of double-cancels, keep the old error code.
70 if (status_ != Status::CANCELED)
71 error_code_ = net::ERR_ABORTED;
64 status_ = Status::CANCELED; 72 status_ = Status::CANCELED;
65 } else if (defer) { 73 } else if (defer) {
66 status_ = Status::CALLBACK_PENDING; 74 status_ = Status::CALLBACK_PENDING;
67 } else { 75 } else {
68 status_ = Status::IDLE; 76 status_ = Status::IDLE;
69 } 77 }
70 return status_; 78 return status_;
71 } 79 }
72 80
73 MockResourceLoader::Status MockResourceLoader::OnResponseStarted( 81 MockResourceLoader::Status MockResourceLoader::OnResponseStarted(
74 scoped_refptr<ResourceResponse> response) { 82 scoped_refptr<ResourceResponse> response) {
75 EXPECT_EQ(Status::IDLE, status_); 83 EXPECT_EQ(Status::IDLE, status_);
76 status_ = Status::CALLING_HANDLER; 84 status_ = Status::CALLING_HANDLER;
77 85
78 bool defer = false; 86 bool defer = false;
79 // Note that |this| does not hold onto |response|, to match ResourceLoader's 87 // Note that |this| does not hold onto |response|, to match ResourceLoader's
80 // behavior. If |resource_handler_| wants to use |response| asynchronously, it 88 // behavior. If |resource_handler_| wants to use |response| asynchronously, it
81 // needs to hold onto its own pointer to it. 89 // needs to hold onto its own pointer to it.
82 bool result = resource_handler_->OnResponseStarted(response.get(), &defer); 90 bool result = resource_handler_->OnResponseStarted(response.get(), &defer);
83 // The second case isn't really allowed, but a number of classes do it 91 // The second case isn't really allowed, but a number of classes do it
84 // anyways. 92 // anyways.
85 EXPECT_TRUE(status_ == Status::CALLING_HANDLER || 93 EXPECT_TRUE(status_ == Status::CALLING_HANDLER ||
86 (result == false && status_ == Status::CANCELED)); 94 (result == false && status_ == Status::CANCELED));
87 if (!result) { 95 if (!result) {
96 // In the case of double-cancels, keep the old error code.
97 if (status_ != Status::CANCELED)
98 error_code_ = net::ERR_ABORTED;
88 status_ = Status::CANCELED; 99 status_ = Status::CANCELED;
89 } else if (defer) { 100 } else if (defer) {
90 status_ = Status::CALLBACK_PENDING; 101 status_ = Status::CALLBACK_PENDING;
91 } else { 102 } else {
92 status_ = Status::IDLE; 103 status_ = Status::IDLE;
93 } 104 }
94 return status_; 105 return status_;
95 } 106 }
96 107
97 MockResourceLoader::Status MockResourceLoader::OnWillRead(int min_size) { 108 MockResourceLoader::Status MockResourceLoader::OnWillRead(int min_size) {
98 EXPECT_EQ(Status::IDLE, status_); 109 EXPECT_EQ(Status::IDLE, status_);
99 EXPECT_FALSE(io_buffer_); 110 EXPECT_FALSE(io_buffer_);
100 EXPECT_EQ(0, io_buffer_size_); 111 EXPECT_EQ(0, io_buffer_size_);
101 112
102 status_ = Status::CALLING_HANDLER; 113 status_ = Status::CALLING_HANDLER;
103 114
104 bool result = 115 bool result =
105 resource_handler_->OnWillRead(&io_buffer_, &io_buffer_size_, min_size); 116 resource_handler_->OnWillRead(&io_buffer_, &io_buffer_size_, min_size);
106 // The second case isn't really allowed, but a number of classes do it 117 // The second case isn't really allowed, but a number of classes do it
107 // anyways. 118 // anyways.
108 EXPECT_TRUE(status_ == Status::CALLING_HANDLER || 119 EXPECT_TRUE(status_ == Status::CALLING_HANDLER ||
109 (result == false && status_ == Status::CANCELED)); 120 (result == false && status_ == Status::CANCELED));
110 if (!result) { 121 if (!result) {
122 // In the case of double-cancels, keep the old error code.
123 if (status_ != Status::CANCELED)
124 error_code_ = net::ERR_ABORTED;
111 EXPECT_EQ(0, io_buffer_size_); 125 EXPECT_EQ(0, io_buffer_size_);
112 EXPECT_FALSE(io_buffer_); 126 EXPECT_FALSE(io_buffer_);
113 status_ = Status::CANCELED; 127 status_ = Status::CANCELED;
114 } else { 128 } else {
115 EXPECT_LE(min_size, io_buffer_size_); 129 EXPECT_LE(min_size, io_buffer_size_);
116 EXPECT_LT(0, io_buffer_size_); 130 EXPECT_LT(0, io_buffer_size_);
117 EXPECT_TRUE(io_buffer_); 131 EXPECT_TRUE(io_buffer_);
118 status_ = Status::IDLE; 132 status_ = Status::IDLE;
119 } 133 }
120 return status_; 134 return status_;
(...skipping 10 matching lines...) Expand all
131 io_buffer_size_ = 0; 145 io_buffer_size_ = 0;
132 status_ = Status::CALLING_HANDLER; 146 status_ = Status::CALLING_HANDLER;
133 147
134 bool defer = false; 148 bool defer = false;
135 bool result = resource_handler_->OnReadCompleted(bytes.size(), &defer); 149 bool result = resource_handler_->OnReadCompleted(bytes.size(), &defer);
136 // The second case isn't really allowed, but a number of classes do it 150 // The second case isn't really allowed, but a number of classes do it
137 // anyways. 151 // anyways.
138 EXPECT_TRUE(status_ == Status::CALLING_HANDLER || 152 EXPECT_TRUE(status_ == Status::CALLING_HANDLER ||
139 (result == false && status_ == Status::CANCELED)); 153 (result == false && status_ == Status::CANCELED));
140 if (!result) { 154 if (!result) {
155 // In the case of double-cancels, keep the old error code.
156 if (status_ != Status::CANCELED)
157 error_code_ = net::ERR_ABORTED;
141 status_ = Status::CANCELED; 158 status_ = Status::CANCELED;
142 } else if (defer) { 159 } else if (defer) {
143 status_ = Status::CALLBACK_PENDING; 160 status_ = Status::CALLBACK_PENDING;
144 } else { 161 } else {
145 status_ = Status::IDLE; 162 status_ = Status::IDLE;
146 } 163 }
147 return status_; 164 return status_;
148 } 165 }
149 166
150 MockResourceLoader::Status MockResourceLoader::OnResponseCompleted( 167 MockResourceLoader::Status MockResourceLoader::OnResponseCompleted(
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } 246 }
230 247
231 void MockResourceLoader::Resume() { 248 void MockResourceLoader::Resume() {
232 EXPECT_EQ(Status::CALLBACK_PENDING, status_); 249 EXPECT_EQ(Status::CALLBACK_PENDING, status_);
233 status_ = Status::IDLE; 250 status_ = Status::IDLE;
234 if (canceled_or_idle_run_loop_) 251 if (canceled_or_idle_run_loop_)
235 canceled_or_idle_run_loop_->Quit(); 252 canceled_or_idle_run_loop_->Quit();
236 } 253 }
237 254
238 } // namespace content 255 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/mime_sniffing_resource_handler_unittest.cc ('k') | content/browser/loader/resource_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698