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

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

Powered by Google App Engine
This is Rietveld 408576698