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

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

Issue 23872030: Fix teardown in tests which use UploadFileElementReader. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 7 years, 3 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 | Annotate | Revision Log
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/base/upload_file_element_reader.h" 5 #include "net/base/upload_file_element_reader.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/run_loop.h"
10 #include "net/base/io_buffer.h" 11 #include "net/base/io_buffer.h"
11 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
12 #include "net/base/test_completion_callback.h" 13 #include "net/base/test_completion_callback.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/platform_test.h" 15 #include "testing/platform_test.h"
15 16
16 namespace net { 17 namespace net {
17 18
18 class UploadFileElementReaderTest : public PlatformTest { 19 class UploadFileElementReaderTest : public PlatformTest {
19 protected: 20 protected:
20 virtual void SetUp() OVERRIDE { 21 UploadFileElementReaderTest() {
21 // Some tests (*.ReadPartially) rely on bytes_.size() being even. 22 // Some tests (*.ReadPartially) rely on bytes_.size() being even.
22 const char kData[] = "123456789abcdefghi"; 23 const char kData[] = "123456789abcdefghi";
23 bytes_.assign(kData, kData + arraysize(kData) - 1); 24 bytes_.assign(kData, kData + arraysize(kData) - 1);
24 25
25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 26 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
26 27
27 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), 28 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(),
28 &temp_file_path_)); 29 &temp_file_path_));
29 ASSERT_EQ( 30 ASSERT_EQ(
30 static_cast<int>(bytes_.size()), 31 static_cast<int>(bytes_.size()),
31 file_util::WriteFile(temp_file_path_, &bytes_[0], bytes_.size())); 32 file_util::WriteFile(temp_file_path_, &bytes_[0], bytes_.size()));
32 33
33 reader_.reset( 34 reader_.reset(
34 new UploadFileElementReader(base::MessageLoopProxy::current().get(), 35 new UploadFileElementReader(base::MessageLoopProxy::current().get(),
35 temp_file_path_, 36 temp_file_path_,
36 0, 37 0,
37 kuint64max, 38 kuint64max,
38 base::Time())); 39 base::Time()));
39 TestCompletionCallback callback; 40 TestCompletionCallback callback;
40 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(callback.callback())); 41 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(callback.callback()));
41 EXPECT_EQ(OK, callback.WaitForResult()); 42 EXPECT_EQ(OK, callback.WaitForResult());
42 EXPECT_EQ(bytes_.size(), reader_->GetContentLength()); 43 EXPECT_EQ(bytes_.size(), reader_->GetContentLength());
43 EXPECT_EQ(bytes_.size(), reader_->BytesRemaining()); 44 EXPECT_EQ(bytes_.size(), reader_->BytesRemaining());
44 EXPECT_FALSE(reader_->IsInMemory()); 45 EXPECT_FALSE(reader_->IsInMemory());
45 } 46 }
47 ~UploadFileElementReaderTest() {
Ryan Sleevi 2013/09/13 21:57:27 style nit: virtual style nit: line break after }
48 reader_.reset();
49 base::RunLoop().RunUntilIdle();
50 }
46 51
47 std::vector<char> bytes_; 52 std::vector<char> bytes_;
48 scoped_ptr<UploadElementReader> reader_; 53 scoped_ptr<UploadElementReader> reader_;
49 base::ScopedTempDir temp_dir_; 54 base::ScopedTempDir temp_dir_;
50 base::FilePath temp_file_path_; 55 base::FilePath temp_file_path_;
51 }; 56 };
52 57
53 TEST_F(UploadFileElementReaderTest, ReadPartially) { 58 TEST_F(UploadFileElementReaderTest, ReadPartially) {
54 const size_t kHalfSize = bytes_.size() / 2; 59 const size_t kHalfSize = bytes_.size() / 2;
55 ASSERT_EQ(bytes_.size(), kHalfSize * 2); 60 ASSERT_EQ(bytes_.size(), kHalfSize * 2);
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 TEST_F(UploadFileElementReaderSyncTest, WrongPath) { 363 TEST_F(UploadFileElementReaderSyncTest, WrongPath) {
359 const base::FilePath wrong_path(FILE_PATH_LITERAL("wrong_path")); 364 const base::FilePath wrong_path(FILE_PATH_LITERAL("wrong_path"));
360 reader_.reset(new UploadFileElementReaderSync( 365 reader_.reset(new UploadFileElementReaderSync(
361 wrong_path, 0, kuint64max, base::Time())); 366 wrong_path, 0, kuint64max, base::Time()));
362 ASSERT_EQ(OK, reader_->Init(CompletionCallback())); 367 ASSERT_EQ(OK, reader_->Init(CompletionCallback()));
363 EXPECT_EQ(0U, reader_->GetContentLength()); 368 EXPECT_EQ(0U, reader_->GetContentLength());
364 EXPECT_EQ(0U, reader_->BytesRemaining()); 369 EXPECT_EQ(0U, reader_->BytesRemaining());
365 } 370 }
366 371
367 } // namespace net 372 } // namespace net
OLDNEW
« net/base/upload_data_stream_unittest.cc ('K') | « net/base/upload_data_stream_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698