OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/mime_sniffing_resource_handler.h" | 5 #include "content/browser/loader/mime_sniffing_resource_handler.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 360 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
361 response->head.mime_type.assign("text/plain"); | 361 response->head.mime_type.assign("text/plain"); |
362 | 362 |
363 // Simulate the response starting. The MimeSniffingHandler should start | 363 // Simulate the response starting. The MimeSniffingHandler should start |
364 // buffering, so the return value should always be true. | 364 // buffering, so the return value should always be true. |
365 ASSERT_EQ(MockResourceLoader::Status::IDLE, | 365 ASSERT_EQ(MockResourceLoader::Status::IDLE, |
366 mock_loader.OnResponseStarted(std::move(response))); | 366 mock_loader.OnResponseStarted(std::move(response))); |
367 | 367 |
368 // Read some data to sniff the mime type. This will ask the next | 368 // Read some data to sniff the mime type. This will ask the next |
369 // ResourceHandler for a buffer. | 369 // ResourceHandler for a buffer. |
370 mock_loader.OnWillRead(-1); | 370 mock_loader.OnWillRead(); |
371 | 371 |
372 if (!will_read) { | 372 if (!will_read) { |
373 EXPECT_EQ(MockResourceLoader::Status::CANCELED, mock_loader.status()); | 373 EXPECT_EQ(MockResourceLoader::Status::CANCELED, mock_loader.status()); |
374 EXPECT_EQ(net::ERR_ABORTED, mock_loader.error_code()); | 374 EXPECT_EQ(net::ERR_ABORTED, mock_loader.error_code()); |
375 | 375 |
376 EXPECT_EQ(1, test_handler->on_will_start_called()); | 376 EXPECT_EQ(1, test_handler->on_will_start_called()); |
377 EXPECT_EQ(0, test_handler->on_request_redirected_called()); | 377 EXPECT_EQ(0, test_handler->on_request_redirected_called()); |
378 EXPECT_EQ(0, test_handler->on_response_started_called()); | 378 EXPECT_EQ(0, test_handler->on_response_started_called()); |
379 EXPECT_EQ(1, test_handler->on_will_read_called()); | 379 EXPECT_EQ(1, test_handler->on_will_read_called()); |
380 EXPECT_EQ(0, test_handler->on_read_completed_called()); | 380 EXPECT_EQ(0, test_handler->on_read_completed_called()); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 mime_sniffing_handler.state_); | 536 mime_sniffing_handler.state_); |
537 test_handler->Resume(); | 537 test_handler->Resume(); |
538 // MimeSniffingResourceHandler may not synchronously resume the request. | 538 // MimeSniffingResourceHandler may not synchronously resume the request. |
539 base::RunLoop().RunUntilIdle(); | 539 base::RunLoop().RunUntilIdle(); |
540 } | 540 } |
541 | 541 |
542 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader.status()); | 542 ASSERT_EQ(MockResourceLoader::Status::IDLE, mock_loader.status()); |
543 | 543 |
544 // The MimeSniffingResourceHandler should be acting as a pass-through | 544 // The MimeSniffingResourceHandler should be acting as a pass-through |
545 // ResourceHandler. | 545 // ResourceHandler. |
546 mock_loader.OnWillRead(-1); | 546 mock_loader.OnWillRead(); |
547 | 547 |
548 if (!will_read) { | 548 if (!will_read) { |
549 EXPECT_EQ(MockResourceLoader::Status::CANCELED, mock_loader.status()); | 549 EXPECT_EQ(MockResourceLoader::Status::CANCELED, mock_loader.status()); |
550 EXPECT_EQ(net::ERR_ABORTED, mock_loader.error_code()); | 550 EXPECT_EQ(net::ERR_ABORTED, mock_loader.error_code()); |
551 | 551 |
552 EXPECT_EQ(1, test_handler->on_will_start_called()); | 552 EXPECT_EQ(1, test_handler->on_will_start_called()); |
553 EXPECT_EQ(0, test_handler->on_request_redirected_called()); | 553 EXPECT_EQ(0, test_handler->on_request_redirected_called()); |
554 EXPECT_EQ(1, test_handler->on_response_started_called()); | 554 EXPECT_EQ(1, test_handler->on_response_started_called()); |
555 EXPECT_EQ(1, test_handler->on_will_read_called()); | 555 EXPECT_EQ(1, test_handler->on_will_read_called()); |
556 EXPECT_EQ(0, test_handler->on_read_completed_called()); | 556 EXPECT_EQ(0, test_handler->on_read_completed_called()); |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 // on OnResponseStarted. | 952 // on OnResponseStarted. |
953 EXPECT_EQ(MockResourceLoader::Status::CANCELED, | 953 EXPECT_EQ(MockResourceLoader::Status::CANCELED, |
954 mock_loader.OnResponseStarted(std::move(response))); | 954 mock_loader.OnResponseStarted(std::move(response))); |
955 EXPECT_EQ(net::ERR_ABORTED, mock_loader.error_code()); | 955 EXPECT_EQ(net::ERR_ABORTED, mock_loader.error_code()); |
956 | 956 |
957 // Process all messages to ensure proper test teardown. | 957 // Process all messages to ensure proper test teardown. |
958 content::RunAllPendingInMessageLoop(); | 958 content::RunAllPendingInMessageLoop(); |
959 } | 959 } |
960 | 960 |
961 } // namespace content | 961 } // namespace content |
OLD | NEW |