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

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

Issue 513683002: [fsp] Add support for providing thumbnails. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use scoped_ptr for EntryMetadata. Created 6 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
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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 const int result = writer.Write(io_buffer.get(), 127 const int result = writer.Write(io_buffer.get(),
128 sizeof(kTextToWrite) - 1, 128 sizeof(kTextToWrite) - 1,
129 base::Bind(&LogValue, &write_log)); 129 base::Bind(&LogValue, &write_log));
130 EXPECT_EQ(net::ERR_IO_PENDING, result); 130 EXPECT_EQ(net::ERR_IO_PENDING, result);
131 base::RunLoop().RunUntilIdle(); 131 base::RunLoop().RunUntilIdle();
132 132
133 ASSERT_EQ(1u, write_log.size()); 133 ASSERT_EQ(1u, write_log.size());
134 EXPECT_LT(0, write_log[0]); 134 EXPECT_LT(0, write_log[0]);
135 EXPECT_EQ(sizeof(kTextToWrite) - 1, static_cast<size_t>(write_log[0])); 135 EXPECT_EQ(sizeof(kTextToWrite) - 1, static_cast<size_t>(write_log[0]));
136 136
137 FakeEntry entry; 137 const FakeEntry* const entry = provided_file_system_->GetEntry(
138 ASSERT_TRUE(provided_file_system_->GetEntry( 138 base::FilePath::FromUTF8Unsafe(kFakeFilePath));
139 base::FilePath::FromUTF8Unsafe(kFakeFilePath), &entry)); 139 ASSERT_TRUE(entry);
140 EXPECT_EQ(kTextToWrite, entry.contents.substr(0, sizeof(kTextToWrite) - 1)); 140
141 EXPECT_EQ(kTextToWrite,
142 entry->contents.substr(0, sizeof(kTextToWrite) - 1));
141 } 143 }
142 144
143 // Write additional data to be sure, that the writer's offset is shifted 145 // Write additional data to be sure, that the writer's offset is shifted
144 // properly. 146 // properly.
145 { 147 {
146 const int result = writer.Write(io_buffer.get(), 148 const int result = writer.Write(io_buffer.get(),
147 sizeof(kTextToWrite) - 1, 149 sizeof(kTextToWrite) - 1,
148 base::Bind(&LogValue, &write_log)); 150 base::Bind(&LogValue, &write_log));
149 EXPECT_EQ(net::ERR_IO_PENDING, result); 151 EXPECT_EQ(net::ERR_IO_PENDING, result);
150 base::RunLoop().RunUntilIdle(); 152 base::RunLoop().RunUntilIdle();
151 153
152 ASSERT_EQ(2u, write_log.size()); 154 ASSERT_EQ(2u, write_log.size());
153 EXPECT_LT(0, write_log[0]); 155 EXPECT_LT(0, write_log[0]);
154 EXPECT_EQ(sizeof(kTextToWrite) - 1, static_cast<size_t>(write_log[0])); 156 EXPECT_EQ(sizeof(kTextToWrite) - 1, static_cast<size_t>(write_log[0]));
155 157
156 FakeEntry entry; 158 const FakeEntry* const entry = provided_file_system_->GetEntry(
157 ASSERT_TRUE(provided_file_system_->GetEntry( 159 base::FilePath::FromUTF8Unsafe(kFakeFilePath));
158 base::FilePath::FromUTF8Unsafe(kFakeFilePath), &entry)); 160 ASSERT_TRUE(entry);
159 161
160 // The testing text is written twice. 162 // The testing text is written twice.
161 const std::string expected_contents = 163 const std::string expected_contents =
162 std::string(kTextToWrite) + kTextToWrite; 164 std::string(kTextToWrite) + kTextToWrite;
163 EXPECT_EQ(expected_contents, 165 EXPECT_EQ(expected_contents,
164 entry.contents.substr(0, expected_contents.size())); 166 entry->contents.substr(0, expected_contents.size()));
165 } 167 }
166 } 168 }
167 169
168 TEST_F(FileSystemProviderFileStreamWriter, Cancel) { 170 TEST_F(FileSystemProviderFileStreamWriter, Cancel) {
169 std::vector<int> write_log; 171 std::vector<int> write_log;
170 172
171 const int64 initial_offset = 0; 173 const int64 initial_offset = 0;
172 FileStreamWriter writer(file_url_, initial_offset); 174 FileStreamWriter writer(file_url_, initial_offset);
173 scoped_refptr<net::IOBuffer> io_buffer(new net::StringIOBuffer(kTextToWrite)); 175 scoped_refptr<net::IOBuffer> io_buffer(new net::StringIOBuffer(kTextToWrite));
174 176
(...skipping 25 matching lines...) Expand all
200 EXPECT_EQ(net::ERR_IO_PENDING, result); 202 EXPECT_EQ(net::ERR_IO_PENDING, result);
201 base::RunLoop().RunUntilIdle(); 203 base::RunLoop().RunUntilIdle();
202 204
203 ASSERT_EQ(1u, write_log.size()); 205 ASSERT_EQ(1u, write_log.size());
204 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, write_log[0]); 206 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, write_log[0]);
205 } 207 }
206 208
207 TEST_F(FileSystemProviderFileStreamWriter, Write_Append) { 209 TEST_F(FileSystemProviderFileStreamWriter, Write_Append) {
208 std::vector<int> write_log; 210 std::vector<int> write_log;
209 211
210 FakeEntry entry_before; 212 const FakeEntry* const entry = provided_file_system_->GetEntry(
211 ASSERT_TRUE(provided_file_system_->GetEntry( 213 base::FilePath::FromUTF8Unsafe(kFakeFilePath));
212 base::FilePath::FromUTF8Unsafe(kFakeFilePath), &entry_before)); 214 ASSERT_TRUE(entry);
213 215
214 const int64 initial_offset = entry_before.metadata.size; 216 const int64 initial_offset = entry->metadata->size;
215 ASSERT_LT(0, initial_offset); 217 ASSERT_LT(0, initial_offset);
216 218
217 FileStreamWriter writer(file_url_, initial_offset); 219 FileStreamWriter writer(file_url_, initial_offset);
218 scoped_refptr<net::IOBuffer> io_buffer(new net::StringIOBuffer(kTextToWrite)); 220 scoped_refptr<net::IOBuffer> io_buffer(new net::StringIOBuffer(kTextToWrite));
219 221
220 const int result = writer.Write(io_buffer.get(), 222 const int result = writer.Write(io_buffer.get(),
221 sizeof(kTextToWrite) - 1, 223 sizeof(kTextToWrite) - 1,
222 base::Bind(&LogValue, &write_log)); 224 base::Bind(&LogValue, &write_log));
223 EXPECT_EQ(net::ERR_IO_PENDING, result); 225 EXPECT_EQ(net::ERR_IO_PENDING, result);
224 base::RunLoop().RunUntilIdle(); 226 base::RunLoop().RunUntilIdle();
225 227
226 ASSERT_EQ(1u, write_log.size()); 228 ASSERT_EQ(1u, write_log.size());
227 EXPECT_EQ(sizeof(kTextToWrite) - 1, static_cast<size_t>(write_log[0])); 229 EXPECT_EQ(sizeof(kTextToWrite) - 1, static_cast<size_t>(write_log[0]));
228 230
229 FakeEntry entry_after; 231 const std::string expected_contents = entry->contents + kTextToWrite;
230 ASSERT_TRUE(provided_file_system_->GetEntry( 232 EXPECT_EQ(expected_contents, entry->contents);
231 base::FilePath::FromUTF8Unsafe(kFakeFilePath), &entry_after));
232 const std::string expected_contents = entry_before.contents + kTextToWrite;
233 EXPECT_EQ(expected_contents, entry_after.contents);
234 } 233 }
235 234
236 } // namespace file_system_provider 235 } // namespace file_system_provider
237 } // namespace chromeos 236 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698