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

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 2150913002: Update URLRequestTestHTTP.GetZippedTest test assertions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self review Created 4 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 4612 matching lines...) Expand 10 before | Expand all | Expand 10 after
4623 // M - Medium length (between C & U). 4623 // M - Medium length (between C & U).
4624 // S - Small length (smaller than both C & U). 4624 // S - Small length (smaller than both C & U).
4625 const char test_parameters[] = "CULMS"; 4625 const char test_parameters[] = "CULMS";
4626 const int num_tests = arraysize(test_parameters)- 1; // Skip NULL. 4626 const int num_tests = arraysize(test_parameters)- 1; // Skip NULL.
4627 // C & U should be OK. 4627 // C & U should be OK.
4628 // L & M are larger than the data sent, and show an error. 4628 // L & M are larger than the data sent, and show an error.
4629 // S has too little data, but we seem to accept it. 4629 // S has too little data, but we seem to accept it.
4630 const bool test_expect_success[num_tests] = 4630 const bool test_expect_success[num_tests] =
4631 { true, true, false, false, true }; 4631 { true, true, false, false, true };
4632 4632
4633 for (int i = 0; i < num_tests ; i++) { 4633 base::FilePath file_path;
4634 PathService::Get(base::DIR_SOURCE_ROOT, &file_path);
4635 file_path = file_path.Append(kTestFilePath);
4636 file_path = file_path.Append(FILE_PATH_LITERAL("BullRunSpeech.txt"));
4637 std::string expected_content;
4638 ASSERT_TRUE(base::ReadFileToString(file_path, &expected_content));
4639
4640 for (int i = 0; i < num_tests; i++) {
4634 TestDelegate d; 4641 TestDelegate d;
4635 { 4642 {
4636 std::string test_file = base::StringPrintf( 4643 std::string test_file = base::StringPrintf(
4637 "compressedfiles/BullRunSpeech.txt?%c", test_parameters[i]); 4644 "compressedfiles/BullRunSpeech.txt?%c", test_parameters[i]);
4638 4645
4639 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 4646 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
4640 TestURLRequestContext context(true); 4647 TestURLRequestContext context(true);
4641 context.set_network_delegate(&network_delegate); 4648 context.set_network_delegate(&network_delegate);
4642 context.Init(); 4649 context.Init();
4643 4650
4644 std::unique_ptr<URLRequest> r(context.CreateRequest( 4651 std::unique_ptr<URLRequest> r(context.CreateRequest(
4645 test_server.GetURL(test_file), DEFAULT_PRIORITY, &d)); 4652 test_server.GetURL(test_file), DEFAULT_PRIORITY, &d));
4646 r->Start(); 4653 r->Start();
4647 EXPECT_TRUE(r->is_pending()); 4654 EXPECT_TRUE(r->is_pending());
4648 4655
4649 base::RunLoop().Run(); 4656 base::RunLoop().Run();
4650 4657
4651 EXPECT_EQ(1, d.response_started_count()); 4658 EXPECT_EQ(1, d.response_started_count());
4652 EXPECT_FALSE(d.received_data_before_response()); 4659 EXPECT_FALSE(d.received_data_before_response());
4653 VLOG(1) << " Received " << d.bytes_received() << " bytes" 4660 VLOG(1) << " Received " << d.bytes_received() << " bytes"
4654 << " status = " << r->status().status() 4661 << " status = " << r->status().status()
4655 << " error = " << r->status().error(); 4662 << " error = " << r->status().error();
4656 if (test_expect_success[i]) { 4663 if (test_expect_success[i]) {
4657 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()) 4664 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status())
4658 << " Parameter = \"" << test_file << "\""; 4665 << " Parameter = \"" << test_file << "\"";
4666 if (test_parameters[i] == 'S') {
4667 // When content length is smaller than both compressed length and
4668 // uncompressed length, HttpStreamParser might not read the full
4669 // response body.
4670 continue;
4671 }
4672 EXPECT_EQ(expected_content, d.data_received());
4659 } else { 4673 } else {
4660 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); 4674 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
4661 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r->status().error()) 4675 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r->status().error())
4662 << " Parameter = \"" << test_file << "\""; 4676 << " Parameter = \"" << test_file << "\"";
4663 } 4677 }
4664 } 4678 }
4665 } 4679 }
4666 } 4680 }
4667 #endif // !defined(OS_IOS) 4681 #endif // !defined(OS_IOS)
4668 4682
(...skipping 5174 matching lines...) Expand 10 before | Expand all | Expand 10 after
9843 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 9857 AddTestInterceptor()->set_main_intercept_job(std::move(job));
9844 9858
9845 req->Start(); 9859 req->Start();
9846 req->Cancel(); 9860 req->Cancel();
9847 base::RunLoop().RunUntilIdle(); 9861 base::RunLoop().RunUntilIdle();
9848 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 9862 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
9849 EXPECT_EQ(0, d.received_redirect_count()); 9863 EXPECT_EQ(0, d.received_redirect_count());
9850 } 9864 }
9851 9865
9852 } // namespace net 9866 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698