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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/fileapi/file_stream_writer_unittest.cc

Issue 440653003: [fsp] Add support for aborting running operations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up. Created 6 years, 4 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 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 base::FilePath::FromUTF8Unsafe(kFakeFilePath), &entry)); 158 base::FilePath::FromUTF8Unsafe(kFakeFilePath), &entry));
159 159
160 // The testing text is written twice. 160 // The testing text is written twice.
161 const std::string expected_contents = 161 const std::string expected_contents =
162 std::string(kTextToWrite) + kTextToWrite; 162 std::string(kTextToWrite) + kTextToWrite;
163 EXPECT_EQ(expected_contents, 163 EXPECT_EQ(expected_contents,
164 entry.contents.substr(0, expected_contents.size())); 164 entry.contents.substr(0, expected_contents.size()));
165 } 165 }
166 } 166 }
167 167
168 TEST_F(FileSystemProviderFileStreamWriter, Cancel) {
169 std::vector<int> write_log;
170
171 const int64 initial_offset = 0;
172 FileStreamWriter writer(file_url_, initial_offset);
173 scoped_refptr<net::IOBuffer> io_buffer(new net::StringIOBuffer(kTextToWrite));
174
175 const int write_result = writer.Write(io_buffer.get(),
176 sizeof(kTextToWrite) - 1,
177 base::Bind(&LogValue, &write_log));
178 EXPECT_EQ(net::ERR_IO_PENDING, write_result);
179
180 std::vector<int> cancel_log;
181 const int cancel_result = writer.Cancel(base::Bind(&LogValue, &cancel_log));
182 EXPECT_EQ(net::ERR_IO_PENDING, cancel_result);
183 base::RunLoop().RunUntilIdle();
184
185 EXPECT_EQ(0u, write_log.size());
186 ASSERT_EQ(1u, cancel_log.size());
187 EXPECT_EQ(net::OK, cancel_log[0]);
188 }
189
168 TEST_F(FileSystemProviderFileStreamWriter, Write_WrongFile) { 190 TEST_F(FileSystemProviderFileStreamWriter, Write_WrongFile) {
169 std::vector<int> write_log; 191 std::vector<int> write_log;
170 192
171 const int64 initial_offset = 0; 193 const int64 initial_offset = 0;
172 FileStreamWriter writer(wrong_file_url_, initial_offset); 194 FileStreamWriter writer(wrong_file_url_, initial_offset);
173 scoped_refptr<net::IOBuffer> io_buffer(new net::StringIOBuffer(kTextToWrite)); 195 scoped_refptr<net::IOBuffer> io_buffer(new net::StringIOBuffer(kTextToWrite));
174 196
175 const int result = writer.Write(io_buffer.get(), 197 const int result = writer.Write(io_buffer.get(),
176 sizeof(kTextToWrite) - 1, 198 sizeof(kTextToWrite) - 1,
177 base::Bind(&LogValue, &write_log)); 199 base::Bind(&LogValue, &write_log));
(...skipping 28 matching lines...) Expand all
206 228
207 FakeEntry entry_after; 229 FakeEntry entry_after;
208 ASSERT_TRUE(provided_file_system_->GetEntry( 230 ASSERT_TRUE(provided_file_system_->GetEntry(
209 base::FilePath::FromUTF8Unsafe(kFakeFilePath), &entry_after)); 231 base::FilePath::FromUTF8Unsafe(kFakeFilePath), &entry_after));
210 const std::string expected_contents = entry_before.contents + kTextToWrite; 232 const std::string expected_contents = entry_before.contents + kTextToWrite;
211 EXPECT_EQ(expected_contents, entry_after.contents); 233 EXPECT_EQ(expected_contents, entry_after.contents);
212 } 234 }
213 235
214 } // namespace file_system_provider 236 } // namespace file_system_provider
215 } // namespace chromeos 237 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698