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

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

Issue 2574143003: Implement upload progress handling in Mojo loading (Closed)
Patch Set: android build fix 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/mojo_async_resource_handler.h" 5 #include "content/browser/loader/mojo_async_resource_handler.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/test/test_simple_task_runner.h"
18 #include "content/browser/loader/mock_resource_loader.h" 19 #include "content/browser/loader/mock_resource_loader.h"
19 #include "content/browser/loader/resource_controller.h" 20 #include "content/browser/loader/resource_controller.h"
20 #include "content/browser/loader/resource_dispatcher_host_impl.h" 21 #include "content/browser/loader/resource_dispatcher_host_impl.h"
21 #include "content/browser/loader/resource_request_info_impl.h" 22 #include "content/browser/loader/resource_request_info_impl.h"
22 #include "content/browser/loader/test_url_loader_client.h" 23 #include "content/browser/loader/test_url_loader_client.h"
23 #include "content/common/resource_request_completion_status.h" 24 #include "content/common/resource_request_completion_status.h"
24 #include "content/common/url_loader.mojom.h" 25 #include "content/common/url_loader.mojom.h"
25 #include "content/public/browser/appcache_service.h" 26 #include "content/public/browser/appcache_service.h"
26 #include "content/public/browser/navigation_data.h" 27 #include "content/public/browser/navigation_data.h"
27 #include "content/public/browser/resource_context.h" 28 #include "content/public/browser/resource_context.h"
28 #include "content/public/browser/resource_dispatcher_host_delegate.h" 29 #include "content/public/browser/resource_dispatcher_host_delegate.h"
29 #include "content/public/browser/resource_throttle.h" 30 #include "content/public/browser/resource_throttle.h"
30 #include "content/public/browser/stream_info.h" 31 #include "content/public/browser/stream_info.h"
31 #include "content/public/common/previews_state.h" 32 #include "content/public/common/previews_state.h"
32 #include "content/public/common/resource_response.h" 33 #include "content/public/common/resource_response.h"
33 #include "content/public/common/resource_type.h" 34 #include "content/public/common/resource_type.h"
34 #include "content/public/test/test_browser_context.h" 35 #include "content/public/test/test_browser_context.h"
35 #include "content/public/test/test_browser_thread_bundle.h" 36 #include "content/public/test/test_browser_thread_bundle.h"
36 #include "mojo/public/c/system/data_pipe.h" 37 #include "mojo/public/c/system/data_pipe.h"
37 #include "mojo/public/c/system/types.h" 38 #include "mojo/public/c/system/types.h"
38 #include "mojo/public/cpp/bindings/strong_binding.h" 39 #include "mojo/public/cpp/bindings/strong_binding.h"
39 #include "mojo/public/cpp/system/data_pipe.h" 40 #include "mojo/public/cpp/system/data_pipe.h"
40 #include "net/base/auth.h" 41 #include "net/base/auth.h"
41 #include "net/base/net_errors.h" 42 #include "net/base/net_errors.h"
42 #include "net/http/http_response_headers.h" 43 #include "net/http/http_response_headers.h"
43 #include "net/http/http_response_info.h" 44 #include "net/http/http_response_info.h"
44 #include "net/http/http_status_code.h" 45 #include "net/http/http_status_code.h"
45 #include "net/http/http_util.h" 46 #include "net/http/http_util.h"
46 #include "net/ssl/client_cert_store.h" 47 #include "net/ssl/client_cert_store.h"
48 #include "net/test/url_request/url_request_mock_data_job.h"
47 #include "net/url_request/url_request.h" 49 #include "net/url_request/url_request.h"
48 #include "net/url_request/url_request_context.h" 50 #include "net/url_request/url_request_context.h"
49 #include "net/url_request/url_request_status.h" 51 #include "net/url_request/url_request_status.h"
50 #include "net/url_request/url_request_test_util.h" 52 #include "net/url_request/url_request_test_util.h"
51 #include "testing/gtest/include/gtest/gtest.h" 53 #include "testing/gtest/include/gtest/gtest.h"
52 #include "ui/base/page_transition_types.h" 54 #include "ui/base/page_transition_types.h"
53 55
54 namespace content { 56 namespace content {
55 namespace { 57 namespace {
56 58
57 constexpr int kSizeMimeSnifferRequiresForFirstOnWillRead = 2048; 59 constexpr int kSizeMimeSnifferRequiresForFirstOnWillRead = 2048;
58 60
61 class DummyUploadDataStream : public net::UploadDataStream {
62 public:
63 DummyUploadDataStream() : UploadDataStream(false, 0) {}
64
65 int InitInternal(const net::NetLogWithSource& net_log) override {
66 NOTREACHED();
67 return 0;
68 }
69 int ReadInternal(net::IOBuffer* buf, int buf_len) override {
70 NOTREACHED();
71 return 0;
72 }
73 void ResetInternal() override { NOTREACHED(); }
mmenke 2017/01/19 16:06:49 nit: include base/logging.h
tzik 2017/01/20 04:42:03 Done.
74
75 private:
76 DISALLOW_COPY_AND_ASSIGN(DummyUploadDataStream);
mmenke 2017/01/19 16:06:49 include base/macros.h
tzik 2017/01/20 04:42:03 Done.
77 };
78
79 class FakeUploadProgressTracker : public UploadProgressTracker {
80 public:
81 using UploadProgressTracker::UploadProgressTracker;
82
83 net::UploadProgress GetUploadProgress() const override {
84 return upload_progress_;
85 }
86 base::TimeTicks GetCurrentTime() const override { return current_time_; }
87
88 net::UploadProgress upload_progress_;
89 base::TimeTicks current_time_;
mmenke 2017/01/19 16:06:49 private: DISALLOW_COPY_AND_ASSIGN?
tzik 2017/01/20 04:42:03 Done.
90 };
91
59 class TestResourceDispatcherHostDelegate final 92 class TestResourceDispatcherHostDelegate final
60 : public ResourceDispatcherHostDelegate { 93 : public ResourceDispatcherHostDelegate {
61 public: 94 public:
62 TestResourceDispatcherHostDelegate() = default; 95 TestResourceDispatcherHostDelegate() = default;
63 ~TestResourceDispatcherHostDelegate() override { 96 ~TestResourceDispatcherHostDelegate() override {
64 EXPECT_EQ(num_on_response_started_calls_expectation_, 97 EXPECT_EQ(num_on_response_started_calls_expectation_,
65 num_on_response_started_calls_); 98 num_on_response_started_calls_);
66 } 99 }
67 100
68 bool ShouldBeginRequest(const std::string& method, 101 bool ShouldBeginRequest(const std::string& method,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 : public MojoAsyncResourceHandler { 212 : public MojoAsyncResourceHandler {
180 public: 213 public:
181 MojoAsyncResourceHandlerWithStubOperations( 214 MojoAsyncResourceHandlerWithStubOperations(
182 net::URLRequest* request, 215 net::URLRequest* request,
183 ResourceDispatcherHostImpl* rdh, 216 ResourceDispatcherHostImpl* rdh,
184 mojom::URLLoaderAssociatedRequest mojo_request, 217 mojom::URLLoaderAssociatedRequest mojo_request,
185 mojom::URLLoaderClientAssociatedPtr url_loader_client) 218 mojom::URLLoaderClientAssociatedPtr url_loader_client)
186 : MojoAsyncResourceHandler(request, 219 : MojoAsyncResourceHandler(request,
187 rdh, 220 rdh,
188 std::move(mojo_request), 221 std::move(mojo_request),
189 std::move(url_loader_client)) {} 222 std::move(url_loader_client)),
223 task_runner_(new base::TestSimpleTaskRunner) {}
190 ~MojoAsyncResourceHandlerWithStubOperations() override {} 224 ~MojoAsyncResourceHandlerWithStubOperations() override {}
191 225
192 void ResetBeginWriteExpectation() { is_begin_write_expectation_set_ = false; } 226 void ResetBeginWriteExpectation() { is_begin_write_expectation_set_ = false; }
193 227
194 void set_begin_write_expectation(MojoResult begin_write_expectation) { 228 void set_begin_write_expectation(MojoResult begin_write_expectation) {
195 is_begin_write_expectation_set_ = true; 229 is_begin_write_expectation_set_ = true;
196 begin_write_expectation_ = begin_write_expectation; 230 begin_write_expectation_ = begin_write_expectation;
197 } 231 }
198 void set_end_write_expectation(MojoResult end_write_expectation) { 232 void set_end_write_expectation(MojoResult end_write_expectation) {
199 is_end_write_expectation_set_ = true; 233 is_end_write_expectation_set_ = true;
200 end_write_expectation_ = end_write_expectation; 234 end_write_expectation_ = end_write_expectation;
201 } 235 }
202 bool has_received_bad_message() const { return has_received_bad_message_; } 236 bool has_received_bad_message() const { return has_received_bad_message_; }
203 void SetMetadata(scoped_refptr<net::IOBufferWithSize> metadata) { 237 void SetMetadata(scoped_refptr<net::IOBufferWithSize> metadata) {
204 metadata_ = std::move(metadata); 238 metadata_ = std::move(metadata);
205 } 239 }
206 240
241 FakeUploadProgressTracker* upload_progress_tracker() const {
242 return upload_progress_tracker_;
243 }
244
245 void PollUploadProgress() {
246 task_runner_->RunPendingTasks();
247 base::RunLoop().RunUntilIdle();
248 }
249
207 private: 250 private:
208 MojoResult BeginWrite(void** data, uint32_t* available) override { 251 MojoResult BeginWrite(void** data, uint32_t* available) override {
209 if (is_begin_write_expectation_set_) 252 if (is_begin_write_expectation_set_)
210 return begin_write_expectation_; 253 return begin_write_expectation_;
211 return MojoAsyncResourceHandler::BeginWrite(data, available); 254 return MojoAsyncResourceHandler::BeginWrite(data, available);
212 } 255 }
213 MojoResult EndWrite(uint32_t written) override { 256 MojoResult EndWrite(uint32_t written) override {
214 if (is_end_write_expectation_set_) 257 if (is_end_write_expectation_set_)
215 return end_write_expectation_; 258 return end_write_expectation_;
216 return MojoAsyncResourceHandler::EndWrite(written); 259 return MojoAsyncResourceHandler::EndWrite(written);
217 } 260 }
218 net::IOBufferWithSize* GetResponseMetadata( 261 net::IOBufferWithSize* GetResponseMetadata(
219 net::URLRequest* request) override { 262 net::URLRequest* request) override {
220 return metadata_.get(); 263 return metadata_.get();
221 } 264 }
222 265
223 void ReportBadMessage(const std::string& error) override { 266 void ReportBadMessage(const std::string& error) override {
224 has_received_bad_message_ = true; 267 has_received_bad_message_ = true;
225 } 268 }
226 269
270 std::unique_ptr<UploadProgressTracker> CreateUploadProgressTracker(
271 const tracked_objects::Location& from_here,
272 UploadProgressTracker::UploadProgressReportCallback callback) override {
273 DCHECK(!upload_progress_tracker_);
274
275 auto upload_progress_tracker = base::MakeUnique<FakeUploadProgressTracker>(
276 from_here, std::move(callback), request(), task_runner_);
277 upload_progress_tracker_ = upload_progress_tracker.get();
278 return std::move(upload_progress_tracker);
279 }
280
227 bool is_begin_write_expectation_set_ = false; 281 bool is_begin_write_expectation_set_ = false;
228 bool is_end_write_expectation_set_ = false; 282 bool is_end_write_expectation_set_ = false;
229 bool has_received_bad_message_ = false; 283 bool has_received_bad_message_ = false;
230 MojoResult begin_write_expectation_ = MOJO_RESULT_UNKNOWN; 284 MojoResult begin_write_expectation_ = MOJO_RESULT_UNKNOWN;
231 MojoResult end_write_expectation_ = MOJO_RESULT_UNKNOWN; 285 MojoResult end_write_expectation_ = MOJO_RESULT_UNKNOWN;
232 scoped_refptr<net::IOBufferWithSize> metadata_; 286 scoped_refptr<net::IOBufferWithSize> metadata_;
233 287
288 FakeUploadProgressTracker* upload_progress_tracker_ = nullptr;
289 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
290
234 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandlerWithStubOperations); 291 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandlerWithStubOperations);
235 }; 292 };
236 293
237 class TestURLLoaderFactory final : public mojom::URLLoaderFactory { 294 class TestURLLoaderFactory final : public mojom::URLLoaderFactory {
238 public: 295 public:
239 TestURLLoaderFactory() {} 296 TestURLLoaderFactory() {}
240 ~TestURLLoaderFactory() override {} 297 ~TestURLLoaderFactory() override {}
241 298
242 void CreateLoaderAndStart( 299 void CreateLoaderAndStart(
243 mojom::URLLoaderAssociatedRequest request, 300 mojom::URLLoaderAssociatedRequest request,
(...skipping 22 matching lines...) Expand all
266 323
267 private: 324 private:
268 mojom::URLLoaderAssociatedRequest loader_request_; 325 mojom::URLLoaderAssociatedRequest loader_request_;
269 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info_; 326 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info_;
270 327
271 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderFactory); 328 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderFactory);
272 }; 329 };
273 330
274 class MojoAsyncResourceHandlerTestBase { 331 class MojoAsyncResourceHandlerTestBase {
275 public: 332 public:
276 MojoAsyncResourceHandlerTestBase() 333 explicit MojoAsyncResourceHandlerTestBase(
334 std::unique_ptr<net::UploadDataStream> upload_stream)
277 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), 335 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
278 browser_context_(new TestBrowserContext()) { 336 browser_context_(new TestBrowserContext()) {
279 MojoAsyncResourceHandler::SetAllocationSizeForTesting(32 * 1024); 337 MojoAsyncResourceHandler::SetAllocationSizeForTesting(32 * 1024);
280 rdh_.SetDelegate(&rdh_delegate_); 338 rdh_.SetDelegate(&rdh_delegate_);
281 339
282 // Create and initialize |request_|. None of this matters, for these tests, 340 // Create and initialize |request_|. None of this matters, for these tests,
283 // just need something non-NULL. 341 // just need something non-NULL.
284 net::URLRequestContext* request_context = 342 net::URLRequestContext* request_context =
285 browser_context_->GetResourceContext()->GetRequestContext(); 343 browser_context_->GetResourceContext()->GetRequestContext();
286 request_ = request_context->CreateRequest( 344 request_ = request_context->CreateRequest(
287 GURL("http://foo/"), net::DEFAULT_PRIORITY, &url_request_delegate_); 345 GURL("http://foo/"), net::DEFAULT_PRIORITY, &url_request_delegate_);
346 request_->set_upload(std::move(upload_stream));
288 ResourceRequestInfo::AllocateForTesting( 347 ResourceRequestInfo::AllocateForTesting(
289 request_.get(), // request 348 request_.get(), // request
290 RESOURCE_TYPE_XHR, // resource_type 349 RESOURCE_TYPE_XHR, // resource_type
291 browser_context_->GetResourceContext(), // context 350 browser_context_->GetResourceContext(), // context
292 2, // render_process_id 351 2, // render_process_id
293 0, // render_view_id 352 0, // render_view_id
294 0, // render_frame_id 353 0, // render_frame_id
295 true, // is_main_frame 354 true, // is_main_frame
296 false, // parent_is_main_frame 355 false, // parent_is_main_frame
297 false, // allow_download 356 false, // allow_download
(...skipping 25 matching lines...) Expand all
323 mock_loader_.reset(new MockResourceLoader(handler_.get())); 382 mock_loader_.reset(new MockResourceLoader(handler_.get()));
324 } 383 }
325 384
326 virtual ~MojoAsyncResourceHandlerTestBase() { 385 virtual ~MojoAsyncResourceHandlerTestBase() {
327 MojoAsyncResourceHandler::SetAllocationSizeForTesting( 386 MojoAsyncResourceHandler::SetAllocationSizeForTesting(
328 MojoAsyncResourceHandler::kDefaultAllocationSize); 387 MojoAsyncResourceHandler::kDefaultAllocationSize);
329 base::RunLoop().RunUntilIdle(); 388 base::RunLoop().RunUntilIdle();
330 } 389 }
331 390
332 // Returns false if something bad happens. 391 // Returns false if something bad happens.
333 bool CallOnWillStartAndOnResponseStarted() { 392 bool CallOnWillStart() {
334 rdh_delegate_.set_num_on_response_started_calls_expectation(1);
335 MockResourceLoader::Status result = 393 MockResourceLoader::Status result =
336 mock_loader_->OnWillStart(request_->url()); 394 mock_loader_->OnWillStart(request_->url());
337 EXPECT_EQ(MockResourceLoader::Status::IDLE, result); 395 EXPECT_EQ(MockResourceLoader::Status::IDLE, result);
338 if (result != MockResourceLoader::Status::IDLE) 396 return result == MockResourceLoader::Status::IDLE;
339 return false; 397 }
340 398
341 result = mock_loader_->OnResponseStarted( 399 // Returns false if something bad happens.
400 bool CallOnResponseStarted() {
401 rdh_delegate_.set_num_on_response_started_calls_expectation(1);
402 MockResourceLoader::Status result = mock_loader_->OnResponseStarted(
342 make_scoped_refptr(new ResourceResponse())); 403 make_scoped_refptr(new ResourceResponse()));
343 EXPECT_EQ(MockResourceLoader::Status::IDLE, result); 404 EXPECT_EQ(MockResourceLoader::Status::IDLE, result);
344 if (result != MockResourceLoader::Status::IDLE) 405 if (result != MockResourceLoader::Status::IDLE)
345 return false; 406 return false;
346 407
347 if (url_loader_client_.has_received_response()) { 408 if (url_loader_client_.has_received_response()) {
348 ADD_FAILURE() << "URLLoaderClient unexpectedly gets a response."; 409 ADD_FAILURE() << "URLLoaderClient unexpectedly gets a response.";
349 return false; 410 return false;
350 } 411 }
351 url_loader_client_.RunUntilResponseReceived(); 412 url_loader_client_.RunUntilResponseReceived();
352 return true; 413 return true;
353 } 414 }
354 415
416 // Returns false if something bad happens.
417 bool CallOnWillStartAndOnResponseStarted() {
418 return CallOnWillStart() && CallOnResponseStarted();
419 }
420
421 void set_upload_progress(const net::UploadProgress& upload_progress) {
422 handler_->upload_progress_tracker()->upload_progress_ = upload_progress;
423 }
424 void AdvanceCurrentTime(const base::TimeDelta& delta) {
425 handler_->upload_progress_tracker()->current_time_ += delta;
426 }
427
355 TestBrowserThreadBundle thread_bundle_; 428 TestBrowserThreadBundle thread_bundle_;
356 TestResourceDispatcherHostDelegate rdh_delegate_; 429 TestResourceDispatcherHostDelegate rdh_delegate_;
357 ResourceDispatcherHostImpl rdh_; 430 ResourceDispatcherHostImpl rdh_;
358 mojom::URLLoaderFactoryPtr url_loader_factory_; 431 mojom::URLLoaderFactoryPtr url_loader_factory_;
359 mojom::URLLoaderAssociatedPtr url_loader_proxy_; 432 mojom::URLLoaderAssociatedPtr url_loader_proxy_;
360 TestURLLoaderClient url_loader_client_; 433 TestURLLoaderClient url_loader_client_;
361 std::unique_ptr<TestBrowserContext> browser_context_; 434 std::unique_ptr<TestBrowserContext> browser_context_;
362 net::TestDelegate url_request_delegate_; 435 net::TestDelegate url_request_delegate_;
363 std::unique_ptr<net::URLRequest> request_; 436 std::unique_ptr<net::URLRequest> request_;
364 std::unique_ptr<MojoAsyncResourceHandlerWithStubOperations> handler_; 437 std::unique_ptr<MojoAsyncResourceHandlerWithStubOperations> handler_;
365 std::unique_ptr<MockResourceLoader> mock_loader_; 438 std::unique_ptr<MockResourceLoader> mock_loader_;
366 439
367 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandlerTestBase); 440 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandlerTestBase);
368 }; 441 };
369 442
370 class MojoAsyncResourceHandlerTest : public MojoAsyncResourceHandlerTestBase, 443 class MojoAsyncResourceHandlerTest : public MojoAsyncResourceHandlerTestBase,
371 public ::testing::Test {}; 444 public ::testing::Test {
445 protected:
446 MojoAsyncResourceHandlerTest() : MojoAsyncResourceHandlerTestBase(nullptr) {}
447 };
372 448
373 // This test class is parameterized with MojoAsyncResourceHandler's allocation 449 // This test class is parameterized with MojoAsyncResourceHandler's allocation
374 // size. 450 // size.
375 class MojoAsyncResourceHandlerWithAllocationSizeTest 451 class MojoAsyncResourceHandlerWithAllocationSizeTest
376 : public MojoAsyncResourceHandlerTestBase, 452 : public MojoAsyncResourceHandlerTestBase,
377 public ::testing::TestWithParam<size_t> { 453 public ::testing::TestWithParam<size_t> {
378 protected: 454 protected:
379 MojoAsyncResourceHandlerWithAllocationSizeTest() { 455 MojoAsyncResourceHandlerWithAllocationSizeTest()
456 : MojoAsyncResourceHandlerTestBase(nullptr) {
380 MojoAsyncResourceHandler::SetAllocationSizeForTesting(GetParam()); 457 MojoAsyncResourceHandler::SetAllocationSizeForTesting(GetParam());
381 } 458 }
382 }; 459 };
383 460
461 class MojoAsyncResourceHandlerUploadTest
462 : public MojoAsyncResourceHandlerTestBase,
463 public ::testing::Test {
464 protected:
465 MojoAsyncResourceHandlerUploadTest()
466 : MojoAsyncResourceHandlerTestBase(
467 base::MakeUnique<DummyUploadDataStream>()) {}
468 };
469
384 TEST_F(MojoAsyncResourceHandlerTest, InFlightRequests) { 470 TEST_F(MojoAsyncResourceHandlerTest, InFlightRequests) {
385 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing()); 471 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing());
386 handler_ = nullptr; 472 handler_ = nullptr;
387 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing()); 473 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing());
388 } 474 }
389 475
390 TEST_F(MojoAsyncResourceHandlerTest, OnWillStart) { 476 TEST_F(MojoAsyncResourceHandlerTest, OnWillStart) {
391 EXPECT_EQ(MockResourceLoader::Status::IDLE, 477 EXPECT_EQ(MockResourceLoader::Status::IDLE,
392 mock_loader_->OnWillStart(request_->url())); 478 mock_loader_->OnWillStart(request_->url()));
393 } 479 }
(...skipping 27 matching lines...) Expand all
421 507
422 url_loader_client_.RunUntilResponseReceived(); 508 url_loader_client_.RunUntilResponseReceived();
423 EXPECT_EQ(response->head.request_start, 509 EXPECT_EQ(response->head.request_start,
424 url_loader_client_.response_head().request_start); 510 url_loader_client_.response_head().request_start);
425 EXPECT_EQ(response->head.response_start, 511 EXPECT_EQ(response->head.response_start,
426 url_loader_client_.response_head().response_start); 512 url_loader_client_.response_head().response_start);
427 EXPECT_EQ(99, url_loader_client_.response_head().content_length); 513 EXPECT_EQ(99, url_loader_client_.response_head().content_length);
428 514
429 url_loader_client_.RunUntilCachedMetadataReceived(); 515 url_loader_client_.RunUntilCachedMetadataReceived();
430 EXPECT_EQ("hello", url_loader_client_.cached_metadata()); 516 EXPECT_EQ("hello", url_loader_client_.cached_metadata());
517
518 EXPECT_FALSE(url_loader_client_.has_received_upload_progress());
431 } 519 }
432 520
433 TEST_F(MojoAsyncResourceHandlerTest, OnWillReadAndInFlightRequests) { 521 TEST_F(MojoAsyncResourceHandlerTest, OnWillReadAndInFlightRequests) {
434 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 522 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
435 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing()); 523 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing());
436 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 524 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
437 EXPECT_EQ(1, rdh_.num_in_flight_requests_for_testing()); 525 EXPECT_EQ(1, rdh_.num_in_flight_requests_for_testing());
438 handler_ = nullptr; 526 handler_ = nullptr;
439 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing()); 527 EXPECT_EQ(0, rdh_.num_in_flight_requests_for_testing());
440 } 528 }
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 ASSERT_EQ(MOJO_RESULT_OK, result); 879 ASSERT_EQ(MOJO_RESULT_OK, result);
792 } 880 }
793 881
794 handler_->set_end_write_expectation(MOJO_RESULT_SHOULD_WAIT); 882 handler_->set_end_write_expectation(MOJO_RESULT_SHOULD_WAIT);
795 mock_loader_->WaitUntilIdleOrCanceled(); 883 mock_loader_->WaitUntilIdleOrCanceled();
796 EXPECT_FALSE(url_loader_client_.has_received_completion()); 884 EXPECT_FALSE(url_loader_client_.has_received_completion());
797 EXPECT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->status()); 885 EXPECT_EQ(MockResourceLoader::Status::CANCELED, mock_loader_->status());
798 EXPECT_EQ(net::ERR_FAILED, mock_loader_->error_code()); 886 EXPECT_EQ(net::ERR_FAILED, mock_loader_->error_code());
799 } 887 }
800 888
889 TEST_F(MojoAsyncResourceHandlerUploadTest, UploadProgressHandling) {
890 ASSERT_TRUE(CallOnWillStart());
891
892 // Expect no report for no progress.
893 set_upload_progress(net::UploadProgress(0, 1000));
894 handler_->PollUploadProgress();
895 EXPECT_FALSE(url_loader_client_.has_received_upload_progress());
896 EXPECT_EQ(0, url_loader_client_.current_upload_position());
897 EXPECT_EQ(0, url_loader_client_.total_upload_size());
898
899 // Expect a upload progress report for a good amount of progress.
900 url_loader_client_.reset_has_received_upload_progress();
901 set_upload_progress(net::UploadProgress(100, 1000));
902 handler_->PollUploadProgress();
903 EXPECT_TRUE(url_loader_client_.has_received_upload_progress());
904 EXPECT_EQ(100, url_loader_client_.current_upload_position());
905 EXPECT_EQ(1000, url_loader_client_.total_upload_size());
906
907 // Expect a upload progress report for the passed time.
908 url_loader_client_.reset_has_received_upload_progress();
909 set_upload_progress(net::UploadProgress(101, 1000));
910 AdvanceCurrentTime(base::TimeDelta::FromSeconds(5));
911 handler_->PollUploadProgress();
912 EXPECT_TRUE(url_loader_client_.has_received_upload_progress());
913 EXPECT_EQ(101, url_loader_client_.current_upload_position());
914 EXPECT_EQ(1000, url_loader_client_.total_upload_size());
915
916 // A redirect rewinds the upload progress. Expect no report for the rewound
917 // progress.
mmenke 2017/01/19 16:06:49 Oops, sorry...When I said rewind, I actually mean
918 url_loader_client_.reset_has_received_upload_progress();
919 set_upload_progress(net::UploadProgress(0, 1000));
920 AdvanceCurrentTime(base::TimeDelta::FromSeconds(5));
921 handler_->PollUploadProgress();
922 EXPECT_FALSE(url_loader_client_.has_received_upload_progress());
923
924 // Set the progress to almost-finished state to prepare for the completion
925 // report below.
926 url_loader_client_.reset_has_received_upload_progress();
927 set_upload_progress(net::UploadProgress(999, 1000));
928 handler_->PollUploadProgress();
929 EXPECT_TRUE(url_loader_client_.has_received_upload_progress());
930 EXPECT_EQ(999, url_loader_client_.current_upload_position());
931 EXPECT_EQ(1000, url_loader_client_.total_upload_size());
932
933 // Expect a upload progress report for the upload completion.
934 url_loader_client_.reset_has_received_upload_progress();
935 set_upload_progress(net::UploadProgress(1000, 1000));
936 ASSERT_TRUE(CallOnResponseStarted());
937 EXPECT_TRUE(url_loader_client_.has_received_upload_progress());
938 EXPECT_EQ(1000, url_loader_client_.current_upload_position());
939 EXPECT_EQ(1000, url_loader_client_.total_upload_size());
940 }
941
801 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest, 942 TEST_P(MojoAsyncResourceHandlerWithAllocationSizeTest,
802 OnWillReadWithLongContents) { 943 OnWillReadWithLongContents) {
803 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted()); 944 ASSERT_TRUE(CallOnWillStartAndOnResponseStarted());
804 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1)); 945 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnWillRead(-1));
805 std::string expected; 946 std::string expected;
806 for (int i = 0; i < 3 * mock_loader_->io_buffer_size() + 2; ++i) 947 for (int i = 0; i < 3 * mock_loader_->io_buffer_size() + 2; ++i)
807 expected += ('A' + i % 26); 948 expected += ('A' + i % 26);
808 949
809 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnReadCompleted(0)); 950 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader_->OnReadCompleted(0));
810 951
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 } 1256 }
1116 } 1257 }
1117 EXPECT_EQ("B", body); 1258 EXPECT_EQ("B", body);
1118 } 1259 }
1119 1260
1120 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest, 1261 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest,
1121 MojoAsyncResourceHandlerWithAllocationSizeTest, 1262 MojoAsyncResourceHandlerWithAllocationSizeTest,
1122 ::testing::Values(8, 32 * 2014)); 1263 ::testing::Values(8, 32 * 2014));
1123 } // namespace 1264 } // namespace
1124 } // namespace content 1265 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698