OLD | NEW |
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 "chrome/browser/chromeos/file_system_provider/fileapi/file_stream_write
r.h" | 5 #include "chrome/browser/chromeos/file_system_provider/fileapi/file_stream_write
r.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 std::vector<int> cancel_log; | 180 std::vector<int> cancel_log; |
181 const int cancel_result = writer.Cancel(base::Bind(&LogValue, &cancel_log)); | 181 const int cancel_result = writer.Cancel(base::Bind(&LogValue, &cancel_log)); |
182 EXPECT_EQ(net::ERR_IO_PENDING, cancel_result); | 182 EXPECT_EQ(net::ERR_IO_PENDING, cancel_result); |
183 base::RunLoop().RunUntilIdle(); | 183 base::RunLoop().RunUntilIdle(); |
184 | 184 |
185 EXPECT_EQ(0u, write_log.size()); | 185 EXPECT_EQ(0u, write_log.size()); |
186 ASSERT_EQ(1u, cancel_log.size()); | 186 ASSERT_EQ(1u, cancel_log.size()); |
187 EXPECT_EQ(net::OK, cancel_log[0]); | 187 EXPECT_EQ(net::OK, cancel_log[0]); |
188 } | 188 } |
189 | 189 |
| 190 TEST_F(FileSystemProviderFileStreamWriter, Cancel_NotRunning) { |
| 191 std::vector<int> write_log; |
| 192 |
| 193 const int64 initial_offset = 0; |
| 194 FileStreamWriter writer(file_url_, initial_offset); |
| 195 scoped_refptr<net::IOBuffer> io_buffer(new net::StringIOBuffer(kTextToWrite)); |
| 196 |
| 197 std::vector<int> cancel_log; |
| 198 const int cancel_result = writer.Cancel(base::Bind(&LogValue, &cancel_log)); |
| 199 EXPECT_EQ(net::ERR_UNEXPECTED, cancel_result); |
| 200 base::RunLoop().RunUntilIdle(); |
| 201 |
| 202 EXPECT_EQ(0u, write_log.size()); |
| 203 EXPECT_EQ(0u, cancel_log.size()); // Result returned synchronously. |
| 204 } |
| 205 |
190 TEST_F(FileSystemProviderFileStreamWriter, Write_WrongFile) { | 206 TEST_F(FileSystemProviderFileStreamWriter, Write_WrongFile) { |
191 std::vector<int> write_log; | 207 std::vector<int> write_log; |
192 | 208 |
193 const int64 initial_offset = 0; | 209 const int64 initial_offset = 0; |
194 FileStreamWriter writer(wrong_file_url_, initial_offset); | 210 FileStreamWriter writer(wrong_file_url_, initial_offset); |
195 scoped_refptr<net::IOBuffer> io_buffer(new net::StringIOBuffer(kTextToWrite)); | 211 scoped_refptr<net::IOBuffer> io_buffer(new net::StringIOBuffer(kTextToWrite)); |
196 | 212 |
197 const int result = writer.Write(io_buffer.get(), | 213 const int result = writer.Write(io_buffer.get(), |
198 sizeof(kTextToWrite) - 1, | 214 sizeof(kTextToWrite) - 1, |
199 base::Bind(&LogValue, &write_log)); | 215 base::Bind(&LogValue, &write_log)); |
(...skipping 26 matching lines...) Expand all Loading... |
226 | 242 |
227 ASSERT_EQ(1u, write_log.size()); | 243 ASSERT_EQ(1u, write_log.size()); |
228 EXPECT_EQ(sizeof(kTextToWrite) - 1, static_cast<size_t>(write_log[0])); | 244 EXPECT_EQ(sizeof(kTextToWrite) - 1, static_cast<size_t>(write_log[0])); |
229 | 245 |
230 const std::string expected_contents = original_contents + kTextToWrite; | 246 const std::string expected_contents = original_contents + kTextToWrite; |
231 EXPECT_EQ(expected_contents, entry->contents); | 247 EXPECT_EQ(expected_contents, entry->contents); |
232 } | 248 } |
233 | 249 |
234 } // namespace file_system_provider | 250 } // namespace file_system_provider |
235 } // namespace chromeos | 251 } // namespace chromeos |
OLD | NEW |