OLD | NEW |
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_data_stream.h" | 5 #include "net/base/upload_data_stream.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/run_loop.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
19 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
20 #include "net/base/test_completion_callback.h" | 21 #include "net/base/test_completion_callback.h" |
21 #include "net/base/upload_bytes_element_reader.h" | 22 #include "net/base/upload_bytes_element_reader.h" |
22 #include "net/base/upload_file_element_reader.h" | 23 #include "net/base/upload_file_element_reader.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "testing/platform_test.h" | 26 #include "testing/platform_test.h" |
26 | 27 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 int init_result_; | 117 int init_result_; |
117 | 118 |
118 // Result value returned from Read(). | 119 // Result value returned from Read(). |
119 int read_result_; | 120 int read_result_; |
120 }; | 121 }; |
121 | 122 |
122 } // namespace | 123 } // namespace |
123 | 124 |
124 class UploadDataStreamTest : public PlatformTest { | 125 class UploadDataStreamTest : public PlatformTest { |
125 public: | 126 public: |
126 virtual void SetUp() OVERRIDE { | 127 virtual void SetUp() { |
| 128 PlatformTest::SetUp(); |
127 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 129 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
128 } | 130 } |
| 131 virtual ~UploadDataStreamTest() { |
| 132 element_readers_.clear(); |
| 133 base::RunLoop().RunUntilIdle(); |
| 134 } |
129 | 135 |
130 void FileChangedHelper(const base::FilePath& file_path, | 136 void FileChangedHelper(const base::FilePath& file_path, |
131 const base::Time& time, | 137 const base::Time& time, |
132 bool error_expected); | 138 bool error_expected); |
133 | 139 |
134 base::ScopedTempDir temp_dir_; | 140 base::ScopedTempDir temp_dir_; |
135 ScopedVector<UploadElementReader> element_readers_; | 141 ScopedVector<UploadElementReader> element_readers_; |
136 }; | 142 }; |
137 | 143 |
138 TEST_F(UploadDataStreamTest, EmptyUploadData) { | 144 TEST_F(UploadDataStreamTest, EmptyUploadData) { |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 wrapped_buffer2.get(), buf2.size(), read_callback2.callback())); | 811 wrapped_buffer2.get(), buf2.size(), read_callback2.callback())); |
806 EXPECT_EQ(static_cast<int>(buf2.size()), read_callback2.WaitForResult()); | 812 EXPECT_EQ(static_cast<int>(buf2.size()), read_callback2.WaitForResult()); |
807 EXPECT_EQ(expected_data, buf2); | 813 EXPECT_EQ(expected_data, buf2); |
808 EXPECT_TRUE(stream.IsEOF()); | 814 EXPECT_TRUE(stream.IsEOF()); |
809 | 815 |
810 // Make sure callbacks are not called for cancelled operations. | 816 // Make sure callbacks are not called for cancelled operations. |
811 EXPECT_FALSE(read_callback1.have_result()); | 817 EXPECT_FALSE(read_callback1.have_result()); |
812 } | 818 } |
813 | 819 |
814 } // namespace net | 820 } // namespace net |
OLD | NEW |