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

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: revert SetUp to constructors 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
« no previous file with comments | « net/base/upload_data_stream_unittest.cc ('k') | no next file » | 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/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 virtual void SetUp() {
22 PlatformTest::SetUp();
21 // Some tests (*.ReadPartially) rely on bytes_.size() being even. 23 // Some tests (*.ReadPartially) rely on bytes_.size() being even.
22 const char kData[] = "123456789abcdefghi"; 24 const char kData[] = "123456789abcdefghi";
23 bytes_.assign(kData, kData + arraysize(kData) - 1); 25 bytes_.assign(kData, kData + arraysize(kData) - 1);
24 26
25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 27 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
26 28
27 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), 29 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(),
28 &temp_file_path_)); 30 &temp_file_path_));
29 ASSERT_EQ( 31 ASSERT_EQ(
30 static_cast<int>(bytes_.size()), 32 static_cast<int>(bytes_.size()),
31 file_util::WriteFile(temp_file_path_, &bytes_[0], bytes_.size())); 33 file_util::WriteFile(temp_file_path_, &bytes_[0], bytes_.size()));
32 34
33 reader_.reset( 35 reader_.reset(
34 new UploadFileElementReader(base::MessageLoopProxy::current().get(), 36 new UploadFileElementReader(base::MessageLoopProxy::current().get(),
35 temp_file_path_, 37 temp_file_path_,
36 0, 38 0,
37 kuint64max, 39 kuint64max,
38 base::Time())); 40 base::Time()));
39 TestCompletionCallback callback; 41 TestCompletionCallback callback;
40 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(callback.callback())); 42 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(callback.callback()));
41 EXPECT_EQ(OK, callback.WaitForResult()); 43 EXPECT_EQ(OK, callback.WaitForResult());
42 EXPECT_EQ(bytes_.size(), reader_->GetContentLength()); 44 EXPECT_EQ(bytes_.size(), reader_->GetContentLength());
43 EXPECT_EQ(bytes_.size(), reader_->BytesRemaining()); 45 EXPECT_EQ(bytes_.size(), reader_->BytesRemaining());
44 EXPECT_FALSE(reader_->IsInMemory()); 46 EXPECT_FALSE(reader_->IsInMemory());
45 } 47 }
46 48
49 virtual ~UploadFileElementReaderTest() {
50 reader_.reset();
51 base::RunLoop().RunUntilIdle();
52 }
53
47 std::vector<char> bytes_; 54 std::vector<char> bytes_;
48 scoped_ptr<UploadElementReader> reader_; 55 scoped_ptr<UploadElementReader> reader_;
49 base::ScopedTempDir temp_dir_; 56 base::ScopedTempDir temp_dir_;
50 base::FilePath temp_file_path_; 57 base::FilePath temp_file_path_;
51 }; 58 };
52 59
53 TEST_F(UploadFileElementReaderTest, ReadPartially) { 60 TEST_F(UploadFileElementReaderTest, ReadPartially) {
54 const size_t kHalfSize = bytes_.size() / 2; 61 const size_t kHalfSize = bytes_.size() / 2;
55 ASSERT_EQ(bytes_.size(), kHalfSize * 2); 62 ASSERT_EQ(bytes_.size(), kHalfSize * 2);
56 std::vector<char> buf(kHalfSize); 63 std::vector<char> buf(kHalfSize);
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 TEST_F(UploadFileElementReaderSyncTest, WrongPath) { 365 TEST_F(UploadFileElementReaderSyncTest, WrongPath) {
359 const base::FilePath wrong_path(FILE_PATH_LITERAL("wrong_path")); 366 const base::FilePath wrong_path(FILE_PATH_LITERAL("wrong_path"));
360 reader_.reset(new UploadFileElementReaderSync( 367 reader_.reset(new UploadFileElementReaderSync(
361 wrong_path, 0, kuint64max, base::Time())); 368 wrong_path, 0, kuint64max, base::Time()));
362 ASSERT_EQ(OK, reader_->Init(CompletionCallback())); 369 ASSERT_EQ(OK, reader_->Init(CompletionCallback()));
363 EXPECT_EQ(0U, reader_->GetContentLength()); 370 EXPECT_EQ(0U, reader_->GetContentLength());
364 EXPECT_EQ(0U, reader_->BytesRemaining()); 371 EXPECT_EQ(0U, reader_->BytesRemaining());
365 } 372 }
366 373
367 } // namespace net 374 } // namespace net
OLDNEW
« no previous file with comments | « 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