OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 mojom::DirectoryPtr directory; | 21 mojom::DirectoryPtr directory; |
22 GetTemporaryRoot(&directory); | 22 GetTemporaryRoot(&directory); |
23 mojom::FileError error; | 23 mojom::FileError error; |
24 bool handled = false; | 24 bool handled = false; |
25 | 25 |
26 { | 26 { |
27 // Create my_file. | 27 // Create my_file. |
28 mojom::FilePtr file; | 28 mojom::FilePtr file; |
29 error = mojom::FileError::FAILED; | 29 error = mojom::FileError::FAILED; |
30 handled = | 30 handled = |
31 directory->OpenFile("my_file", GetProxy(&file), | 31 directory->OpenFile("my_file", MakeRequest(&file), |
32 mojom::kFlagWrite | mojom::kFlagCreate, &error); | 32 mojom::kFlagWrite | mojom::kFlagCreate, &error); |
33 ASSERT_TRUE(handled); | 33 ASSERT_TRUE(handled); |
34 EXPECT_EQ(mojom::FileError::OK, error); | 34 EXPECT_EQ(mojom::FileError::OK, error); |
35 | 35 |
36 // Write to it. | 36 // Write to it. |
37 std::vector<uint8_t> bytes_to_write; | 37 std::vector<uint8_t> bytes_to_write; |
38 bytes_to_write.push_back(static_cast<uint8_t>('h')); | 38 bytes_to_write.push_back(static_cast<uint8_t>('h')); |
39 bytes_to_write.push_back(static_cast<uint8_t>('e')); | 39 bytes_to_write.push_back(static_cast<uint8_t>('e')); |
40 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 40 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
41 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 41 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
(...skipping 17 matching lines...) Expand all Loading... |
59 error = mojom::FileError::FAILED; | 59 error = mojom::FileError::FAILED; |
60 handled = directory->Rename("my_file", "your_file", &error); | 60 handled = directory->Rename("my_file", "your_file", &error); |
61 ASSERT_TRUE(handled); | 61 ASSERT_TRUE(handled); |
62 EXPECT_EQ(mojom::FileError::OK, error); | 62 EXPECT_EQ(mojom::FileError::OK, error); |
63 | 63 |
64 { | 64 { |
65 // Open my_file again. | 65 // Open my_file again. |
66 mojom::FilePtr file; | 66 mojom::FilePtr file; |
67 error = mojom::FileError::FAILED; | 67 error = mojom::FileError::FAILED; |
68 bool handled = | 68 bool handled = |
69 directory->OpenFile("your_file", GetProxy(&file), | 69 directory->OpenFile("your_file", MakeRequest(&file), |
70 mojom::kFlagRead | mojom::kFlagOpen, &error); | 70 mojom::kFlagRead | mojom::kFlagOpen, &error); |
71 ASSERT_TRUE(handled); | 71 ASSERT_TRUE(handled); |
72 EXPECT_EQ(mojom::FileError::OK, error); | 72 EXPECT_EQ(mojom::FileError::OK, error); |
73 | 73 |
74 // Read from it. | 74 // Read from it. |
75 base::Optional<std::vector<uint8_t>> bytes_read; | 75 base::Optional<std::vector<uint8_t>> bytes_read; |
76 error = mojom::FileError::FAILED; | 76 error = mojom::FileError::FAILED; |
77 handled = file->Read(3, 1, mojom::Whence::FROM_BEGIN, &error, &bytes_read); | 77 handled = file->Read(3, 1, mojom::Whence::FROM_BEGIN, &error, &bytes_read); |
78 ASSERT_TRUE(handled); | 78 ASSERT_TRUE(handled); |
79 EXPECT_EQ(mojom::FileError::OK, error); | 79 EXPECT_EQ(mojom::FileError::OK, error); |
(...skipping 17 matching lines...) Expand all Loading... |
97 bytes_to_write.push_back(static_cast<uint8_t>('e')); | 97 bytes_to_write.push_back(static_cast<uint8_t>('e')); |
98 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 98 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
99 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 99 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
100 bytes_to_write.push_back(static_cast<uint8_t>('o')); | 100 bytes_to_write.push_back(static_cast<uint8_t>('o')); |
101 | 101 |
102 { | 102 { |
103 // Create my_file. | 103 // Create my_file. |
104 mojom::FilePtr file; | 104 mojom::FilePtr file; |
105 error = mojom::FileError::FAILED; | 105 error = mojom::FileError::FAILED; |
106 bool handled = | 106 bool handled = |
107 directory->OpenFile("my_file", GetProxy(&file), | 107 directory->OpenFile("my_file", MakeRequest(&file), |
108 mojom::kFlagWrite | mojom::kFlagCreate, &error); | 108 mojom::kFlagWrite | mojom::kFlagCreate, &error); |
109 ASSERT_TRUE(handled); | 109 ASSERT_TRUE(handled); |
110 EXPECT_EQ(mojom::FileError::OK, error); | 110 EXPECT_EQ(mojom::FileError::OK, error); |
111 | 111 |
112 // Write to it. | 112 // Write to it. |
113 error = mojom::FileError::FAILED; | 113 error = mojom::FileError::FAILED; |
114 uint32_t num_bytes_written = 0; | 114 uint32_t num_bytes_written = 0; |
115 handled = file->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT, | 115 handled = file->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT, |
116 &error, &num_bytes_written); | 116 &error, &num_bytes_written); |
117 ASSERT_TRUE(handled); | 117 ASSERT_TRUE(handled); |
118 EXPECT_EQ(mojom::FileError::OK, error); | 118 EXPECT_EQ(mojom::FileError::OK, error); |
119 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); | 119 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); |
120 | 120 |
121 // Close it. | 121 // Close it. |
122 error = mojom::FileError::FAILED; | 122 error = mojom::FileError::FAILED; |
123 handled = file->Close((&error)); | 123 handled = file->Close((&error)); |
124 ASSERT_TRUE(handled); | 124 ASSERT_TRUE(handled); |
125 EXPECT_EQ(mojom::FileError::OK, error); | 125 EXPECT_EQ(mojom::FileError::OK, error); |
126 } | 126 } |
127 | 127 |
128 { | 128 { |
129 // Open my_file again, this time with read only mode. | 129 // Open my_file again, this time with read only mode. |
130 mojom::FilePtr file; | 130 mojom::FilePtr file; |
131 error = mojom::FileError::FAILED; | 131 error = mojom::FileError::FAILED; |
132 bool handled = | 132 bool handled = |
133 directory->OpenFile("my_file", GetProxy(&file), | 133 directory->OpenFile("my_file", MakeRequest(&file), |
134 mojom::kFlagRead | mojom::kFlagOpen, &error); | 134 mojom::kFlagRead | mojom::kFlagOpen, &error); |
135 ASSERT_TRUE(handled); | 135 ASSERT_TRUE(handled); |
136 EXPECT_EQ(mojom::FileError::OK, error); | 136 EXPECT_EQ(mojom::FileError::OK, error); |
137 | 137 |
138 // Try to write in read mode; it should fail. | 138 // Try to write in read mode; it should fail. |
139 error = mojom::FileError::OK; | 139 error = mojom::FileError::OK; |
140 uint32_t num_bytes_written = 0; | 140 uint32_t num_bytes_written = 0; |
141 handled = file->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT, | 141 handled = file->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT, |
142 &error, &num_bytes_written); | 142 &error, &num_bytes_written); |
143 | 143 |
(...skipping 12 matching lines...) Expand all Loading... |
156 TEST_F(FileImplTest, OpenInAppendMode) { | 156 TEST_F(FileImplTest, OpenInAppendMode) { |
157 mojom::DirectoryPtr directory; | 157 mojom::DirectoryPtr directory; |
158 GetTemporaryRoot(&directory); | 158 GetTemporaryRoot(&directory); |
159 mojom::FileError error; | 159 mojom::FileError error; |
160 | 160 |
161 { | 161 { |
162 // Create my_file. | 162 // Create my_file. |
163 mojom::FilePtr file; | 163 mojom::FilePtr file; |
164 error = mojom::FileError::FAILED; | 164 error = mojom::FileError::FAILED; |
165 bool handled = | 165 bool handled = |
166 directory->OpenFile("my_file", GetProxy(&file), | 166 directory->OpenFile("my_file", MakeRequest(&file), |
167 mojom::kFlagWrite | mojom::kFlagCreate, &error); | 167 mojom::kFlagWrite | mojom::kFlagCreate, &error); |
168 ASSERT_TRUE(handled); | 168 ASSERT_TRUE(handled); |
169 EXPECT_EQ(mojom::FileError::OK, error); | 169 EXPECT_EQ(mojom::FileError::OK, error); |
170 | 170 |
171 // Write to it. | 171 // Write to it. |
172 std::vector<uint8_t> bytes_to_write; | 172 std::vector<uint8_t> bytes_to_write; |
173 bytes_to_write.push_back(static_cast<uint8_t>('h')); | 173 bytes_to_write.push_back(static_cast<uint8_t>('h')); |
174 bytes_to_write.push_back(static_cast<uint8_t>('e')); | 174 bytes_to_write.push_back(static_cast<uint8_t>('e')); |
175 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 175 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
176 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 176 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
(...skipping 11 matching lines...) Expand all Loading... |
188 handled = file->Close(&error); | 188 handled = file->Close(&error); |
189 ASSERT_TRUE(handled); | 189 ASSERT_TRUE(handled); |
190 EXPECT_EQ(mojom::FileError::OK, error); | 190 EXPECT_EQ(mojom::FileError::OK, error); |
191 } | 191 } |
192 | 192 |
193 { | 193 { |
194 // Append to my_file. | 194 // Append to my_file. |
195 mojom::FilePtr file; | 195 mojom::FilePtr file; |
196 error = mojom::FileError::FAILED; | 196 error = mojom::FileError::FAILED; |
197 bool handled = | 197 bool handled = |
198 directory->OpenFile("my_file", GetProxy(&file), | 198 directory->OpenFile("my_file", MakeRequest(&file), |
199 mojom::kFlagAppend | mojom::kFlagOpen, &error); | 199 mojom::kFlagAppend | mojom::kFlagOpen, &error); |
200 ASSERT_TRUE(handled); | 200 ASSERT_TRUE(handled); |
201 EXPECT_EQ(mojom::FileError::OK, error); | 201 EXPECT_EQ(mojom::FileError::OK, error); |
202 | 202 |
203 // Write to it. | 203 // Write to it. |
204 std::vector<uint8_t> bytes_to_write; | 204 std::vector<uint8_t> bytes_to_write; |
205 bytes_to_write.push_back(static_cast<uint8_t>('g')); | 205 bytes_to_write.push_back(static_cast<uint8_t>('g')); |
206 bytes_to_write.push_back(static_cast<uint8_t>('o')); | 206 bytes_to_write.push_back(static_cast<uint8_t>('o')); |
207 bytes_to_write.push_back(static_cast<uint8_t>('o')); | 207 bytes_to_write.push_back(static_cast<uint8_t>('o')); |
208 bytes_to_write.push_back(static_cast<uint8_t>('d')); | 208 bytes_to_write.push_back(static_cast<uint8_t>('d')); |
(...skipping 13 matching lines...) Expand all Loading... |
222 handled = file->Close((&error)); | 222 handled = file->Close((&error)); |
223 ASSERT_TRUE(handled); | 223 ASSERT_TRUE(handled); |
224 EXPECT_EQ(mojom::FileError::OK, error); | 224 EXPECT_EQ(mojom::FileError::OK, error); |
225 } | 225 } |
226 | 226 |
227 { | 227 { |
228 // Open my_file again. | 228 // Open my_file again. |
229 mojom::FilePtr file; | 229 mojom::FilePtr file; |
230 error = mojom::FileError::FAILED; | 230 error = mojom::FileError::FAILED; |
231 bool handled = | 231 bool handled = |
232 directory->OpenFile("my_file", GetProxy(&file), | 232 directory->OpenFile("my_file", MakeRequest(&file), |
233 mojom::kFlagRead | mojom::kFlagOpen, &error); | 233 mojom::kFlagRead | mojom::kFlagOpen, &error); |
234 ASSERT_TRUE(handled); | 234 ASSERT_TRUE(handled); |
235 EXPECT_EQ(mojom::FileError::OK, error); | 235 EXPECT_EQ(mojom::FileError::OK, error); |
236 | 236 |
237 // Read from it. | 237 // Read from it. |
238 base::Optional<std::vector<uint8_t>> bytes_read; | 238 base::Optional<std::vector<uint8_t>> bytes_read; |
239 error = mojom::FileError::FAILED; | 239 error = mojom::FileError::FAILED; |
240 handled = file->Read(12, 0, mojom::Whence::FROM_BEGIN, &error, &bytes_read); | 240 handled = file->Read(12, 0, mojom::Whence::FROM_BEGIN, &error, &bytes_read); |
241 ASSERT_TRUE(handled); | 241 ASSERT_TRUE(handled); |
242 EXPECT_EQ(mojom::FileError::OK, error); | 242 EXPECT_EQ(mojom::FileError::OK, error); |
243 ASSERT_TRUE(bytes_read.has_value()); | 243 ASSERT_TRUE(bytes_read.has_value()); |
244 ASSERT_EQ(12u, bytes_read.value().size()); | 244 ASSERT_EQ(12u, bytes_read.value().size()); |
245 EXPECT_EQ(static_cast<uint8_t>('l'), bytes_read.value()[3]); | 245 EXPECT_EQ(static_cast<uint8_t>('l'), bytes_read.value()[3]); |
246 EXPECT_EQ(static_cast<uint8_t>('o'), bytes_read.value()[4]); | 246 EXPECT_EQ(static_cast<uint8_t>('o'), bytes_read.value()[4]); |
247 EXPECT_EQ(static_cast<uint8_t>('g'), bytes_read.value()[5]); | 247 EXPECT_EQ(static_cast<uint8_t>('g'), bytes_read.value()[5]); |
248 EXPECT_EQ(static_cast<uint8_t>('o'), bytes_read.value()[6]); | 248 EXPECT_EQ(static_cast<uint8_t>('o'), bytes_read.value()[6]); |
249 } | 249 } |
250 } | 250 } |
251 | 251 |
252 TEST_F(FileImplTest, OpenInTruncateMode) { | 252 TEST_F(FileImplTest, OpenInTruncateMode) { |
253 mojom::DirectoryPtr directory; | 253 mojom::DirectoryPtr directory; |
254 GetTemporaryRoot(&directory); | 254 GetTemporaryRoot(&directory); |
255 mojom::FileError error; | 255 mojom::FileError error; |
256 | 256 |
257 { | 257 { |
258 // Create my_file. | 258 // Create my_file. |
259 mojom::FilePtr file; | 259 mojom::FilePtr file; |
260 error = mojom::FileError::FAILED; | 260 error = mojom::FileError::FAILED; |
261 bool handled = | 261 bool handled = |
262 directory->OpenFile("my_file", GetProxy(&file), | 262 directory->OpenFile("my_file", MakeRequest(&file), |
263 mojom::kFlagWrite | mojom::kFlagCreate, &error); | 263 mojom::kFlagWrite | mojom::kFlagCreate, &error); |
264 ASSERT_TRUE(handled); | 264 ASSERT_TRUE(handled); |
265 EXPECT_EQ(mojom::FileError::OK, error); | 265 EXPECT_EQ(mojom::FileError::OK, error); |
266 | 266 |
267 // Write to it. | 267 // Write to it. |
268 std::vector<uint8_t> bytes_to_write; | 268 std::vector<uint8_t> bytes_to_write; |
269 bytes_to_write.push_back(static_cast<uint8_t>('h')); | 269 bytes_to_write.push_back(static_cast<uint8_t>('h')); |
270 bytes_to_write.push_back(static_cast<uint8_t>('e')); | 270 bytes_to_write.push_back(static_cast<uint8_t>('e')); |
271 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 271 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
272 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 272 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
(...skipping 11 matching lines...) Expand all Loading... |
284 handled = file->Close(&error); | 284 handled = file->Close(&error); |
285 ASSERT_TRUE(handled); | 285 ASSERT_TRUE(handled); |
286 EXPECT_EQ(mojom::FileError::OK, error); | 286 EXPECT_EQ(mojom::FileError::OK, error); |
287 } | 287 } |
288 | 288 |
289 { | 289 { |
290 // Append to my_file. | 290 // Append to my_file. |
291 mojom::FilePtr file; | 291 mojom::FilePtr file; |
292 error = mojom::FileError::FAILED; | 292 error = mojom::FileError::FAILED; |
293 bool handled = directory->OpenFile( | 293 bool handled = directory->OpenFile( |
294 "my_file", GetProxy(&file), | 294 "my_file", MakeRequest(&file), |
295 mojom::kFlagWrite | mojom::kFlagOpenTruncated, &error); | 295 mojom::kFlagWrite | mojom::kFlagOpenTruncated, &error); |
296 ASSERT_TRUE(handled); | 296 ASSERT_TRUE(handled); |
297 EXPECT_EQ(mojom::FileError::OK, error); | 297 EXPECT_EQ(mojom::FileError::OK, error); |
298 | 298 |
299 // Write to it. | 299 // Write to it. |
300 std::vector<uint8_t> bytes_to_write; | 300 std::vector<uint8_t> bytes_to_write; |
301 bytes_to_write.push_back(static_cast<uint8_t>('g')); | 301 bytes_to_write.push_back(static_cast<uint8_t>('g')); |
302 bytes_to_write.push_back(static_cast<uint8_t>('o')); | 302 bytes_to_write.push_back(static_cast<uint8_t>('o')); |
303 bytes_to_write.push_back(static_cast<uint8_t>('o')); | 303 bytes_to_write.push_back(static_cast<uint8_t>('o')); |
304 bytes_to_write.push_back(static_cast<uint8_t>('d')); | 304 bytes_to_write.push_back(static_cast<uint8_t>('d')); |
(...skipping 13 matching lines...) Expand all Loading... |
318 handled = file->Close(&error); | 318 handled = file->Close(&error); |
319 ASSERT_TRUE(handled); | 319 ASSERT_TRUE(handled); |
320 EXPECT_EQ(mojom::FileError::OK, error); | 320 EXPECT_EQ(mojom::FileError::OK, error); |
321 } | 321 } |
322 | 322 |
323 { | 323 { |
324 // Open my_file again. | 324 // Open my_file again. |
325 mojom::FilePtr file; | 325 mojom::FilePtr file; |
326 error = mojom::FileError::FAILED; | 326 error = mojom::FileError::FAILED; |
327 bool handled = | 327 bool handled = |
328 directory->OpenFile("my_file", GetProxy(&file), | 328 directory->OpenFile("my_file", MakeRequest(&file), |
329 mojom::kFlagRead | mojom::kFlagOpen, &error); | 329 mojom::kFlagRead | mojom::kFlagOpen, &error); |
330 ASSERT_TRUE(handled); | 330 ASSERT_TRUE(handled); |
331 EXPECT_EQ(mojom::FileError::OK, error); | 331 EXPECT_EQ(mojom::FileError::OK, error); |
332 | 332 |
333 // Read from it. | 333 // Read from it. |
334 base::Optional<std::vector<uint8_t>> bytes_read; | 334 base::Optional<std::vector<uint8_t>> bytes_read; |
335 error = mojom::FileError::FAILED; | 335 error = mojom::FileError::FAILED; |
336 handled = file->Read(7, 0, mojom::Whence::FROM_BEGIN, &error, &bytes_read); | 336 handled = file->Read(7, 0, mojom::Whence::FROM_BEGIN, &error, &bytes_read); |
337 ASSERT_TRUE(handled); | 337 ASSERT_TRUE(handled); |
338 EXPECT_EQ(mojom::FileError::OK, error); | 338 EXPECT_EQ(mojom::FileError::OK, error); |
(...skipping 10 matching lines...) Expand all Loading... |
349 // least second-resolution support though. | 349 // least second-resolution support though. |
350 TEST_F(FileImplTest, StatTouch) { | 350 TEST_F(FileImplTest, StatTouch) { |
351 mojom::DirectoryPtr directory; | 351 mojom::DirectoryPtr directory; |
352 GetTemporaryRoot(&directory); | 352 GetTemporaryRoot(&directory); |
353 mojom::FileError error; | 353 mojom::FileError error; |
354 | 354 |
355 // Create my_file. | 355 // Create my_file. |
356 mojom::FilePtr file; | 356 mojom::FilePtr file; |
357 error = mojom::FileError::FAILED; | 357 error = mojom::FileError::FAILED; |
358 bool handled = | 358 bool handled = |
359 directory->OpenFile("my_file", GetProxy(&file), | 359 directory->OpenFile("my_file", MakeRequest(&file), |
360 mojom::kFlagWrite | mojom::kFlagCreate, &error); | 360 mojom::kFlagWrite | mojom::kFlagCreate, &error); |
361 ASSERT_TRUE(handled); | 361 ASSERT_TRUE(handled); |
362 EXPECT_EQ(mojom::FileError::OK, error); | 362 EXPECT_EQ(mojom::FileError::OK, error); |
363 | 363 |
364 // Stat it. | 364 // Stat it. |
365 error = mojom::FileError::FAILED; | 365 error = mojom::FileError::FAILED; |
366 mojom::FileInformationPtr file_info; | 366 mojom::FileInformationPtr file_info; |
367 handled = file->Stat(&error, &file_info); | 367 handled = file->Stat(&error, &file_info); |
368 ASSERT_TRUE(handled); | 368 ASSERT_TRUE(handled); |
369 EXPECT_EQ(mojom::FileError::OK, error); | 369 EXPECT_EQ(mojom::FileError::OK, error); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 420 |
421 TEST_F(FileImplTest, TellSeek) { | 421 TEST_F(FileImplTest, TellSeek) { |
422 mojom::DirectoryPtr directory; | 422 mojom::DirectoryPtr directory; |
423 GetTemporaryRoot(&directory); | 423 GetTemporaryRoot(&directory); |
424 mojom::FileError error; | 424 mojom::FileError error; |
425 | 425 |
426 // Create my_file. | 426 // Create my_file. |
427 mojom::FilePtr file; | 427 mojom::FilePtr file; |
428 error = mojom::FileError::FAILED; | 428 error = mojom::FileError::FAILED; |
429 bool handled = | 429 bool handled = |
430 directory->OpenFile("my_file", GetProxy(&file), | 430 directory->OpenFile("my_file", MakeRequest(&file), |
431 mojom::kFlagWrite | mojom::kFlagCreate, &error); | 431 mojom::kFlagWrite | mojom::kFlagCreate, &error); |
432 ASSERT_TRUE(handled); | 432 ASSERT_TRUE(handled); |
433 EXPECT_EQ(mojom::FileError::OK, error); | 433 EXPECT_EQ(mojom::FileError::OK, error); |
434 | 434 |
435 // Write to it. | 435 // Write to it. |
436 std::vector<uint8_t> bytes_to_write(1000, '!'); | 436 std::vector<uint8_t> bytes_to_write(1000, '!'); |
437 error = mojom::FileError::FAILED; | 437 error = mojom::FileError::FAILED; |
438 uint32_t num_bytes_written = 0; | 438 uint32_t num_bytes_written = 0; |
439 handled = file->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT, &error, | 439 handled = file->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT, &error, |
440 &num_bytes_written); | 440 &num_bytes_written); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 | 506 |
507 TEST_F(FileImplTest, Dup) { | 507 TEST_F(FileImplTest, Dup) { |
508 mojom::DirectoryPtr directory; | 508 mojom::DirectoryPtr directory; |
509 GetTemporaryRoot(&directory); | 509 GetTemporaryRoot(&directory); |
510 mojom::FileError error; | 510 mojom::FileError error; |
511 | 511 |
512 // Create my_file. | 512 // Create my_file. |
513 mojom::FilePtr file1; | 513 mojom::FilePtr file1; |
514 error = mojom::FileError::FAILED; | 514 error = mojom::FileError::FAILED; |
515 bool handled = directory->OpenFile( | 515 bool handled = directory->OpenFile( |
516 "my_file", GetProxy(&file1), | 516 "my_file", MakeRequest(&file1), |
517 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, &error); | 517 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, &error); |
518 ASSERT_TRUE(handled); | 518 ASSERT_TRUE(handled); |
519 EXPECT_EQ(mojom::FileError::OK, error); | 519 EXPECT_EQ(mojom::FileError::OK, error); |
520 | 520 |
521 // Write to it. | 521 // Write to it. |
522 std::vector<uint8_t> bytes_to_write; | 522 std::vector<uint8_t> bytes_to_write; |
523 bytes_to_write.push_back(static_cast<uint8_t>('h')); | 523 bytes_to_write.push_back(static_cast<uint8_t>('h')); |
524 bytes_to_write.push_back(static_cast<uint8_t>('e')); | 524 bytes_to_write.push_back(static_cast<uint8_t>('e')); |
525 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 525 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
526 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 526 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
527 bytes_to_write.push_back(static_cast<uint8_t>('o')); | 527 bytes_to_write.push_back(static_cast<uint8_t>('o')); |
528 error = mojom::FileError::FAILED; | 528 error = mojom::FileError::FAILED; |
529 uint32_t num_bytes_written = 0; | 529 uint32_t num_bytes_written = 0; |
530 handled = file1->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT, &error, | 530 handled = file1->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT, &error, |
531 &num_bytes_written); | 531 &num_bytes_written); |
532 ASSERT_TRUE(handled); | 532 ASSERT_TRUE(handled); |
533 EXPECT_EQ(mojom::FileError::OK, error); | 533 EXPECT_EQ(mojom::FileError::OK, error); |
534 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); | 534 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); |
535 const int end_hello_pos = static_cast<int>(num_bytes_written); | 535 const int end_hello_pos = static_cast<int>(num_bytes_written); |
536 | 536 |
537 // Dup it. | 537 // Dup it. |
538 mojom::FilePtr file2; | 538 mojom::FilePtr file2; |
539 error = mojom::FileError::FAILED; | 539 error = mojom::FileError::FAILED; |
540 handled = file1->Dup(GetProxy(&file2), &error); | 540 handled = file1->Dup(MakeRequest(&file2), &error); |
541 ASSERT_TRUE(handled); | 541 ASSERT_TRUE(handled); |
542 EXPECT_EQ(mojom::FileError::OK, error); | 542 EXPECT_EQ(mojom::FileError::OK, error); |
543 | 543 |
544 // |file2| should have the same position. | 544 // |file2| should have the same position. |
545 error = mojom::FileError::FAILED; | 545 error = mojom::FileError::FAILED; |
546 int64_t position = -1; | 546 int64_t position = -1; |
547 handled = file2->Tell(&error, &position); | 547 handled = file2->Tell(&error, &position); |
548 ASSERT_TRUE(handled); | 548 ASSERT_TRUE(handled); |
549 EXPECT_EQ(mojom::FileError::OK, error); | 549 EXPECT_EQ(mojom::FileError::OK, error); |
550 EXPECT_EQ(end_hello_pos, position); | 550 EXPECT_EQ(end_hello_pos, position); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 const uint32_t kTruncatedSize = 654; | 600 const uint32_t kTruncatedSize = 654; |
601 | 601 |
602 mojom::DirectoryPtr directory; | 602 mojom::DirectoryPtr directory; |
603 GetTemporaryRoot(&directory); | 603 GetTemporaryRoot(&directory); |
604 mojom::FileError error; | 604 mojom::FileError error; |
605 | 605 |
606 // Create my_file. | 606 // Create my_file. |
607 mojom::FilePtr file; | 607 mojom::FilePtr file; |
608 error = mojom::FileError::FAILED; | 608 error = mojom::FileError::FAILED; |
609 bool handled = | 609 bool handled = |
610 directory->OpenFile("my_file", GetProxy(&file), | 610 directory->OpenFile("my_file", MakeRequest(&file), |
611 mojom::kFlagWrite | mojom::kFlagCreate, &error); | 611 mojom::kFlagWrite | mojom::kFlagCreate, &error); |
612 ASSERT_TRUE(handled); | 612 ASSERT_TRUE(handled); |
613 EXPECT_EQ(mojom::FileError::OK, error); | 613 EXPECT_EQ(mojom::FileError::OK, error); |
614 | 614 |
615 // Write to it. | 615 // Write to it. |
616 std::vector<uint8_t> bytes_to_write(kInitialSize, '!'); | 616 std::vector<uint8_t> bytes_to_write(kInitialSize, '!'); |
617 error = mojom::FileError::FAILED; | 617 error = mojom::FileError::FAILED; |
618 uint32_t num_bytes_written = 0; | 618 uint32_t num_bytes_written = 0; |
619 handled = file->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT, &error, | 619 handled = file->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT, &error, |
620 &num_bytes_written); | 620 &num_bytes_written); |
(...skipping 29 matching lines...) Expand all Loading... |
650 TEST_F(FileImplTest, AsHandle) { | 650 TEST_F(FileImplTest, AsHandle) { |
651 mojom::DirectoryPtr directory; | 651 mojom::DirectoryPtr directory; |
652 GetTemporaryRoot(&directory); | 652 GetTemporaryRoot(&directory); |
653 mojom::FileError error; | 653 mojom::FileError error; |
654 | 654 |
655 { | 655 { |
656 // Create my_file. | 656 // Create my_file. |
657 mojom::FilePtr file1; | 657 mojom::FilePtr file1; |
658 error = mojom::FileError::FAILED; | 658 error = mojom::FileError::FAILED; |
659 bool handled = directory->OpenFile( | 659 bool handled = directory->OpenFile( |
660 "my_file", GetProxy(&file1), | 660 "my_file", MakeRequest(&file1), |
661 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, &error); | 661 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, &error); |
662 ASSERT_TRUE(handled); | 662 ASSERT_TRUE(handled); |
663 EXPECT_EQ(mojom::FileError::OK, error); | 663 EXPECT_EQ(mojom::FileError::OK, error); |
664 | 664 |
665 // Fetch the file. | 665 // Fetch the file. |
666 error = mojom::FileError::FAILED; | 666 error = mojom::FileError::FAILED; |
667 base::File raw_file; | 667 base::File raw_file; |
668 handled = file1->AsHandle(&error, &raw_file); | 668 handled = file1->AsHandle(&error, &raw_file); |
669 ASSERT_TRUE(handled); | 669 ASSERT_TRUE(handled); |
670 EXPECT_EQ(mojom::FileError::OK, error); | 670 EXPECT_EQ(mojom::FileError::OK, error); |
671 | 671 |
672 ASSERT_TRUE(raw_file.IsValid()); | 672 ASSERT_TRUE(raw_file.IsValid()); |
673 EXPECT_EQ(5, raw_file.WriteAtCurrentPos("hello", 5)); | 673 EXPECT_EQ(5, raw_file.WriteAtCurrentPos("hello", 5)); |
674 } | 674 } |
675 | 675 |
676 { | 676 { |
677 // Reopen my_file. | 677 // Reopen my_file. |
678 mojom::FilePtr file2; | 678 mojom::FilePtr file2; |
679 error = mojom::FileError::FAILED; | 679 error = mojom::FileError::FAILED; |
680 bool handled = | 680 bool handled = |
681 directory->OpenFile("my_file", GetProxy(&file2), | 681 directory->OpenFile("my_file", MakeRequest(&file2), |
682 mojom::kFlagRead | mojom::kFlagOpen, &error); | 682 mojom::kFlagRead | mojom::kFlagOpen, &error); |
683 ASSERT_TRUE(handled); | 683 ASSERT_TRUE(handled); |
684 EXPECT_EQ(mojom::FileError::OK, error); | 684 EXPECT_EQ(mojom::FileError::OK, error); |
685 | 685 |
686 // Verify that we wrote data raw on the file descriptor. | 686 // Verify that we wrote data raw on the file descriptor. |
687 base::Optional<std::vector<uint8_t>> bytes_read; | 687 base::Optional<std::vector<uint8_t>> bytes_read; |
688 error = mojom::FileError::FAILED; | 688 error = mojom::FileError::FAILED; |
689 handled = file2->Read(5, 0, mojom::Whence::FROM_BEGIN, &error, &bytes_read); | 689 handled = file2->Read(5, 0, mojom::Whence::FROM_BEGIN, &error, &bytes_read); |
690 ASSERT_TRUE(handled); | 690 ASSERT_TRUE(handled); |
691 EXPECT_EQ(mojom::FileError::OK, error); | 691 EXPECT_EQ(mojom::FileError::OK, error); |
692 ASSERT_TRUE(bytes_read.has_value()); | 692 ASSERT_TRUE(bytes_read.has_value()); |
693 ASSERT_EQ(5u, bytes_read.value().size()); | 693 ASSERT_EQ(5u, bytes_read.value().size()); |
694 EXPECT_EQ(static_cast<uint8_t>('h'), bytes_read.value()[0]); | 694 EXPECT_EQ(static_cast<uint8_t>('h'), bytes_read.value()[0]); |
695 EXPECT_EQ(static_cast<uint8_t>('e'), bytes_read.value()[1]); | 695 EXPECT_EQ(static_cast<uint8_t>('e'), bytes_read.value()[1]); |
696 EXPECT_EQ(static_cast<uint8_t>('l'), bytes_read.value()[2]); | 696 EXPECT_EQ(static_cast<uint8_t>('l'), bytes_read.value()[2]); |
697 EXPECT_EQ(static_cast<uint8_t>('l'), bytes_read.value()[3]); | 697 EXPECT_EQ(static_cast<uint8_t>('l'), bytes_read.value()[3]); |
698 EXPECT_EQ(static_cast<uint8_t>('o'), bytes_read.value()[4]); | 698 EXPECT_EQ(static_cast<uint8_t>('o'), bytes_read.value()[4]); |
699 } | 699 } |
700 } | 700 } |
701 | 701 |
702 TEST_F(FileImplTest, SimpleLockUnlock) { | 702 TEST_F(FileImplTest, SimpleLockUnlock) { |
703 mojom::DirectoryPtr directory; | 703 mojom::DirectoryPtr directory; |
704 GetTemporaryRoot(&directory); | 704 GetTemporaryRoot(&directory); |
705 mojom::FileError error; | 705 mojom::FileError error; |
706 | 706 |
707 // Create my_file. | 707 // Create my_file. |
708 mojom::FilePtr file; | 708 mojom::FilePtr file; |
709 error = mojom::FileError::FAILED; | 709 error = mojom::FileError::FAILED; |
710 bool handled = directory->OpenFile( | 710 bool handled = directory->OpenFile( |
711 "my_file", GetProxy(&file), | 711 "my_file", MakeRequest(&file), |
712 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, &error); | 712 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, &error); |
713 ASSERT_TRUE(handled); | 713 ASSERT_TRUE(handled); |
714 EXPECT_EQ(mojom::FileError::OK, error); | 714 EXPECT_EQ(mojom::FileError::OK, error); |
715 | 715 |
716 // Lock the file. | 716 // Lock the file. |
717 error = mojom::FileError::FAILED; | 717 error = mojom::FileError::FAILED; |
718 handled = file->Lock(&error); | 718 handled = file->Lock(&error); |
719 ASSERT_TRUE(handled); | 719 ASSERT_TRUE(handled); |
720 EXPECT_EQ(mojom::FileError::OK, error); | 720 EXPECT_EQ(mojom::FileError::OK, error); |
721 | 721 |
722 // Unlock the file. | 722 // Unlock the file. |
723 error = mojom::FileError::FAILED; | 723 error = mojom::FileError::FAILED; |
724 handled = file->Unlock(&error); | 724 handled = file->Unlock(&error); |
725 ASSERT_TRUE(handled); | 725 ASSERT_TRUE(handled); |
726 EXPECT_EQ(mojom::FileError::OK, error); | 726 EXPECT_EQ(mojom::FileError::OK, error); |
727 } | 727 } |
728 | 728 |
729 TEST_F(FileImplTest, CantDoubleLock) { | 729 TEST_F(FileImplTest, CantDoubleLock) { |
730 mojom::DirectoryPtr directory; | 730 mojom::DirectoryPtr directory; |
731 GetTemporaryRoot(&directory); | 731 GetTemporaryRoot(&directory); |
732 mojom::FileError error; | 732 mojom::FileError error; |
733 | 733 |
734 // Create my_file. | 734 // Create my_file. |
735 mojom::FilePtr file; | 735 mojom::FilePtr file; |
736 error = mojom::FileError::FAILED; | 736 error = mojom::FileError::FAILED; |
737 bool handled = directory->OpenFile( | 737 bool handled = directory->OpenFile( |
738 "my_file", GetProxy(&file), | 738 "my_file", MakeRequest(&file), |
739 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, &error); | 739 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, &error); |
740 ASSERT_TRUE(handled); | 740 ASSERT_TRUE(handled); |
741 EXPECT_EQ(mojom::FileError::OK, error); | 741 EXPECT_EQ(mojom::FileError::OK, error); |
742 | 742 |
743 // Lock the file. | 743 // Lock the file. |
744 error = mojom::FileError::FAILED; | 744 error = mojom::FileError::FAILED; |
745 handled = file->Lock(&error); | 745 handled = file->Lock(&error); |
746 ASSERT_TRUE(handled); | 746 ASSERT_TRUE(handled); |
747 EXPECT_EQ(mojom::FileError::OK, error); | 747 EXPECT_EQ(mojom::FileError::OK, error); |
748 | 748 |
749 // Lock the file again. | 749 // Lock the file again. |
750 error = mojom::FileError::OK; | 750 error = mojom::FileError::OK; |
751 handled = file->Lock(&error); | 751 handled = file->Lock(&error); |
752 ASSERT_TRUE(handled); | 752 ASSERT_TRUE(handled); |
753 EXPECT_EQ(mojom::FileError::FAILED, error); | 753 EXPECT_EQ(mojom::FileError::FAILED, error); |
754 } | 754 } |
755 | 755 |
756 TEST_F(FileImplTest, ClosingFileClearsLock) { | 756 TEST_F(FileImplTest, ClosingFileClearsLock) { |
757 mojom::DirectoryPtr directory; | 757 mojom::DirectoryPtr directory; |
758 GetTemporaryRoot(&directory); | 758 GetTemporaryRoot(&directory); |
759 mojom::FileError error; | 759 mojom::FileError error; |
760 | 760 |
761 { | 761 { |
762 // Create my_file. | 762 // Create my_file. |
763 mojom::FilePtr file; | 763 mojom::FilePtr file; |
764 error = mojom::FileError::FAILED; | 764 error = mojom::FileError::FAILED; |
765 bool handled = directory->OpenFile( | 765 bool handled = directory->OpenFile( |
766 "my_file", GetProxy(&file), | 766 "my_file", MakeRequest(&file), |
767 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagOpenAlways, &error); | 767 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagOpenAlways, &error); |
768 ASSERT_TRUE(handled); | 768 ASSERT_TRUE(handled); |
769 EXPECT_EQ(mojom::FileError::OK, error); | 769 EXPECT_EQ(mojom::FileError::OK, error); |
770 | 770 |
771 // Lock the file. | 771 // Lock the file. |
772 error = mojom::FileError::FAILED; | 772 error = mojom::FileError::FAILED; |
773 handled = file->Lock(&error); | 773 handled = file->Lock(&error); |
774 ASSERT_TRUE(handled); | 774 ASSERT_TRUE(handled); |
775 EXPECT_EQ(mojom::FileError::OK, error); | 775 EXPECT_EQ(mojom::FileError::OK, error); |
776 } | 776 } |
777 | 777 |
778 { | 778 { |
779 // Open the file again. | 779 // Open the file again. |
780 mojom::FilePtr file; | 780 mojom::FilePtr file; |
781 error = mojom::FileError::FAILED; | 781 error = mojom::FileError::FAILED; |
782 bool handled = directory->OpenFile( | 782 bool handled = directory->OpenFile( |
783 "my_file", GetProxy(&file), | 783 "my_file", MakeRequest(&file), |
784 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagOpenAlways, &error); | 784 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagOpenAlways, &error); |
785 ASSERT_TRUE(handled); | 785 ASSERT_TRUE(handled); |
786 EXPECT_EQ(mojom::FileError::OK, error); | 786 EXPECT_EQ(mojom::FileError::OK, error); |
787 | 787 |
788 // The file shouldn't be locked (and we check by trying to lock it). | 788 // The file shouldn't be locked (and we check by trying to lock it). |
789 error = mojom::FileError::FAILED; | 789 error = mojom::FileError::FAILED; |
790 handled = file->Lock(&error); | 790 handled = file->Lock(&error); |
791 ASSERT_TRUE(handled); | 791 ASSERT_TRUE(handled); |
792 EXPECT_EQ(mojom::FileError::OK, error); | 792 EXPECT_EQ(mojom::FileError::OK, error); |
793 } | 793 } |
794 } | 794 } |
795 | 795 |
796 } // namespace | 796 } // namespace |
797 } // namespace filesystem | 797 } // namespace filesystem |
OLD | NEW |