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

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

Issue 1502503004: Remove kuint64max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint8
Patch Set: rebase Created 5 years 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 (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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 #endif 10 #endif
11 11
12 #include <stdint.h> 12 #include <stdint.h>
13 13
14 #include <algorithm> 14 #include <algorithm>
15 #include <limits>
15 16
16 #include "base/basictypes.h"
17 #include "base/bind.h" 17 #include "base/bind.h"
18 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
19 #include "base/files/file_path.h" 19 #include "base/files/file_path.h"
20 #include "base/files/file_util.h" 20 #include "base/files/file_util.h"
21 #include "base/files/scoped_temp_dir.h" 21 #include "base/files/scoped_temp_dir.h"
22 #include "base/format_macros.h" 22 #include "base/format_macros.h"
23 #include "base/json/json_reader.h" 23 #include "base/json/json_reader.h"
24 #include "base/location.h" 24 #include "base/location.h"
25 #include "base/memory/scoped_ptr.h" 25 #include "base/memory/scoped_ptr.h"
26 #include "base/memory/weak_ptr.h" 26 #include "base/memory/weak_ptr.h"
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 new UploadBytesElementReader(data, strlen(data))); 295 new UploadBytesElementReader(data, strlen(data)));
296 return ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0); 296 return ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0);
297 } 297 }
298 298
299 // Verify that the SSLInfo of a successful SSL connection has valid values. 299 // Verify that the SSLInfo of a successful SSL connection has valid values.
300 void CheckSSLInfo(const SSLInfo& ssl_info) { 300 void CheckSSLInfo(const SSLInfo& ssl_info) {
301 // -1 means unknown. 0 means no encryption. 301 // -1 means unknown. 0 means no encryption.
302 EXPECT_GT(ssl_info.security_bits, 0); 302 EXPECT_GT(ssl_info.security_bits, 0);
303 303
304 // The cipher suite TLS_NULL_WITH_NULL_NULL (0) must not be negotiated. 304 // The cipher suite TLS_NULL_WITH_NULL_NULL (0) must not be negotiated.
305 uint16 cipher_suite = SSLConnectionStatusToCipherSuite( 305 uint16_t cipher_suite =
306 ssl_info.connection_status); 306 SSLConnectionStatusToCipherSuite(ssl_info.connection_status);
307 EXPECT_NE(0U, cipher_suite); 307 EXPECT_NE(0U, cipher_suite);
308 } 308 }
309 309
310 void CheckFullRequestHeaders(const HttpRequestHeaders& headers, 310 void CheckFullRequestHeaders(const HttpRequestHeaders& headers,
311 const GURL& host_url) { 311 const GURL& host_url) {
312 std::string sent_value; 312 std::string sent_value;
313 313
314 EXPECT_TRUE(headers.GetHeader("Host", &sent_value)); 314 EXPECT_TRUE(headers.GetHeader("Host", &sent_value));
315 EXPECT_EQ(GetHostAndOptionalPort(host_url), sent_value); 315 EXPECT_EQ(GetHostAndOptionalPort(host_url), sent_value);
316 316
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 TestDelegate d; 806 TestDelegate d;
807 { 807 {
808 scoped_ptr<URLRequest> r( 808 scoped_ptr<URLRequest> r(
809 default_context_.CreateRequest(app_url, DEFAULT_PRIORITY, &d)); 809 default_context_.CreateRequest(app_url, DEFAULT_PRIORITY, &d));
810 810
811 r->Start(); 811 r->Start();
812 EXPECT_TRUE(r->is_pending()); 812 EXPECT_TRUE(r->is_pending());
813 813
814 base::RunLoop().Run(); 814 base::RunLoop().Run();
815 815
816 int64 file_size = -1; 816 int64_t file_size = -1;
817 EXPECT_TRUE(base::GetFileSize(app_path, &file_size)); 817 EXPECT_TRUE(base::GetFileSize(app_path, &file_size));
818 818
819 EXPECT_TRUE(!r->is_pending()); 819 EXPECT_TRUE(!r->is_pending());
820 EXPECT_EQ(1, d.response_started_count()); 820 EXPECT_EQ(1, d.response_started_count());
821 EXPECT_FALSE(d.received_data_before_response()); 821 EXPECT_FALSE(d.received_data_before_response());
822 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 822 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
823 EXPECT_EQ("", r->GetSocketAddress().host()); 823 EXPECT_EQ("", r->GetSocketAddress().host());
824 EXPECT_EQ(0, r->GetSocketAddress().port()); 824 EXPECT_EQ(0, r->GetSocketAddress().port());
825 825
826 HttpRequestHeaders headers; 826 HttpRequestHeaders headers;
(...skipping 23 matching lines...) Expand all
850 TEST_F(URLRequestTest, FileTestFullSpecifiedRange) { 850 TEST_F(URLRequestTest, FileTestFullSpecifiedRange) {
851 const size_t buffer_size = 4000; 851 const size_t buffer_size = 4000;
852 scoped_ptr<char[]> buffer(new char[buffer_size]); 852 scoped_ptr<char[]> buffer(new char[buffer_size]);
853 FillBuffer(buffer.get(), buffer_size); 853 FillBuffer(buffer.get(), buffer_size);
854 854
855 base::FilePath temp_path; 855 base::FilePath temp_path;
856 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); 856 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path));
857 GURL temp_url = FilePathToFileURL(temp_path); 857 GURL temp_url = FilePathToFileURL(temp_path);
858 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size)); 858 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size));
859 859
860 int64 file_size; 860 int64_t file_size;
861 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); 861 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size));
862 862
863 const size_t first_byte_position = 500; 863 const size_t first_byte_position = 500;
864 const size_t last_byte_position = buffer_size - first_byte_position; 864 const size_t last_byte_position = buffer_size - first_byte_position;
865 const size_t content_length = last_byte_position - first_byte_position + 1; 865 const size_t content_length = last_byte_position - first_byte_position + 1;
866 std::string partial_buffer_string(buffer.get() + first_byte_position, 866 std::string partial_buffer_string(buffer.get() + first_byte_position,
867 buffer.get() + last_byte_position + 1); 867 buffer.get() + last_byte_position + 1);
868 868
869 TestDelegate d; 869 TestDelegate d;
870 { 870 {
(...skipping 24 matching lines...) Expand all
895 TEST_F(URLRequestTest, FileTestHalfSpecifiedRange) { 895 TEST_F(URLRequestTest, FileTestHalfSpecifiedRange) {
896 const size_t buffer_size = 4000; 896 const size_t buffer_size = 4000;
897 scoped_ptr<char[]> buffer(new char[buffer_size]); 897 scoped_ptr<char[]> buffer(new char[buffer_size]);
898 FillBuffer(buffer.get(), buffer_size); 898 FillBuffer(buffer.get(), buffer_size);
899 899
900 base::FilePath temp_path; 900 base::FilePath temp_path;
901 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); 901 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path));
902 GURL temp_url = FilePathToFileURL(temp_path); 902 GURL temp_url = FilePathToFileURL(temp_path);
903 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size)); 903 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size));
904 904
905 int64 file_size; 905 int64_t file_size;
906 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); 906 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size));
907 907
908 const size_t first_byte_position = 500; 908 const size_t first_byte_position = 500;
909 const size_t last_byte_position = buffer_size - 1; 909 const size_t last_byte_position = buffer_size - 1;
910 const size_t content_length = last_byte_position - first_byte_position + 1; 910 const size_t content_length = last_byte_position - first_byte_position + 1;
911 std::string partial_buffer_string(buffer.get() + first_byte_position, 911 std::string partial_buffer_string(buffer.get() + first_byte_position,
912 buffer.get() + last_byte_position + 1); 912 buffer.get() + last_byte_position + 1);
913 913
914 TestDelegate d; 914 TestDelegate d;
915 { 915 {
(...skipping 23 matching lines...) Expand all
939 TEST_F(URLRequestTest, FileTestMultipleRanges) { 939 TEST_F(URLRequestTest, FileTestMultipleRanges) {
940 const size_t buffer_size = 400000; 940 const size_t buffer_size = 400000;
941 scoped_ptr<char[]> buffer(new char[buffer_size]); 941 scoped_ptr<char[]> buffer(new char[buffer_size]);
942 FillBuffer(buffer.get(), buffer_size); 942 FillBuffer(buffer.get(), buffer_size);
943 943
944 base::FilePath temp_path; 944 base::FilePath temp_path;
945 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); 945 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path));
946 GURL temp_url = FilePathToFileURL(temp_path); 946 GURL temp_url = FilePathToFileURL(temp_path);
947 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size)); 947 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size));
948 948
949 int64 file_size; 949 int64_t file_size;
950 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); 950 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size));
951 951
952 TestDelegate d; 952 TestDelegate d;
953 { 953 {
954 scoped_ptr<URLRequest> r( 954 scoped_ptr<URLRequest> r(
955 default_context_.CreateRequest(temp_url, DEFAULT_PRIORITY, &d)); 955 default_context_.CreateRequest(temp_url, DEFAULT_PRIORITY, &d));
956 956
957 HttpRequestHeaders headers; 957 HttpRequestHeaders headers;
958 headers.SetHeader(HttpRequestHeaders::kRange, "bytes=0-0,10-200,200-300"); 958 headers.SetHeader(HttpRequestHeaders::kRange, "bytes=0-0,10-200,200-300");
959 r->SetExtraRequestHeaders(headers); 959 r->SetExtraRequestHeaders(headers);
(...skipping 4505 matching lines...) Expand 10 before | Expand all | Expand 10 after
5465 base::FilePath dir; 5465 base::FilePath dir;
5466 PathService::Get(base::DIR_EXE, &dir); 5466 PathService::Get(base::DIR_EXE, &dir);
5467 base::SetCurrentDirectory(dir); 5467 base::SetCurrentDirectory(dir);
5468 5468
5469 std::vector<scoped_ptr<UploadElementReader>> element_readers; 5469 std::vector<scoped_ptr<UploadElementReader>> element_readers;
5470 5470
5471 base::FilePath path; 5471 base::FilePath path;
5472 PathService::Get(base::DIR_SOURCE_ROOT, &path); 5472 PathService::Get(base::DIR_SOURCE_ROOT, &path);
5473 path = path.Append(kTestFilePath); 5473 path = path.Append(kTestFilePath);
5474 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); 5474 path = path.Append(FILE_PATH_LITERAL("with-headers.html"));
5475 element_readers.push_back(make_scoped_ptr( 5475 element_readers.push_back(make_scoped_ptr(new UploadFileElementReader(
5476 new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), 5476 base::ThreadTaskRunnerHandle::Get().get(), path, 0,
5477 path, 0, kuint64max, base::Time()))); 5477 std::numeric_limits<uint64_t>::max(), base::Time())));
5478 r->set_upload(make_scoped_ptr<UploadDataStream>( 5478 r->set_upload(make_scoped_ptr<UploadDataStream>(
5479 new ElementsUploadDataStream(std::move(element_readers), 0))); 5479 new ElementsUploadDataStream(std::move(element_readers), 0)));
5480 5480
5481 r->Start(); 5481 r->Start();
5482 EXPECT_TRUE(r->is_pending()); 5482 EXPECT_TRUE(r->is_pending());
5483 5483
5484 base::RunLoop().Run(); 5484 base::RunLoop().Run();
5485 5485
5486 int64 size64 = 0; 5486 int64_t size64 = 0;
5487 ASSERT_EQ(true, base::GetFileSize(path, &size64)); 5487 ASSERT_EQ(true, base::GetFileSize(path, &size64));
5488 ASSERT_LE(size64, std::numeric_limits<int>::max()); 5488 ASSERT_LE(size64, std::numeric_limits<int>::max());
5489 int size = static_cast<int>(size64); 5489 int size = static_cast<int>(size64);
5490 scoped_ptr<char[]> buf(new char[size]); 5490 scoped_ptr<char[]> buf(new char[size]);
5491 5491
5492 ASSERT_EQ(size, base::ReadFile(path, buf.get(), size)); 5492 ASSERT_EQ(size, base::ReadFile(path, buf.get(), size));
5493 5493
5494 ASSERT_EQ(1, d.response_started_count()) 5494 ASSERT_EQ(1, d.response_started_count())
5495 << "request failed: " << r->status().status() 5495 << "request failed: " << r->status().status()
5496 << ", error: " << r->status().error(); 5496 << ", error: " << r->status().error();
(...skipping 13 matching lines...) Expand all
5510 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 5510 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5511 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); 5511 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d));
5512 r->set_method("POST"); 5512 r->set_method("POST");
5513 5513
5514 std::vector<scoped_ptr<UploadElementReader>> element_readers; 5514 std::vector<scoped_ptr<UploadElementReader>> element_readers;
5515 5515
5516 element_readers.push_back(make_scoped_ptr(new UploadFileElementReader( 5516 element_readers.push_back(make_scoped_ptr(new UploadFileElementReader(
5517 base::ThreadTaskRunnerHandle::Get().get(), 5517 base::ThreadTaskRunnerHandle::Get().get(),
5518 base::FilePath(FILE_PATH_LITERAL( 5518 base::FilePath(FILE_PATH_LITERAL(
5519 "c:\\path\\to\\non\\existant\\file.randomness.12345")), 5519 "c:\\path\\to\\non\\existant\\file.randomness.12345")),
5520 0, kuint64max, base::Time()))); 5520 0, std::numeric_limits<uint64_t>::max(), base::Time())));
5521 r->set_upload(make_scoped_ptr<UploadDataStream>( 5521 r->set_upload(make_scoped_ptr<UploadDataStream>(
5522 new ElementsUploadDataStream(std::move(element_readers), 0))); 5522 new ElementsUploadDataStream(std::move(element_readers), 0)));
5523 5523
5524 r->Start(); 5524 r->Start();
5525 EXPECT_TRUE(r->is_pending()); 5525 EXPECT_TRUE(r->is_pending());
5526 5526
5527 base::RunLoop().Run(); 5527 base::RunLoop().Run();
5528 5528
5529 EXPECT_TRUE(d.request_failed()); 5529 EXPECT_TRUE(d.request_failed());
5530 EXPECT_FALSE(d.received_data_before_response()); 5530 EXPECT_FALSE(d.received_data_before_response());
(...skipping 2916 matching lines...) Expand 10 before | Expand all | Expand 10 after
8447 TestSSLConfigService(bool ev_enabled, 8447 TestSSLConfigService(bool ev_enabled,
8448 bool online_rev_checking, 8448 bool online_rev_checking,
8449 bool rev_checking_required_local_anchors) 8449 bool rev_checking_required_local_anchors)
8450 : ev_enabled_(ev_enabled), 8450 : ev_enabled_(ev_enabled),
8451 online_rev_checking_(online_rev_checking), 8451 online_rev_checking_(online_rev_checking),
8452 rev_checking_required_local_anchors_( 8452 rev_checking_required_local_anchors_(
8453 rev_checking_required_local_anchors), 8453 rev_checking_required_local_anchors),
8454 min_version_(kDefaultSSLVersionMin), 8454 min_version_(kDefaultSSLVersionMin),
8455 fallback_min_version_(kDefaultSSLVersionFallbackMin) {} 8455 fallback_min_version_(kDefaultSSLVersionFallbackMin) {}
8456 8456
8457 void set_min_version(uint16 version) { 8457 void set_min_version(uint16_t version) { min_version_ = version; }
8458 min_version_ = version;
8459 }
8460 8458
8461 void set_fallback_min_version(uint16 version) { 8459 void set_fallback_min_version(uint16_t version) {
8462 fallback_min_version_ = version; 8460 fallback_min_version_ = version;
8463 } 8461 }
8464 8462
8465 // SSLConfigService: 8463 // SSLConfigService:
8466 void GetSSLConfig(SSLConfig* config) override { 8464 void GetSSLConfig(SSLConfig* config) override {
8467 *config = SSLConfig(); 8465 *config = SSLConfig();
8468 config->rev_checking_enabled = online_rev_checking_; 8466 config->rev_checking_enabled = online_rev_checking_;
8469 config->verify_ev_cert = ev_enabled_; 8467 config->verify_ev_cert = ev_enabled_;
8470 config->rev_checking_required_local_anchors = 8468 config->rev_checking_required_local_anchors =
8471 rev_checking_required_local_anchors_; 8469 rev_checking_required_local_anchors_;
8472 if (fallback_min_version_) { 8470 if (fallback_min_version_) {
8473 config->version_fallback_min = fallback_min_version_; 8471 config->version_fallback_min = fallback_min_version_;
8474 } 8472 }
8475 if (min_version_) { 8473 if (min_version_) {
8476 config->version_min = min_version_; 8474 config->version_min = min_version_;
8477 } 8475 }
8478 } 8476 }
8479 8477
8480 protected: 8478 protected:
8481 ~TestSSLConfigService() override {} 8479 ~TestSSLConfigService() override {}
8482 8480
8483 private: 8481 private:
8484 const bool ev_enabled_; 8482 const bool ev_enabled_;
8485 const bool online_rev_checking_; 8483 const bool online_rev_checking_;
8486 const bool rev_checking_required_local_anchors_; 8484 const bool rev_checking_required_local_anchors_;
8487 uint16 min_version_; 8485 uint16_t min_version_;
8488 uint16 fallback_min_version_; 8486 uint16_t fallback_min_version_;
8489 }; 8487 };
8490 8488
8491 class FallbackTestURLRequestContext : public TestURLRequestContext { 8489 class FallbackTestURLRequestContext : public TestURLRequestContext {
8492 public: 8490 public:
8493 explicit FallbackTestURLRequestContext(bool delay_initialization) 8491 explicit FallbackTestURLRequestContext(bool delay_initialization)
8494 : TestURLRequestContext(delay_initialization) {} 8492 : TestURLRequestContext(delay_initialization) {}
8495 8493
8496 void set_fallback_min_version(uint16 version) { 8494 void set_fallback_min_version(uint16_t version) {
8497 TestSSLConfigService *ssl_config_service = 8495 TestSSLConfigService *ssl_config_service =
8498 new TestSSLConfigService(true /* check for EV */, 8496 new TestSSLConfigService(true /* check for EV */,
8499 false /* online revocation checking */, 8497 false /* online revocation checking */,
8500 false /* require rev. checking for local 8498 false /* require rev. checking for local
8501 anchors */); 8499 anchors */);
8502 ssl_config_service->set_fallback_min_version(version); 8500 ssl_config_service->set_fallback_min_version(version);
8503 set_ssl_config_service(ssl_config_service); 8501 set_ssl_config_service(ssl_config_service);
8504 } 8502 }
8505 }; 8503 };
8506 8504
(...skipping 14 matching lines...) Expand all
8521 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 8519 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
8522 ASSERT_TRUE(test_server.Start()); 8520 ASSERT_TRUE(test_server.Start());
8523 8521
8524 request_ = context_.CreateRequest(test_server.GetURL("/"), DEFAULT_PRIORITY, 8522 request_ = context_.CreateRequest(test_server.GetURL("/"), DEFAULT_PRIORITY,
8525 &delegate_); 8523 &delegate_);
8526 request_->Start(); 8524 request_->Start();
8527 8525
8528 base::RunLoop().Run(); 8526 base::RunLoop().Run();
8529 } 8527 }
8530 8528
8531 void set_fallback_min_version(uint16 version) { 8529 void set_fallback_min_version(uint16_t version) {
8532 context_.set_fallback_min_version(version); 8530 context_.set_fallback_min_version(version);
8533 } 8531 }
8534 8532
8535 void ExpectConnection(int version) { 8533 void ExpectConnection(int version) {
8536 EXPECT_EQ(1, delegate_.response_started_count()); 8534 EXPECT_EQ(1, delegate_.response_started_count());
8537 EXPECT_NE(0, delegate_.bytes_received()); 8535 EXPECT_NE(0, delegate_.bytes_received());
8538 EXPECT_EQ(version, SSLConnectionStatusToVersion( 8536 EXPECT_EQ(version, SSLConnectionStatusToVersion(
8539 request_->ssl_info().connection_status)); 8537 request_->ssl_info().connection_status));
8540 EXPECT_TRUE(request_->ssl_info().connection_status & 8538 EXPECT_TRUE(request_->ssl_info().connection_status &
8541 SSL_CONNECTION_VERSION_FALLBACK); 8539 SSL_CONNECTION_VERSION_FALLBACK);
(...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after
9717 9715
9718 req->Start(); 9716 req->Start();
9719 req->Cancel(); 9717 req->Cancel();
9720 job->DetachRequest(); 9718 job->DetachRequest();
9721 base::RunLoop().RunUntilIdle(); 9719 base::RunLoop().RunUntilIdle();
9722 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 9720 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
9723 EXPECT_EQ(0, d.received_redirect_count()); 9721 EXPECT_EQ(0, d.received_redirect_count());
9724 } 9722 }
9725 9723
9726 } // namespace net 9724 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698