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

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

Issue 2449933003: Use Associated interfaces for mojo-loading (Closed)
Patch Set: fix Created 4 years, 1 month 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/url_loader_factory_impl.h" 5 #include "content/browser/loader/url_loader_factory_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 scoped_refptr<ResourceMessageFilter> resource_message_filter_; 129 scoped_refptr<ResourceMessageFilter> resource_message_filter_;
130 mojom::URLLoaderFactoryPtr factory_; 130 mojom::URLLoaderFactoryPtr factory_;
131 131
132 DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryImplTest); 132 DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryImplTest);
133 }; 133 };
134 134
135 TEST_P(URLLoaderFactoryImplTest, GetResponse) { 135 TEST_P(URLLoaderFactoryImplTest, GetResponse) {
136 constexpr int32_t kRoutingId = 81; 136 constexpr int32_t kRoutingId = 81;
137 constexpr int32_t kRequestId = 28; 137 constexpr int32_t kRequestId = 28;
138 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true); 138 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
139 mojom::URLLoaderPtr loader; 139 mojom::URLLoaderAssociatedPtr loader;
140 base::FilePath root; 140 base::FilePath root;
141 PathService::Get(DIR_TEST_DATA, &root); 141 PathService::Get(DIR_TEST_DATA, &root);
142 net::URLRequestMockHTTPJob::AddUrlHandlers(root, 142 net::URLRequestMockHTTPJob::AddUrlHandlers(root,
143 BrowserThread::GetBlockingPool()); 143 BrowserThread::GetBlockingPool());
144 ResourceRequest request; 144 ResourceRequest request;
145 TestURLLoaderClient client; 145 TestURLLoaderClient client;
146 // Assume the file contents is small enough to be stored in the data pipe. 146 // Assume the file contents is small enough to be stored in the data pipe.
147 request.url = net::URLRequestMockHTTPJob::GetMockUrl("hello.html"); 147 request.url = net::URLRequestMockHTTPJob::GetMockUrl("hello.html");
148 request.method = "GET"; 148 request.method = "GET";
149 request.is_main_frame = true; 149 request.is_main_frame = true;
150 factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), kRoutingId, 150 factory_->CreateLoaderAndStart(
151 kRequestId, request, 151 mojo::GetProxy(&loader, factory_.associated_group()), kRoutingId,
152 client.CreateInterfacePtrAndBind()); 152 kRequestId, request,
153 client.CreateRemoteAssociatedPtrInfo(factory_.associated_group()));
153 154
154 ASSERT_FALSE(client.has_received_response()); 155 ASSERT_FALSE(client.has_received_response());
155 ASSERT_FALSE(client.response_body().is_valid()); 156 ASSERT_FALSE(client.response_body().is_valid());
156 ASSERT_FALSE(client.has_received_completion()); 157 ASSERT_FALSE(client.has_received_completion());
157 158
158 client.RunUntilResponseReceived(); 159 client.RunUntilResponseReceived();
159 160
160 net::URLRequest* url_request = 161 net::URLRequest* url_request =
161 rdh_.GetURLRequest(GlobalRequestID(kChildId, kRequestId)); 162 rdh_.GetURLRequest(GlobalRequestID(kChildId, kRequestId));
162 ASSERT_TRUE(url_request); 163 ASSERT_TRUE(url_request);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 contents += std::string(buffer, read_size); 198 contents += std::string(buffer, read_size);
198 } 199 }
199 std::string expected; 200 std::string expected;
200 base::ReadFileToString( 201 base::ReadFileToString(
201 root.Append(base::FilePath(FILE_PATH_LITERAL("hello.html"))), &expected); 202 root.Append(base::FilePath(FILE_PATH_LITERAL("hello.html"))), &expected);
202 EXPECT_EQ(expected, contents); 203 EXPECT_EQ(expected, contents);
203 } 204 }
204 205
205 TEST_P(URLLoaderFactoryImplTest, GetFailedResponse) { 206 TEST_P(URLLoaderFactoryImplTest, GetFailedResponse) {
206 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true); 207 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
207 mojom::URLLoaderPtr loader; 208 mojom::URLLoaderAssociatedPtr loader;
208 ResourceRequest request; 209 ResourceRequest request;
209 TestURLLoaderClient client; 210 TestURLLoaderClient client;
210 net::URLRequestFailedJob::AddUrlHandler(); 211 net::URLRequestFailedJob::AddUrlHandler();
211 request.url = net::URLRequestFailedJob::GetMockHttpUrlWithFailurePhase( 212 request.url = net::URLRequestFailedJob::GetMockHttpUrlWithFailurePhase(
212 net::URLRequestFailedJob::START, net::ERR_TIMED_OUT); 213 net::URLRequestFailedJob::START, net::ERR_TIMED_OUT);
213 request.method = "GET"; 214 request.method = "GET";
214 factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), 2, 1, request, 215 factory_->CreateLoaderAndStart(
215 client.CreateInterfacePtrAndBind()); 216 mojo::GetProxy(&loader, factory_.associated_group()), 2, 1, request,
217 client.CreateRemoteAssociatedPtrInfo(factory_.associated_group()));
216 218
217 client.RunUntilComplete(); 219 client.RunUntilComplete();
218 ASSERT_FALSE(client.has_received_response()); 220 ASSERT_FALSE(client.has_received_response());
219 ASSERT_FALSE(client.response_body().is_valid()); 221 ASSERT_FALSE(client.response_body().is_valid());
220 222
221 EXPECT_EQ(net::ERR_TIMED_OUT, client.completion_status().error_code); 223 EXPECT_EQ(net::ERR_TIMED_OUT, client.completion_status().error_code);
222 } 224 }
223 225
224 // This test tests a case where resource loading is cancelled before started. 226 // This test tests a case where resource loading is cancelled before started.
225 TEST_P(URLLoaderFactoryImplTest, InvalidURL) { 227 TEST_P(URLLoaderFactoryImplTest, InvalidURL) {
226 mojom::URLLoaderPtr loader; 228 mojom::URLLoaderAssociatedPtr loader;
227 ResourceRequest request; 229 ResourceRequest request;
228 TestURLLoaderClient client; 230 TestURLLoaderClient client;
229 request.url = GURL(); 231 request.url = GURL();
230 request.method = "GET"; 232 request.method = "GET";
231 ASSERT_FALSE(request.url.is_valid()); 233 ASSERT_FALSE(request.url.is_valid());
232 factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), 2, 1, request, 234 factory_->CreateLoaderAndStart(
233 client.CreateInterfacePtrAndBind()); 235 mojo::GetProxy(&loader, factory_.associated_group()), 2, 1, request,
236 client.CreateRemoteAssociatedPtrInfo(factory_.associated_group()));
234 237
235 client.RunUntilComplete(); 238 client.RunUntilComplete();
236 ASSERT_FALSE(client.has_received_response()); 239 ASSERT_FALSE(client.has_received_response());
237 ASSERT_FALSE(client.response_body().is_valid()); 240 ASSERT_FALSE(client.response_body().is_valid());
238 241
239 EXPECT_EQ(net::ERR_ABORTED, client.completion_status().error_code); 242 EXPECT_EQ(net::ERR_ABORTED, client.completion_status().error_code);
240 } 243 }
241 244
242 // This test tests a case where resource loading is cancelled before started. 245 // This test tests a case where resource loading is cancelled before started.
243 TEST_P(URLLoaderFactoryImplTest, ShouldNotRequestURL) { 246 TEST_P(URLLoaderFactoryImplTest, ShouldNotRequestURL) {
244 mojom::URLLoaderPtr loader; 247 mojom::URLLoaderAssociatedPtr loader;
245 RejectingResourceDispatcherHostDelegate rdh_delegate; 248 RejectingResourceDispatcherHostDelegate rdh_delegate;
246 rdh_.SetDelegate(&rdh_delegate); 249 rdh_.SetDelegate(&rdh_delegate);
247 ResourceRequest request; 250 ResourceRequest request;
248 TestURLLoaderClient client; 251 TestURLLoaderClient client;
249 request.url = GURL("http://localhost/"); 252 request.url = GURL("http://localhost/");
250 request.method = "GET"; 253 request.method = "GET";
251 factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), 2, 1, request, 254 factory_->CreateLoaderAndStart(
252 client.CreateInterfacePtrAndBind()); 255 mojo::GetProxy(&loader, factory_.associated_group()), 2, 1, request,
256 client.CreateRemoteAssociatedPtrInfo(factory_.associated_group()));
253 257
254 client.RunUntilComplete(); 258 client.RunUntilComplete();
255 rdh_.SetDelegate(nullptr); 259 rdh_.SetDelegate(nullptr);
256 260
257 ASSERT_FALSE(client.has_received_response()); 261 ASSERT_FALSE(client.has_received_response());
258 ASSERT_FALSE(client.response_body().is_valid()); 262 ASSERT_FALSE(client.response_body().is_valid());
259 263
260 EXPECT_EQ(net::ERR_ABORTED, client.completion_status().error_code); 264 EXPECT_EQ(net::ERR_ABORTED, client.completion_status().error_code);
261 } 265 }
262 266
263 INSTANTIATE_TEST_CASE_P(URLLoaderFactoryImplTest, 267 INSTANTIATE_TEST_CASE_P(URLLoaderFactoryImplTest,
264 URLLoaderFactoryImplTest, 268 URLLoaderFactoryImplTest,
265 ::testing::Values(128, 32 * 1024)); 269 ::testing::Values(128, 32 * 1024));
266 270
267 } // namespace 271 } // namespace
268 272
269 } // namespace content 273 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698