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

Side by Side Diff: net/base/chunked_upload_data_stream_unittest.cc

Issue 1732493002: Prevent URLFetcher::AppendChunkedData from dereferencing NULL pointers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge Created 4 years, 9 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
OLDNEW
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 "net/base/chunked_upload_data_stream.h" 5 #include "net/base/chunked_upload_data_stream.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 stream.AppendData(kTestData, kTestDataSize, true); 298 stream.AppendData(kTestData, kTestDataSize, true);
299 EXPECT_FALSE(callback.have_result()); 299 EXPECT_FALSE(callback.have_result());
300 300
301 std::string data = ReadSync(&stream, kTestBufferSize); 301 std::string data = ReadSync(&stream, kTestBufferSize);
302 EXPECT_EQ(kTestData, data); 302 EXPECT_EQ(kTestData, data);
303 EXPECT_EQ(kTestDataSize, stream.position()); 303 EXPECT_EQ(kTestDataSize, stream.position());
304 ASSERT_TRUE(stream.IsEOF()); 304 ASSERT_TRUE(stream.IsEOF());
305 EXPECT_FALSE(callback.have_result()); 305 EXPECT_FALSE(callback.have_result());
306 } 306 }
307 307
308 // Check the behavior of ChunkedUploadDataStream::Writer.
309 TEST(ChunkedUploadDataStreamTest, ChunkedUploadDataStreamWriter) {
310 scoped_ptr<ChunkedUploadDataStream> stream(new ChunkedUploadDataStream(0));
311 scoped_ptr<ChunkedUploadDataStream::Writer> writer(stream->CreateWriter());
312
313 // Write before Init.
314 ASSERT_TRUE(writer->AppendData(kTestData, 1, false));
315 ASSERT_EQ(OK, stream->Init(TestCompletionCallback().callback()));
316
317 // Write after Init.
318 ASSERT_TRUE(writer->AppendData(kTestData + 1, kTestDataSize - 1, false));
319
320 TestCompletionCallback callback;
321 std::string data = ReadSync(stream.get(), kTestBufferSize);
322 EXPECT_EQ(kTestData, data);
323
324 // Writing data should gracefully fail if the stream is deleted while still
325 // appending data to it.
326 stream.reset();
327 EXPECT_FALSE(writer->AppendData(kTestData, kTestDataSize, true));
328 }
329
308 } // namespace net 330 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698