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

Side by Side Diff: net/http/http_stream_parser_unittest.cc

Issue 1421793007: Fix ScopedTempDir in net_unittests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 | net/url_request/url_request_file_job_unittest.cc » ('j') | 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 "net/http/http_stream_parser.h" 5 #include "net/http/http_stream_parser.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 const std::string payload = "123"; 139 const std::string payload = "123";
140 scoped_ptr<ChunkedUploadDataStream> body(new ChunkedUploadDataStream(0)); 140 scoped_ptr<ChunkedUploadDataStream> body(new ChunkedUploadDataStream(0));
141 body->AppendData(payload.data(), payload.size(), true); 141 body->AppendData(payload.data(), payload.size(), true);
142 ASSERT_EQ(OK, body->Init(TestCompletionCallback().callback())); 142 ASSERT_EQ(OK, body->Init(TestCompletionCallback().callback()));
143 // Shouldn't be merged if upload data carries chunked data. 143 // Shouldn't be merged if upload data carries chunked data.
144 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( 144 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody(
145 "some header", body.get())); 145 "some header", body.get()));
146 } 146 }
147 147
148 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_FileBody) { 148 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_FileBody) {
149 // Create an empty temporary file.
150 base::ScopedTempDir temp_dir;
151 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
152 base::FilePath temp_file_path;
153 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &temp_file_path));
154
149 { 155 {
150 ScopedVector<UploadElementReader> element_readers; 156 ScopedVector<UploadElementReader> element_readers;
151 157
152 // Create an empty temporary file.
153 base::ScopedTempDir temp_dir;
154 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
155 base::FilePath temp_file_path;
156 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(),
157 &temp_file_path));
158
159 element_readers.push_back( 158 element_readers.push_back(
160 new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), 159 new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(),
161 temp_file_path, 0, 0, base::Time())); 160 temp_file_path, 0, 0, base::Time()));
162 161
163 scoped_ptr<UploadDataStream> body( 162 scoped_ptr<UploadDataStream> body(
164 new ElementsUploadDataStream(element_readers.Pass(), 0)); 163 new ElementsUploadDataStream(element_readers.Pass(), 0));
165 TestCompletionCallback callback; 164 TestCompletionCallback callback;
166 ASSERT_EQ(ERR_IO_PENDING, body->Init(callback.callback())); 165 ASSERT_EQ(ERR_IO_PENDING, body->Init(callback.callback()));
167 ASSERT_EQ(OK, callback.WaitForResult()); 166 ASSERT_EQ(OK, callback.WaitForResult());
168 // Shouldn't be merged if upload data carries a file, as it's not in-memory. 167 // Shouldn't be merged if upload data carries a file, as it's not in-memory.
169 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( 168 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody(
170 "some header", body.get())); 169 "some header", body.get()));
171 } 170 }
171
172 // UploadFileElementReaders may post clean-up tasks on destruction. 172 // UploadFileElementReaders may post clean-up tasks on destruction.
173 base::RunLoop().RunUntilIdle(); 173 base::RunLoop().RunUntilIdle();
174 } 174 }
175 175
176 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_SmallBodyInMemory) { 176 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_SmallBodyInMemory) {
177 ScopedVector<UploadElementReader> element_readers; 177 ScopedVector<UploadElementReader> element_readers;
178 const std::string payload = "123"; 178 const std::string payload = "123";
179 element_readers.push_back(new UploadBytesElementReader( 179 element_readers.push_back(new UploadBytesElementReader(
180 payload.data(), payload.size())); 180 payload.data(), payload.size()));
181 181
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 ASSERT_EQ(kBodySize, parser.ReadResponseBody( 1281 ASSERT_EQ(kBodySize, parser.ReadResponseBody(
1282 body_buffer.get(), kBodySize, callback.callback())); 1282 body_buffer.get(), kBodySize, callback.callback()));
1283 1283
1284 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), parser.sent_bytes()); 1284 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), parser.sent_bytes());
1285 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), parser.received_bytes()); 1285 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), parser.received_bytes());
1286 } 1286 }
1287 1287
1288 } // namespace 1288 } // namespace
1289 1289
1290 } // namespace net 1290 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/url_request/url_request_file_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698