OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/chromeos/drive/webkit_file_stream_reader_impl.h" | 5 #include "chrome/browser/chromeos/drive/webkit_file_stream_reader_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 scoped_ptr<base::Thread> worker_thread_; | 66 scoped_ptr<base::Thread> worker_thread_; |
67 | 67 |
68 scoped_ptr<FakeDriveService> fake_drive_service_; | 68 scoped_ptr<FakeDriveService> fake_drive_service_; |
69 scoped_ptr<test_util::FakeFileSystem> fake_file_system_; | 69 scoped_ptr<test_util::FakeFileSystem> fake_file_system_; |
70 }; | 70 }; |
71 | 71 |
72 TEST_F(WebkitFileStreamReaderImplTest, ReadThenGetLength) { | 72 TEST_F(WebkitFileStreamReaderImplTest, ReadThenGetLength) { |
73 const base::FilePath kDriveFile = | 73 const base::FilePath kDriveFile = |
74 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); | 74 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); |
75 | 75 |
76 scoped_ptr<WebkitFileStreamReaderImpl> reader( | 76 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( |
77 new WebkitFileStreamReaderImpl( | 77 GetFileSystemGetter(), |
78 GetFileSystemGetter(), | 78 worker_thread_->message_loop_proxy().get(), |
79 worker_thread_->message_loop_proxy(), | 79 kDriveFile, |
80 kDriveFile, | 80 0, // offset |
81 0, // offset | 81 base::Time())); // expected modification time |
82 base::Time())); // expected modification time | |
83 | 82 |
84 std::string content; | 83 std::string content; |
85 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content)); | 84 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content)); |
86 | 85 |
87 net::TestInt64CompletionCallback callback; | 86 net::TestInt64CompletionCallback callback; |
88 int64 length = reader->GetLength(callback.callback()); | 87 int64 length = reader->GetLength(callback.callback()); |
89 length = callback.GetResult(length); | 88 length = callback.GetResult(length); |
90 EXPECT_EQ(content.size(), static_cast<size_t>(length)); | 89 EXPECT_EQ(content.size(), static_cast<size_t>(length)); |
91 } | 90 } |
92 | 91 |
93 TEST_F(WebkitFileStreamReaderImplTest, GetLengthThenRead) { | 92 TEST_F(WebkitFileStreamReaderImplTest, GetLengthThenRead) { |
94 const base::FilePath kDriveFile = | 93 const base::FilePath kDriveFile = |
95 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); | 94 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); |
96 | 95 |
97 scoped_ptr<WebkitFileStreamReaderImpl> reader( | 96 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( |
98 new WebkitFileStreamReaderImpl( | 97 GetFileSystemGetter(), |
99 GetFileSystemGetter(), | 98 worker_thread_->message_loop_proxy().get(), |
100 worker_thread_->message_loop_proxy(), | 99 kDriveFile, |
101 kDriveFile, | 100 0, // offset |
102 0, // offset | 101 base::Time())); // expected modification time |
103 base::Time())); // expected modification time | |
104 | 102 |
105 net::TestInt64CompletionCallback callback; | 103 net::TestInt64CompletionCallback callback; |
106 int64 length = reader->GetLength(callback.callback()); | 104 int64 length = reader->GetLength(callback.callback()); |
107 length = callback.GetResult(length); | 105 length = callback.GetResult(length); |
108 | 106 |
109 std::string content; | 107 std::string content; |
110 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content)); | 108 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content)); |
111 EXPECT_EQ(content.size(), static_cast<size_t>(length)); | 109 EXPECT_EQ(content.size(), static_cast<size_t>(length)); |
112 } | 110 } |
113 | 111 |
114 TEST_F(WebkitFileStreamReaderImplTest, ReadWithOffset) { | 112 TEST_F(WebkitFileStreamReaderImplTest, ReadWithOffset) { |
115 const base::FilePath kDriveFile = | 113 const base::FilePath kDriveFile = |
116 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); | 114 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); |
117 const int kOffset = 5; | 115 const int kOffset = 5; |
118 | 116 |
119 scoped_ptr<WebkitFileStreamReaderImpl> reader( | 117 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( |
120 new WebkitFileStreamReaderImpl( | 118 GetFileSystemGetter(), |
121 GetFileSystemGetter(), | 119 worker_thread_->message_loop_proxy().get(), |
122 worker_thread_->message_loop_proxy(), | 120 kDriveFile, |
123 kDriveFile, | 121 kOffset, |
124 kOffset, | 122 base::Time())); // expected modification time |
125 base::Time())); // expected modification time | |
126 | 123 |
127 std::string content; | 124 std::string content; |
128 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content)); | 125 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content)); |
129 | 126 |
130 net::TestInt64CompletionCallback callback; | 127 net::TestInt64CompletionCallback callback; |
131 int64 length = reader->GetLength(callback.callback()); | 128 int64 length = reader->GetLength(callback.callback()); |
132 length = callback.GetResult(length); | 129 length = callback.GetResult(length); |
133 EXPECT_EQ(content.size() + kOffset, static_cast<size_t>(length)); | 130 EXPECT_EQ(content.size() + kOffset, static_cast<size_t>(length)); |
134 } | 131 } |
135 | 132 |
136 TEST_F(WebkitFileStreamReaderImplTest, ReadError) { | 133 TEST_F(WebkitFileStreamReaderImplTest, ReadError) { |
137 const base::FilePath kDriveFile = | 134 const base::FilePath kDriveFile = |
138 util::GetDriveMyDriveRootPath().AppendASCII("non-existing.txt"); | 135 util::GetDriveMyDriveRootPath().AppendASCII("non-existing.txt"); |
139 | 136 |
140 scoped_ptr<WebkitFileStreamReaderImpl> reader( | 137 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( |
141 new WebkitFileStreamReaderImpl( | 138 GetFileSystemGetter(), |
142 GetFileSystemGetter(), | 139 worker_thread_->message_loop_proxy().get(), |
143 worker_thread_->message_loop_proxy(), | 140 kDriveFile, |
144 kDriveFile, | 141 0, // offset |
145 0, // offset | 142 base::Time())); // expected modification time |
146 base::Time())); // expected modification time | |
147 | 143 |
148 const int kBufferSize = 10; | 144 const int kBufferSize = 10; |
149 scoped_refptr<net::IOBuffer> io_buffer(new net::IOBuffer(kBufferSize)); | 145 scoped_refptr<net::IOBuffer> io_buffer(new net::IOBuffer(kBufferSize)); |
150 net::TestCompletionCallback callback; | 146 net::TestCompletionCallback callback; |
151 int result = reader->Read(io_buffer.get(), kBufferSize, callback.callback()); | 147 int result = reader->Read(io_buffer.get(), kBufferSize, callback.callback()); |
152 result = callback.GetResult(result); | 148 result = callback.GetResult(result); |
153 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, result); | 149 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, result); |
154 } | 150 } |
155 | 151 |
156 TEST_F(WebkitFileStreamReaderImplTest, GetLengthError) { | 152 TEST_F(WebkitFileStreamReaderImplTest, GetLengthError) { |
157 const base::FilePath kDriveFile = | 153 const base::FilePath kDriveFile = |
158 util::GetDriveMyDriveRootPath().AppendASCII("non-existing.txt"); | 154 util::GetDriveMyDriveRootPath().AppendASCII("non-existing.txt"); |
159 | 155 |
160 scoped_ptr<WebkitFileStreamReaderImpl> reader( | 156 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( |
161 new WebkitFileStreamReaderImpl( | 157 GetFileSystemGetter(), |
162 GetFileSystemGetter(), | 158 worker_thread_->message_loop_proxy().get(), |
163 worker_thread_->message_loop_proxy(), | 159 kDriveFile, |
164 kDriveFile, | 160 0, // offset |
165 0, // offset | 161 base::Time())); // expected modification time |
166 base::Time())); // expected modification time | |
167 | 162 |
168 net::TestInt64CompletionCallback callback; | 163 net::TestInt64CompletionCallback callback; |
169 int64 result = reader->GetLength(callback.callback()); | 164 int64 result = reader->GetLength(callback.callback()); |
170 result = callback.GetResult(result); | 165 result = callback.GetResult(result); |
171 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, result); | 166 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, result); |
172 } | 167 } |
173 | 168 |
174 TEST_F(WebkitFileStreamReaderImplTest, LastModification) { | 169 TEST_F(WebkitFileStreamReaderImplTest, LastModification) { |
175 const base::FilePath kDriveFile = | 170 const base::FilePath kDriveFile = |
176 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); | 171 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); |
177 | 172 |
178 base::Time expected_modification_time; | 173 base::Time expected_modification_time; |
179 ASSERT_TRUE(google_apis::util::GetTimeFromString( | 174 ASSERT_TRUE(google_apis::util::GetTimeFromString( |
180 "2011-12-14T00:40:47.330Z", &expected_modification_time)); | 175 "2011-12-14T00:40:47.330Z", &expected_modification_time)); |
181 scoped_ptr<WebkitFileStreamReaderImpl> reader( | 176 scoped_ptr<WebkitFileStreamReaderImpl> reader( |
182 new WebkitFileStreamReaderImpl( | 177 new WebkitFileStreamReaderImpl(GetFileSystemGetter(), |
183 GetFileSystemGetter(), | 178 worker_thread_->message_loop_proxy().get(), |
184 worker_thread_->message_loop_proxy(), | 179 kDriveFile, |
185 kDriveFile, | 180 0, // offset |
186 0, // offset | 181 expected_modification_time)); |
187 expected_modification_time)); | |
188 | 182 |
189 net::TestInt64CompletionCallback callback; | 183 net::TestInt64CompletionCallback callback; |
190 int64 result = reader->GetLength(callback.callback()); | 184 int64 result = reader->GetLength(callback.callback()); |
191 result = callback.GetResult(result); | 185 result = callback.GetResult(result); |
192 | 186 |
193 std::string content; | 187 std::string content; |
194 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content)); | 188 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content)); |
195 EXPECT_GE(content.size(), static_cast<size_t>(result)); | 189 EXPECT_GE(content.size(), static_cast<size_t>(result)); |
196 } | 190 } |
197 | 191 |
198 TEST_F(WebkitFileStreamReaderImplTest, LastModificationError) { | 192 TEST_F(WebkitFileStreamReaderImplTest, LastModificationError) { |
199 const base::FilePath kDriveFile = | 193 const base::FilePath kDriveFile = |
200 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); | 194 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); |
201 | 195 |
202 scoped_ptr<WebkitFileStreamReaderImpl> reader( | 196 scoped_ptr<WebkitFileStreamReaderImpl> reader( |
203 new WebkitFileStreamReaderImpl( | 197 new WebkitFileStreamReaderImpl(GetFileSystemGetter(), |
204 GetFileSystemGetter(), | 198 worker_thread_->message_loop_proxy().get(), |
205 worker_thread_->message_loop_proxy(), | 199 kDriveFile, |
206 kDriveFile, | 200 0, // offset |
207 0, // offset | 201 base::Time::FromInternalValue(1))); |
208 base::Time::FromInternalValue(1))); | |
209 | 202 |
210 net::TestInt64CompletionCallback callback; | 203 net::TestInt64CompletionCallback callback; |
211 int64 result = reader->GetLength(callback.callback()); | 204 int64 result = reader->GetLength(callback.callback()); |
212 result = callback.GetResult(result); | 205 result = callback.GetResult(result); |
213 EXPECT_EQ(net::ERR_UPLOAD_FILE_CHANGED, result); | 206 EXPECT_EQ(net::ERR_UPLOAD_FILE_CHANGED, result); |
214 } | 207 } |
215 | 208 |
216 } // namespace internal | 209 } // namespace internal |
217 } // namespace drive | 210 } // namespace drive |
OLD | NEW |