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

Side by Side Diff: net/http/http_network_transaction_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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "net/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 #include <stdarg.h> 8 #include <stdarg.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <limits>
11 #include <string> 12 #include <string>
12 #include <vector> 13 #include <vector>
13 14
14 #include "base/basictypes.h" 15 #include "base/basictypes.h"
15 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
16 #include "base/files/file_path.h" 17 #include "base/files/file_path.h"
17 #include "base/files/file_util.h" 18 #include "base/files/file_util.h"
18 #include "base/json/json_writer.h" 19 #include "base/json/json_writer.h"
19 #include "base/logging.h" 20 #include "base/logging.h"
20 #include "base/memory/scoped_ptr.h" 21 #include "base/memory/scoped_ptr.h"
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 DCHECK(sizeof_data >= size); 540 DCHECK(sizeof_data >= size);
540 str->reserve(sizeof_data); 541 str->reserve(sizeof_data);
541 542
542 for (int i = 0; i < num_rows; ++i) 543 for (int i = 0; i < num_rows; ++i)
543 str->append(row, sizeof_row); 544 str->append(row, sizeof_row);
544 } 545 }
545 546
546 #if defined(NTLM_PORTABLE) 547 #if defined(NTLM_PORTABLE)
547 // Alternative functions that eliminate randomness and dependency on the local 548 // Alternative functions that eliminate randomness and dependency on the local
548 // host name so that the generated NTLM messages are reproducible. 549 // host name so that the generated NTLM messages are reproducible.
549 void MockGenerateRandom1(uint8* output, size_t n) { 550 void MockGenerateRandom1(uint8_t* output, size_t n) {
550 static const uint8 bytes[] = { 551 static const uint8_t bytes[] = {0x55, 0x29, 0x66, 0x26,
551 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 552 0x6b, 0x9c, 0x73, 0x54};
552 };
553 static size_t current_byte = 0; 553 static size_t current_byte = 0;
554 for (size_t i = 0; i < n; ++i) { 554 for (size_t i = 0; i < n; ++i) {
555 output[i] = bytes[current_byte++]; 555 output[i] = bytes[current_byte++];
556 current_byte %= arraysize(bytes); 556 current_byte %= arraysize(bytes);
557 } 557 }
558 } 558 }
559 559
560 void MockGenerateRandom2(uint8* output, size_t n) { 560 void MockGenerateRandom2(uint8_t* output, size_t n) {
561 static const uint8 bytes[] = { 561 static const uint8_t bytes[] = {0x96, 0x79, 0x85, 0xe7, 0x49, 0x93,
562 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, 562 0x70, 0xa1, 0x4e, 0xe7, 0x87, 0x45,
563 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f 563 0x31, 0x5b, 0xd3, 0x1f};
564 };
565 static size_t current_byte = 0; 564 static size_t current_byte = 0;
566 for (size_t i = 0; i < n; ++i) { 565 for (size_t i = 0; i < n; ++i) {
567 output[i] = bytes[current_byte++]; 566 output[i] = bytes[current_byte++];
568 current_byte %= arraysize(bytes); 567 current_byte %= arraysize(bytes);
569 } 568 }
570 } 569 }
571 570
572 std::string MockGetHostName() { 571 std::string MockGetHostName() {
573 return "WTC-WIN7"; 572 return "WTC-WIN7";
574 } 573 }
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 MockRead("world"), 1368 MockRead("world"),
1370 MockRead(ASYNC, OK), 1369 MockRead(ASYNC, OK),
1371 }; 1370 };
1372 StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); 1371 StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0);
1373 session_deps_.socket_factory->AddSocketDataProvider(&data2); 1372 session_deps_.socket_factory->AddSocketDataProvider(&data2);
1374 1373
1375 const char* const kExpectedResponseData[] = { 1374 const char* const kExpectedResponseData[] = {
1376 "hello", "world" 1375 "hello", "world"
1377 }; 1376 };
1378 1377
1379 uint32 first_socket_log_id = NetLog::Source::kInvalidId; 1378 uint32_t first_socket_log_id = NetLog::Source::kInvalidId;
1380 for (int i = 0; i < 2; ++i) { 1379 for (int i = 0; i < 2; ++i) {
1381 TestCompletionCallback callback; 1380 TestCompletionCallback callback;
1382 1381
1383 scoped_ptr<HttpTransaction> trans( 1382 scoped_ptr<HttpTransaction> trans(
1384 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 1383 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
1385 1384
1386 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 1385 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
1387 EXPECT_EQ(ERR_IO_PENDING, rv); 1386 EXPECT_EQ(ERR_IO_PENDING, rv);
1388 1387
1389 rv = callback.WaitForResult(); 1388 rv = callback.WaitForResult();
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
1897 MockRead(ASYNC, 22, "hello"), 1896 MockRead(ASYNC, 22, "hello"),
1898 }; 1897 };
1899 SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, 1898 SequencedSocketData data(data_reads, arraysize(data_reads), data_writes,
1900 arraysize(data_writes)); 1899 arraysize(data_writes));
1901 data.set_busy_before_sync_reads(true); 1900 data.set_busy_before_sync_reads(true);
1902 session_deps_.socket_factory->AddSocketDataProvider(&data); 1901 session_deps_.socket_factory->AddSocketDataProvider(&data);
1903 1902
1904 const int kNumUnreadBodies = arraysize(data_writes) - 1; 1903 const int kNumUnreadBodies = arraysize(data_writes) - 1;
1905 std::string response_lines[kNumUnreadBodies]; 1904 std::string response_lines[kNumUnreadBodies];
1906 1905
1907 uint32 first_socket_log_id = NetLog::Source::kInvalidId; 1906 uint32_t first_socket_log_id = NetLog::Source::kInvalidId;
1908 for (size_t i = 0; i < kNumUnreadBodies; ++i) { 1907 for (size_t i = 0; i < kNumUnreadBodies; ++i) {
1909 TestCompletionCallback callback; 1908 TestCompletionCallback callback;
1910 1909
1911 scoped_ptr<HttpTransaction> trans( 1910 scoped_ptr<HttpTransaction> trans(
1912 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 1911 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
1913 1912
1914 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 1913 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
1915 EXPECT_EQ(OK, callback.GetResult(rv)); 1914 EXPECT_EQ(OK, callback.GetResult(rv));
1916 1915
1917 LoadTimingInfo load_timing_info; 1916 LoadTimingInfo load_timing_info;
(...skipping 7202 matching lines...) Expand 10 before | Expand all | Expand 10 after
9120 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); 9119 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine());
9121 9120
9122 std::string response_data; 9121 std::string response_data;
9123 rv = ReadTransaction(trans.get(), &response_data); 9122 rv = ReadTransaction(trans.get(), &response_data);
9124 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); 9123 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv);
9125 } 9124 }
9126 9125
9127 TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { 9126 TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) {
9128 base::FilePath temp_file_path; 9127 base::FilePath temp_file_path;
9129 ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); 9128 ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path));
9130 const uint64 kFakeSize = 100000; // file is actually blank 9129 const uint64_t kFakeSize = 100000; // file is actually blank
9131 UploadFileElementReader::ScopedOverridingContentLengthForTests 9130 UploadFileElementReader::ScopedOverridingContentLengthForTests
9132 overriding_content_length(kFakeSize); 9131 overriding_content_length(kFakeSize);
9133 9132
9134 std::vector<scoped_ptr<UploadElementReader>> element_readers; 9133 std::vector<scoped_ptr<UploadElementReader>> element_readers;
9135 element_readers.push_back(make_scoped_ptr(new UploadFileElementReader( 9134 element_readers.push_back(make_scoped_ptr(new UploadFileElementReader(
9136 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, kuint64max, 9135 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0,
9137 base::Time()))); 9136 std::numeric_limits<uint64_t>::max(), base::Time())));
9138 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); 9137 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0);
9139 9138
9140 HttpRequestInfo request; 9139 HttpRequestInfo request;
9141 request.method = "POST"; 9140 request.method = "POST";
9142 request.url = GURL("http://www.example.org/upload"); 9141 request.url = GURL("http://www.example.org/upload");
9143 request.upload_data_stream = &upload_data_stream; 9142 request.upload_data_stream = &upload_data_stream;
9144 request.load_flags = 0; 9143 request.load_flags = 0;
9145 9144
9146 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 9145 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
9147 scoped_ptr<HttpTransaction> trans( 9146 scoped_ptr<HttpTransaction> trans(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
9179 9178
9180 TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { 9179 TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) {
9181 base::FilePath temp_file; 9180 base::FilePath temp_file;
9182 ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); 9181 ASSERT_TRUE(base::CreateTemporaryFile(&temp_file));
9183 std::string temp_file_content("Unreadable file."); 9182 std::string temp_file_content("Unreadable file.");
9184 ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), 9183 ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(),
9185 temp_file_content.length())); 9184 temp_file_content.length()));
9186 ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); 9185 ASSERT_TRUE(base::MakeFileUnreadable(temp_file));
9187 9186
9188 std::vector<scoped_ptr<UploadElementReader>> element_readers; 9187 std::vector<scoped_ptr<UploadElementReader>> element_readers;
9189 element_readers.push_back(make_scoped_ptr( 9188 element_readers.push_back(make_scoped_ptr(new UploadFileElementReader(
9190 new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), 9189 base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0,
9191 temp_file, 0, kuint64max, base::Time()))); 9190 std::numeric_limits<uint64_t>::max(), base::Time())));
9192 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); 9191 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0);
9193 9192
9194 HttpRequestInfo request; 9193 HttpRequestInfo request;
9195 request.method = "POST"; 9194 request.method = "POST";
9196 request.url = GURL("http://www.example.org/upload"); 9195 request.url = GURL("http://www.example.org/upload");
9197 request.upload_data_stream = &upload_data_stream; 9196 request.upload_data_stream = &upload_data_stream;
9198 request.load_flags = 0; 9197 request.load_flags = 0;
9199 9198
9200 // If we try to upload an unreadable file, the transaction should fail. 9199 // If we try to upload an unreadable file, the transaction should fail.
9201 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 9200 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
(...skipping 20 matching lines...) Expand all
9222 FakeUploadElementReader() {} 9221 FakeUploadElementReader() {}
9223 ~FakeUploadElementReader() override {} 9222 ~FakeUploadElementReader() override {}
9224 9223
9225 const CompletionCallback& callback() const { return callback_; } 9224 const CompletionCallback& callback() const { return callback_; }
9226 9225
9227 // UploadElementReader overrides: 9226 // UploadElementReader overrides:
9228 int Init(const CompletionCallback& callback) override { 9227 int Init(const CompletionCallback& callback) override {
9229 callback_ = callback; 9228 callback_ = callback;
9230 return ERR_IO_PENDING; 9229 return ERR_IO_PENDING;
9231 } 9230 }
9232 uint64 GetContentLength() const override { return 0; } 9231 uint64_t GetContentLength() const override { return 0; }
9233 uint64 BytesRemaining() const override { return 0; } 9232 uint64_t BytesRemaining() const override { return 0; }
9234 int Read(IOBuffer* buf, 9233 int Read(IOBuffer* buf,
9235 int buf_length, 9234 int buf_length,
9236 const CompletionCallback& callback) override { 9235 const CompletionCallback& callback) override {
9237 return ERR_FAILED; 9236 return ERR_FAILED;
9238 } 9237 }
9239 9238
9240 private: 9239 private:
9241 CompletionCallback callback_; 9240 CompletionCallback callback_;
9242 }; 9241 };
9243 9242
(...skipping 6415 matching lines...) Expand 10 before | Expand all | Expand 10 after
15659 15658
15660 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 15659 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
15661 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 15660 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
15662 15661
15663 EXPECT_THAT(trans.server_ssl_config_.alpn_protos, 15662 EXPECT_THAT(trans.server_ssl_config_.alpn_protos,
15664 testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); 15663 testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11));
15665 EXPECT_TRUE(trans.server_ssl_config_.npn_protos.empty()); 15664 EXPECT_TRUE(trans.server_ssl_config_.npn_protos.empty());
15666 } 15665 }
15667 15666
15668 } // namespace net 15667 } // namespace net
OLDNEW
« no previous file with comments | « net/base/upload_file_element_reader_unittest.cc ('k') | net/quic/congestion_control/send_algorithm_simulator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698