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" |
11 #include "components/filesystem/files_test_base.h" | 11 #include "components/filesystem/files_test_base.h" |
12 #include "mojo/platform_handle/platform_handle_functions.h" | 12 #include "mojo/platform_handle/platform_handle_functions.h" |
13 #include "mojo/public/cpp/bindings/interface_request.h" | 13 #include "mojo/public/cpp/bindings/interface_request.h" |
14 #include "mojo/public/cpp/bindings/type_converter.h" | 14 #include "mojo/public/cpp/bindings/type_converter.h" |
15 #include "mojo/util/capture_util.h" | 15 #include "mojo/util/capture_util.h" |
16 | 16 |
17 using mojo::Capture; | 17 using mojo::Capture; |
18 | 18 |
19 namespace filesystem { | 19 namespace filesystem { |
20 namespace { | 20 namespace { |
21 | 21 |
22 using FileImplTest = FilesTestBase; | 22 using FileImplTest = FilesTestBase; |
23 | 23 |
24 TEST_F(FileImplTest, CreateWriteCloseRenameOpenRead) { | 24 TEST_F(FileImplTest, CreateWriteCloseRenameOpenRead) { |
25 DirectoryPtr directory; | 25 mojom::DirectoryPtr directory; |
26 GetTemporaryRoot(&directory); | 26 GetTemporaryRoot(&directory); |
27 FileError error; | 27 mojom::FileError error; |
28 | 28 |
29 { | 29 { |
30 // Create my_file. | 30 // Create my_file. |
31 FilePtr file; | 31 mojom::FilePtr file; |
32 error = FileError::FAILED; | 32 error = mojom::FileError::FAILED; |
33 directory->OpenFile("my_file", GetProxy(&file), kFlagWrite | kFlagCreate, | 33 directory->OpenFile("my_file", GetProxy(&file), |
| 34 mojom::kFlagWrite | mojom::kFlagCreate, |
34 Capture(&error)); | 35 Capture(&error)); |
35 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 36 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
36 EXPECT_EQ(FileError::OK, error); | 37 EXPECT_EQ(mojom::FileError::OK, error); |
37 | 38 |
38 // Write to it. | 39 // Write to it. |
39 std::vector<uint8_t> bytes_to_write; | 40 std::vector<uint8_t> bytes_to_write; |
40 bytes_to_write.push_back(static_cast<uint8_t>('h')); | 41 bytes_to_write.push_back(static_cast<uint8_t>('h')); |
41 bytes_to_write.push_back(static_cast<uint8_t>('e')); | 42 bytes_to_write.push_back(static_cast<uint8_t>('e')); |
42 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 43 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
43 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 44 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
44 bytes_to_write.push_back(static_cast<uint8_t>('o')); | 45 bytes_to_write.push_back(static_cast<uint8_t>('o')); |
45 error = FileError::FAILED; | 46 error = mojom::FileError::FAILED; |
46 uint32_t num_bytes_written = 0; | 47 uint32_t num_bytes_written = 0; |
47 file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, | 48 file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, |
48 Whence::FROM_CURRENT, Capture(&error, &num_bytes_written)); | 49 mojom::Whence::FROM_CURRENT, |
| 50 Capture(&error, &num_bytes_written)); |
49 ASSERT_TRUE(file.WaitForIncomingResponse()); | 51 ASSERT_TRUE(file.WaitForIncomingResponse()); |
50 EXPECT_EQ(FileError::OK, error); | 52 EXPECT_EQ(mojom::FileError::OK, error); |
51 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); | 53 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); |
52 | 54 |
53 // Close it. | 55 // Close it. |
54 error = FileError::FAILED; | 56 error = mojom::FileError::FAILED; |
55 file->Close(Capture(&error)); | 57 file->Close(Capture(&error)); |
56 ASSERT_TRUE(file.WaitForIncomingResponse()); | 58 ASSERT_TRUE(file.WaitForIncomingResponse()); |
57 EXPECT_EQ(FileError::OK, error); | 59 EXPECT_EQ(mojom::FileError::OK, error); |
58 } | 60 } |
59 | 61 |
60 // Rename it. | 62 // Rename it. |
61 error = FileError::FAILED; | 63 error = mojom::FileError::FAILED; |
62 directory->Rename("my_file", "your_file", Capture(&error)); | 64 directory->Rename("my_file", "your_file", Capture(&error)); |
63 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 65 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
64 EXPECT_EQ(FileError::OK, error); | 66 EXPECT_EQ(mojom::FileError::OK, error); |
65 | 67 |
66 { | 68 { |
67 // Open my_file again. | 69 // Open my_file again. |
68 FilePtr file; | 70 mojom::FilePtr file; |
69 error = FileError::FAILED; | 71 error = mojom::FileError::FAILED; |
70 directory->OpenFile("your_file", GetProxy(&file), kFlagRead | kFlagOpen, | 72 directory->OpenFile("your_file", GetProxy(&file), |
71 Capture(&error)); | 73 mojom::kFlagRead | mojom::kFlagOpen, Capture(&error)); |
72 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 74 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
73 EXPECT_EQ(FileError::OK, error); | 75 EXPECT_EQ(mojom::FileError::OK, error); |
74 | 76 |
75 // Read from it. | 77 // Read from it. |
76 mojo::Array<uint8_t> bytes_read; | 78 mojo::Array<uint8_t> bytes_read; |
77 error = FileError::FAILED; | 79 error = mojom::FileError::FAILED; |
78 file->Read(3, 1, Whence::FROM_BEGIN, Capture(&error, &bytes_read)); | 80 file->Read(3, 1, mojom::Whence::FROM_BEGIN, Capture(&error, &bytes_read)); |
79 ASSERT_TRUE(file.WaitForIncomingResponse()); | 81 ASSERT_TRUE(file.WaitForIncomingResponse()); |
80 EXPECT_EQ(FileError::OK, error); | 82 EXPECT_EQ(mojom::FileError::OK, error); |
81 ASSERT_EQ(3u, bytes_read.size()); | 83 ASSERT_EQ(3u, bytes_read.size()); |
82 EXPECT_EQ(static_cast<uint8_t>('e'), bytes_read[0]); | 84 EXPECT_EQ(static_cast<uint8_t>('e'), bytes_read[0]); |
83 EXPECT_EQ(static_cast<uint8_t>('l'), bytes_read[1]); | 85 EXPECT_EQ(static_cast<uint8_t>('l'), bytes_read[1]); |
84 EXPECT_EQ(static_cast<uint8_t>('l'), bytes_read[2]); | 86 EXPECT_EQ(static_cast<uint8_t>('l'), bytes_read[2]); |
85 } | 87 } |
86 | 88 |
87 // TODO(vtl): Test read/write offset options. | 89 // TODO(vtl): Test read/write offset options. |
88 } | 90 } |
89 | 91 |
90 TEST_F(FileImplTest, CantWriteInReadMode) { | 92 TEST_F(FileImplTest, CantWriteInReadMode) { |
91 DirectoryPtr directory; | 93 mojom::DirectoryPtr directory; |
92 GetTemporaryRoot(&directory); | 94 GetTemporaryRoot(&directory); |
93 FileError error; | 95 mojom::FileError error; |
94 | 96 |
95 std::vector<uint8_t> bytes_to_write; | 97 std::vector<uint8_t> bytes_to_write; |
96 bytes_to_write.push_back(static_cast<uint8_t>('h')); | 98 bytes_to_write.push_back(static_cast<uint8_t>('h')); |
97 bytes_to_write.push_back(static_cast<uint8_t>('e')); | 99 bytes_to_write.push_back(static_cast<uint8_t>('e')); |
98 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 100 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
99 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 101 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
100 bytes_to_write.push_back(static_cast<uint8_t>('o')); | 102 bytes_to_write.push_back(static_cast<uint8_t>('o')); |
101 | 103 |
102 { | 104 { |
103 // Create my_file. | 105 // Create my_file. |
104 FilePtr file; | 106 mojom::FilePtr file; |
105 error = FileError::FAILED; | 107 error = mojom::FileError::FAILED; |
106 directory->OpenFile("my_file", GetProxy(&file), kFlagWrite | kFlagCreate, | 108 directory->OpenFile("my_file", GetProxy(&file), |
| 109 mojom::kFlagWrite | mojom::kFlagCreate, |
107 Capture(&error)); | 110 Capture(&error)); |
108 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 111 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
109 EXPECT_EQ(FileError::OK, error); | 112 EXPECT_EQ(mojom::FileError::OK, error); |
110 | 113 |
111 // Write to it. | 114 // Write to it. |
112 error = FileError::FAILED; | 115 error = mojom::FileError::FAILED; |
113 uint32_t num_bytes_written = 0; | 116 uint32_t num_bytes_written = 0; |
114 file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, | 117 file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, |
115 Whence::FROM_CURRENT, Capture(&error, &num_bytes_written)); | 118 mojom::Whence::FROM_CURRENT, |
| 119 Capture(&error, &num_bytes_written)); |
116 ASSERT_TRUE(file.WaitForIncomingResponse()); | 120 ASSERT_TRUE(file.WaitForIncomingResponse()); |
117 EXPECT_EQ(FileError::OK, error); | 121 EXPECT_EQ(mojom::FileError::OK, error); |
118 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); | 122 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); |
119 | 123 |
120 // Close it. | 124 // Close it. |
121 error = FileError::FAILED; | 125 error = mojom::FileError::FAILED; |
122 file->Close(Capture(&error)); | 126 file->Close(Capture(&error)); |
123 ASSERT_TRUE(file.WaitForIncomingResponse()); | 127 ASSERT_TRUE(file.WaitForIncomingResponse()); |
124 EXPECT_EQ(FileError::OK, error); | 128 EXPECT_EQ(mojom::FileError::OK, error); |
125 } | 129 } |
126 | 130 |
127 { | 131 { |
128 // Open my_file again, this time with read only mode. | 132 // Open my_file again, this time with read only mode. |
129 FilePtr file; | 133 mojom::FilePtr file; |
130 error = FileError::FAILED; | 134 error = mojom::FileError::FAILED; |
131 directory->OpenFile("my_file", GetProxy(&file), kFlagRead | kFlagOpen, | 135 directory->OpenFile("my_file", GetProxy(&file), |
132 Capture(&error)); | 136 mojom::kFlagRead | mojom::kFlagOpen, Capture(&error)); |
133 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 137 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
134 EXPECT_EQ(FileError::OK, error); | 138 EXPECT_EQ(mojom::FileError::OK, error); |
135 | 139 |
136 // Try to write in read mode; it should fail. | 140 // Try to write in read mode; it should fail. |
137 error = FileError::OK; | 141 error = mojom::FileError::OK; |
138 uint32_t num_bytes_written = 0; | 142 uint32_t num_bytes_written = 0; |
139 file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, | 143 file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, |
140 Whence::FROM_CURRENT, Capture(&error, &num_bytes_written)); | 144 mojom::Whence::FROM_CURRENT, |
| 145 Capture(&error, &num_bytes_written)); |
141 | 146 |
142 ASSERT_TRUE(file.WaitForIncomingResponse()); | 147 ASSERT_TRUE(file.WaitForIncomingResponse()); |
143 EXPECT_EQ(FileError::FAILED, error); | 148 EXPECT_EQ(mojom::FileError::FAILED, error); |
144 EXPECT_EQ(0u, num_bytes_written); | 149 EXPECT_EQ(0u, num_bytes_written); |
145 | 150 |
146 // Close it. | 151 // Close it. |
147 error = FileError::FAILED; | 152 error = mojom::FileError::FAILED; |
148 file->Close(Capture(&error)); | 153 file->Close(Capture(&error)); |
149 ASSERT_TRUE(file.WaitForIncomingResponse()); | 154 ASSERT_TRUE(file.WaitForIncomingResponse()); |
150 EXPECT_EQ(FileError::OK, error); | 155 EXPECT_EQ(mojom::FileError::OK, error); |
151 } | 156 } |
152 } | 157 } |
153 | 158 |
154 TEST_F(FileImplTest, OpenInAppendMode) { | 159 TEST_F(FileImplTest, OpenInAppendMode) { |
155 DirectoryPtr directory; | 160 mojom::DirectoryPtr directory; |
156 GetTemporaryRoot(&directory); | 161 GetTemporaryRoot(&directory); |
157 FileError error; | 162 mojom::FileError error; |
158 | 163 |
159 { | 164 { |
160 // Create my_file. | 165 // Create my_file. |
161 FilePtr file; | 166 mojom::FilePtr file; |
162 error = FileError::FAILED; | 167 error = mojom::FileError::FAILED; |
163 directory->OpenFile("my_file", GetProxy(&file), kFlagWrite | kFlagCreate, | 168 directory->OpenFile("my_file", GetProxy(&file), |
| 169 mojom::kFlagWrite | mojom::kFlagCreate, |
164 Capture(&error)); | 170 Capture(&error)); |
165 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 171 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
166 EXPECT_EQ(FileError::OK, error); | 172 EXPECT_EQ(mojom::FileError::OK, error); |
167 | 173 |
168 // Write to it. | 174 // Write to it. |
169 std::vector<uint8_t> bytes_to_write; | 175 std::vector<uint8_t> bytes_to_write; |
170 bytes_to_write.push_back(static_cast<uint8_t>('h')); | 176 bytes_to_write.push_back(static_cast<uint8_t>('h')); |
171 bytes_to_write.push_back(static_cast<uint8_t>('e')); | 177 bytes_to_write.push_back(static_cast<uint8_t>('e')); |
172 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 178 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
173 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 179 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
174 bytes_to_write.push_back(static_cast<uint8_t>('o')); | 180 bytes_to_write.push_back(static_cast<uint8_t>('o')); |
175 error = FileError::FAILED; | 181 error = mojom::FileError::FAILED; |
176 uint32_t num_bytes_written = 0; | 182 uint32_t num_bytes_written = 0; |
177 file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, | 183 file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, |
178 Whence::FROM_CURRENT, Capture(&error, &num_bytes_written)); | 184 mojom::Whence::FROM_CURRENT, |
| 185 Capture(&error, &num_bytes_written)); |
179 ASSERT_TRUE(file.WaitForIncomingResponse()); | 186 ASSERT_TRUE(file.WaitForIncomingResponse()); |
180 EXPECT_EQ(FileError::OK, error); | 187 EXPECT_EQ(mojom::FileError::OK, error); |
181 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); | 188 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); |
182 | 189 |
183 // Close it. | 190 // Close it. |
184 error = FileError::FAILED; | 191 error = mojom::FileError::FAILED; |
185 file->Close(Capture(&error)); | 192 file->Close(Capture(&error)); |
186 ASSERT_TRUE(file.WaitForIncomingResponse()); | 193 ASSERT_TRUE(file.WaitForIncomingResponse()); |
187 EXPECT_EQ(FileError::OK, error); | 194 EXPECT_EQ(mojom::FileError::OK, error); |
188 } | 195 } |
189 | 196 |
190 { | 197 { |
191 // Append to my_file. | 198 // Append to my_file. |
192 FilePtr file; | 199 mojom::FilePtr file; |
193 error = FileError::FAILED; | 200 error = mojom::FileError::FAILED; |
194 directory->OpenFile("my_file", GetProxy(&file), kFlagAppend | kFlagOpen, | 201 directory->OpenFile("my_file", GetProxy(&file), |
195 Capture(&error)); | 202 mojom::kFlagAppend | mojom::kFlagOpen, Capture(&error)); |
196 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 203 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
197 EXPECT_EQ(FileError::OK, error); | 204 EXPECT_EQ(mojom::FileError::OK, error); |
198 | 205 |
199 // Write to it. | 206 // Write to it. |
200 std::vector<uint8_t> bytes_to_write; | 207 std::vector<uint8_t> bytes_to_write; |
201 bytes_to_write.push_back(static_cast<uint8_t>('g')); | 208 bytes_to_write.push_back(static_cast<uint8_t>('g')); |
202 bytes_to_write.push_back(static_cast<uint8_t>('o')); | 209 bytes_to_write.push_back(static_cast<uint8_t>('o')); |
203 bytes_to_write.push_back(static_cast<uint8_t>('o')); | 210 bytes_to_write.push_back(static_cast<uint8_t>('o')); |
204 bytes_to_write.push_back(static_cast<uint8_t>('d')); | 211 bytes_to_write.push_back(static_cast<uint8_t>('d')); |
205 bytes_to_write.push_back(static_cast<uint8_t>('b')); | 212 bytes_to_write.push_back(static_cast<uint8_t>('b')); |
206 bytes_to_write.push_back(static_cast<uint8_t>('y')); | 213 bytes_to_write.push_back(static_cast<uint8_t>('y')); |
207 bytes_to_write.push_back(static_cast<uint8_t>('e')); | 214 bytes_to_write.push_back(static_cast<uint8_t>('e')); |
208 error = FileError::FAILED; | 215 error = mojom::FileError::FAILED; |
209 uint32_t num_bytes_written = 0; | 216 uint32_t num_bytes_written = 0; |
210 file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, | 217 file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, |
211 Whence::FROM_CURRENT, Capture(&error, &num_bytes_written)); | 218 mojom::Whence::FROM_CURRENT, |
| 219 Capture(&error, &num_bytes_written)); |
212 ASSERT_TRUE(file.WaitForIncomingResponse()); | 220 ASSERT_TRUE(file.WaitForIncomingResponse()); |
213 EXPECT_EQ(FileError::OK, error); | 221 EXPECT_EQ(mojom::FileError::OK, error); |
214 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); | 222 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); |
215 | 223 |
216 // Close it. | 224 // Close it. |
217 error = FileError::FAILED; | 225 error = mojom::FileError::FAILED; |
218 file->Close(Capture(&error)); | 226 file->Close(Capture(&error)); |
219 ASSERT_TRUE(file.WaitForIncomingResponse()); | 227 ASSERT_TRUE(file.WaitForIncomingResponse()); |
220 EXPECT_EQ(FileError::OK, error); | 228 EXPECT_EQ(mojom::FileError::OK, error); |
221 } | 229 } |
222 | 230 |
223 { | 231 { |
224 // Open my_file again. | 232 // Open my_file again. |
225 FilePtr file; | 233 mojom::FilePtr file; |
226 error = FileError::FAILED; | 234 error = mojom::FileError::FAILED; |
227 directory->OpenFile("my_file", GetProxy(&file), kFlagRead | kFlagOpen, | 235 directory->OpenFile("my_file", GetProxy(&file), |
228 Capture(&error)); | 236 mojom::kFlagRead | mojom::kFlagOpen, Capture(&error)); |
229 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 237 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
230 EXPECT_EQ(FileError::OK, error); | 238 EXPECT_EQ(mojom::FileError::OK, error); |
231 | 239 |
232 // Read from it. | 240 // Read from it. |
233 mojo::Array<uint8_t> bytes_read; | 241 mojo::Array<uint8_t> bytes_read; |
234 error = FileError::FAILED; | 242 error = mojom::FileError::FAILED; |
235 file->Read(12, 0, Whence::FROM_BEGIN, Capture(&error, &bytes_read)); | 243 file->Read(12, 0, mojom::Whence::FROM_BEGIN, Capture(&error, &bytes_read)); |
236 ASSERT_TRUE(file.WaitForIncomingResponse()); | 244 ASSERT_TRUE(file.WaitForIncomingResponse()); |
237 EXPECT_EQ(FileError::OK, error); | 245 EXPECT_EQ(mojom::FileError::OK, error); |
238 ASSERT_EQ(12u, bytes_read.size()); | 246 ASSERT_EQ(12u, bytes_read.size()); |
239 EXPECT_EQ(static_cast<uint8_t>('l'), bytes_read[3]); | 247 EXPECT_EQ(static_cast<uint8_t>('l'), bytes_read[3]); |
240 EXPECT_EQ(static_cast<uint8_t>('o'), bytes_read[4]); | 248 EXPECT_EQ(static_cast<uint8_t>('o'), bytes_read[4]); |
241 EXPECT_EQ(static_cast<uint8_t>('g'), bytes_read[5]); | 249 EXPECT_EQ(static_cast<uint8_t>('g'), bytes_read[5]); |
242 EXPECT_EQ(static_cast<uint8_t>('o'), bytes_read[6]); | 250 EXPECT_EQ(static_cast<uint8_t>('o'), bytes_read[6]); |
243 } | 251 } |
244 } | 252 } |
245 | 253 |
246 TEST_F(FileImplTest, OpenInTruncateMode) { | 254 TEST_F(FileImplTest, OpenInTruncateMode) { |
247 DirectoryPtr directory; | 255 mojom::DirectoryPtr directory; |
248 GetTemporaryRoot(&directory); | 256 GetTemporaryRoot(&directory); |
249 FileError error; | 257 mojom::FileError error; |
250 | 258 |
251 { | 259 { |
252 // Create my_file. | 260 // Create my_file. |
253 FilePtr file; | 261 mojom::FilePtr file; |
254 error = FileError::FAILED; | 262 error = mojom::FileError::FAILED; |
255 directory->OpenFile("my_file", GetProxy(&file), kFlagWrite | kFlagCreate, | 263 directory->OpenFile("my_file", GetProxy(&file), |
| 264 mojom::kFlagWrite | mojom::kFlagCreate, |
256 Capture(&error)); | 265 Capture(&error)); |
257 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 266 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
258 EXPECT_EQ(FileError::OK, error); | 267 EXPECT_EQ(mojom::FileError::OK, error); |
259 | 268 |
260 // Write to it. | 269 // Write to it. |
261 std::vector<uint8_t> bytes_to_write; | 270 std::vector<uint8_t> bytes_to_write; |
262 bytes_to_write.push_back(static_cast<uint8_t>('h')); | 271 bytes_to_write.push_back(static_cast<uint8_t>('h')); |
263 bytes_to_write.push_back(static_cast<uint8_t>('e')); | 272 bytes_to_write.push_back(static_cast<uint8_t>('e')); |
264 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 273 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
265 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 274 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
266 bytes_to_write.push_back(static_cast<uint8_t>('o')); | 275 bytes_to_write.push_back(static_cast<uint8_t>('o')); |
267 error = FileError::FAILED; | 276 error = mojom::FileError::FAILED; |
268 uint32_t num_bytes_written = 0; | 277 uint32_t num_bytes_written = 0; |
269 file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, | 278 file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, |
270 Whence::FROM_CURRENT, Capture(&error, &num_bytes_written)); | 279 mojom::Whence::FROM_CURRENT, |
| 280 Capture(&error, &num_bytes_written)); |
271 ASSERT_TRUE(file.WaitForIncomingResponse()); | 281 ASSERT_TRUE(file.WaitForIncomingResponse()); |
272 EXPECT_EQ(FileError::OK, error); | 282 EXPECT_EQ(mojom::FileError::OK, error); |
273 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); | 283 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); |
274 | 284 |
275 // Close it. | 285 // Close it. |
276 error = FileError::FAILED; | 286 error = mojom::FileError::FAILED; |
277 file->Close(Capture(&error)); | 287 file->Close(Capture(&error)); |
278 ASSERT_TRUE(file.WaitForIncomingResponse()); | 288 ASSERT_TRUE(file.WaitForIncomingResponse()); |
279 EXPECT_EQ(FileError::OK, error); | 289 EXPECT_EQ(mojom::FileError::OK, error); |
280 } | 290 } |
281 | 291 |
282 { | 292 { |
283 // Append to my_file. | 293 // Append to my_file. |
284 FilePtr file; | 294 mojom::FilePtr file; |
285 error = FileError::FAILED; | 295 error = mojom::FileError::FAILED; |
286 directory->OpenFile("my_file", GetProxy(&file), | 296 directory->OpenFile("my_file", GetProxy(&file), |
287 kFlagWrite | kFlagOpenTruncated, Capture(&error)); | 297 mojom::kFlagWrite | mojom::kFlagOpenTruncated, |
| 298 Capture(&error)); |
288 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 299 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
289 EXPECT_EQ(FileError::OK, error); | 300 EXPECT_EQ(mojom::FileError::OK, error); |
290 | 301 |
291 // Write to it. | 302 // Write to it. |
292 std::vector<uint8_t> bytes_to_write; | 303 std::vector<uint8_t> bytes_to_write; |
293 bytes_to_write.push_back(static_cast<uint8_t>('g')); | 304 bytes_to_write.push_back(static_cast<uint8_t>('g')); |
294 bytes_to_write.push_back(static_cast<uint8_t>('o')); | 305 bytes_to_write.push_back(static_cast<uint8_t>('o')); |
295 bytes_to_write.push_back(static_cast<uint8_t>('o')); | 306 bytes_to_write.push_back(static_cast<uint8_t>('o')); |
296 bytes_to_write.push_back(static_cast<uint8_t>('d')); | 307 bytes_to_write.push_back(static_cast<uint8_t>('d')); |
297 bytes_to_write.push_back(static_cast<uint8_t>('b')); | 308 bytes_to_write.push_back(static_cast<uint8_t>('b')); |
298 bytes_to_write.push_back(static_cast<uint8_t>('y')); | 309 bytes_to_write.push_back(static_cast<uint8_t>('y')); |
299 bytes_to_write.push_back(static_cast<uint8_t>('e')); | 310 bytes_to_write.push_back(static_cast<uint8_t>('e')); |
300 error = FileError::FAILED; | 311 error = mojom::FileError::FAILED; |
301 uint32_t num_bytes_written = 0; | 312 uint32_t num_bytes_written = 0; |
302 file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, | 313 file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, |
303 Whence::FROM_CURRENT, Capture(&error, &num_bytes_written)); | 314 mojom::Whence::FROM_CURRENT, |
| 315 Capture(&error, &num_bytes_written)); |
304 ASSERT_TRUE(file.WaitForIncomingResponse()); | 316 ASSERT_TRUE(file.WaitForIncomingResponse()); |
305 EXPECT_EQ(FileError::OK, error); | 317 EXPECT_EQ(mojom::FileError::OK, error); |
306 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); | 318 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); |
307 | 319 |
308 // Close it. | 320 // Close it. |
309 error = FileError::FAILED; | 321 error = mojom::FileError::FAILED; |
310 file->Close(Capture(&error)); | 322 file->Close(Capture(&error)); |
311 ASSERT_TRUE(file.WaitForIncomingResponse()); | 323 ASSERT_TRUE(file.WaitForIncomingResponse()); |
312 EXPECT_EQ(FileError::OK, error); | 324 EXPECT_EQ(mojom::FileError::OK, error); |
313 } | 325 } |
314 | 326 |
315 { | 327 { |
316 // Open my_file again. | 328 // Open my_file again. |
317 FilePtr file; | 329 mojom::FilePtr file; |
318 error = FileError::FAILED; | 330 error = mojom::FileError::FAILED; |
319 directory->OpenFile("my_file", GetProxy(&file), kFlagRead | kFlagOpen, | 331 directory->OpenFile("my_file", GetProxy(&file), |
320 Capture(&error)); | 332 mojom::kFlagRead | mojom::kFlagOpen, Capture(&error)); |
321 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 333 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
322 EXPECT_EQ(FileError::OK, error); | 334 EXPECT_EQ(mojom::FileError::OK, error); |
323 | 335 |
324 // Read from it. | 336 // Read from it. |
325 mojo::Array<uint8_t> bytes_read; | 337 mojo::Array<uint8_t> bytes_read; |
326 error = FileError::FAILED; | 338 error = mojom::FileError::FAILED; |
327 file->Read(7, 0, Whence::FROM_BEGIN, Capture(&error, &bytes_read)); | 339 file->Read(7, 0, mojom::Whence::FROM_BEGIN, Capture(&error, &bytes_read)); |
328 ASSERT_TRUE(file.WaitForIncomingResponse()); | 340 ASSERT_TRUE(file.WaitForIncomingResponse()); |
329 EXPECT_EQ(FileError::OK, error); | 341 EXPECT_EQ(mojom::FileError::OK, error); |
330 ASSERT_EQ(7u, bytes_read.size()); | 342 ASSERT_EQ(7u, bytes_read.size()); |
331 EXPECT_EQ(static_cast<uint8_t>('g'), bytes_read[0]); | 343 EXPECT_EQ(static_cast<uint8_t>('g'), bytes_read[0]); |
332 EXPECT_EQ(static_cast<uint8_t>('o'), bytes_read[1]); | 344 EXPECT_EQ(static_cast<uint8_t>('o'), bytes_read[1]); |
333 EXPECT_EQ(static_cast<uint8_t>('o'), bytes_read[2]); | 345 EXPECT_EQ(static_cast<uint8_t>('o'), bytes_read[2]); |
334 EXPECT_EQ(static_cast<uint8_t>('d'), bytes_read[3]); | 346 EXPECT_EQ(static_cast<uint8_t>('d'), bytes_read[3]); |
335 } | 347 } |
336 } | 348 } |
337 | 349 |
338 // Note: Ignore nanoseconds, since it may not always be supported. We expect at | 350 // Note: Ignore nanoseconds, since it may not always be supported. We expect at |
339 // least second-resolution support though. | 351 // least second-resolution support though. |
340 TEST_F(FileImplTest, StatTouch) { | 352 TEST_F(FileImplTest, StatTouch) { |
341 DirectoryPtr directory; | 353 mojom::DirectoryPtr directory; |
342 GetTemporaryRoot(&directory); | 354 GetTemporaryRoot(&directory); |
343 FileError error; | 355 mojom::FileError error; |
344 | 356 |
345 // Create my_file. | 357 // Create my_file. |
346 FilePtr file; | 358 mojom::FilePtr file; |
347 error = FileError::FAILED; | 359 error = mojom::FileError::FAILED; |
348 directory->OpenFile("my_file", GetProxy(&file), kFlagWrite | kFlagCreate, | 360 directory->OpenFile("my_file", GetProxy(&file), |
349 Capture(&error)); | 361 mojom::kFlagWrite | mojom::kFlagCreate, Capture(&error)); |
350 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 362 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
351 EXPECT_EQ(FileError::OK, error); | 363 EXPECT_EQ(mojom::FileError::OK, error); |
352 | 364 |
353 // Stat it. | 365 // Stat it. |
354 error = FileError::FAILED; | 366 error = mojom::FileError::FAILED; |
355 FileInformationPtr file_info; | 367 mojom::FileInformationPtr file_info; |
356 file->Stat(Capture(&error, &file_info)); | 368 file->Stat(Capture(&error, &file_info)); |
357 ASSERT_TRUE(file.WaitForIncomingResponse()); | 369 ASSERT_TRUE(file.WaitForIncomingResponse()); |
358 EXPECT_EQ(FileError::OK, error); | 370 EXPECT_EQ(mojom::FileError::OK, error); |
359 ASSERT_FALSE(file_info.is_null()); | 371 ASSERT_FALSE(file_info.is_null()); |
360 EXPECT_EQ(FsFileType::REGULAR_FILE, file_info->type); | 372 EXPECT_EQ(mojom::FsFileType::REGULAR_FILE, file_info->type); |
361 EXPECT_EQ(0, file_info->size); | 373 EXPECT_EQ(0, file_info->size); |
362 EXPECT_GT(file_info->atime, 0); // Expect that it's not 1970-01-01. | 374 EXPECT_GT(file_info->atime, 0); // Expect that it's not 1970-01-01. |
363 EXPECT_GT(file_info->mtime, 0); | 375 EXPECT_GT(file_info->mtime, 0); |
364 double first_mtime = file_info->mtime; | 376 double first_mtime = file_info->mtime; |
365 | 377 |
366 // Touch only the atime. | 378 // Touch only the atime. |
367 error = FileError::FAILED; | 379 error = mojom::FileError::FAILED; |
368 TimespecOrNowPtr t(TimespecOrNow::New()); | 380 mojom::TimespecOrNowPtr t(mojom::TimespecOrNow::New()); |
369 t->now = false; | 381 t->now = false; |
370 const int64_t kPartyTime1 = 1234567890; // Party like it's 2009-02-13. | 382 const int64_t kPartyTime1 = 1234567890; // Party like it's 2009-02-13. |
371 t->seconds = kPartyTime1; | 383 t->seconds = kPartyTime1; |
372 file->Touch(std::move(t), nullptr, Capture(&error)); | 384 file->Touch(std::move(t), nullptr, Capture(&error)); |
373 ASSERT_TRUE(file.WaitForIncomingResponse()); | 385 ASSERT_TRUE(file.WaitForIncomingResponse()); |
374 EXPECT_EQ(FileError::OK, error); | 386 EXPECT_EQ(mojom::FileError::OK, error); |
375 | 387 |
376 // Stat again. | 388 // Stat again. |
377 error = FileError::FAILED; | 389 error = mojom::FileError::FAILED; |
378 file_info.reset(); | 390 file_info.reset(); |
379 file->Stat(Capture(&error, &file_info)); | 391 file->Stat(Capture(&error, &file_info)); |
380 ASSERT_TRUE(file.WaitForIncomingResponse()); | 392 ASSERT_TRUE(file.WaitForIncomingResponse()); |
381 EXPECT_EQ(FileError::OK, error); | 393 EXPECT_EQ(mojom::FileError::OK, error); |
382 ASSERT_FALSE(file_info.is_null()); | 394 ASSERT_FALSE(file_info.is_null()); |
383 EXPECT_EQ(kPartyTime1, file_info->atime); | 395 EXPECT_EQ(kPartyTime1, file_info->atime); |
384 EXPECT_EQ(first_mtime, file_info->mtime); | 396 EXPECT_EQ(first_mtime, file_info->mtime); |
385 | 397 |
386 // Touch only the mtime. | 398 // Touch only the mtime. |
387 t = TimespecOrNow::New(); | 399 t = mojom::TimespecOrNow::New(); |
388 t->now = false; | 400 t->now = false; |
389 const int64_t kPartyTime2 = 1425059525; // No time like the present. | 401 const int64_t kPartyTime2 = 1425059525; // No time like the present. |
390 t->seconds = kPartyTime2; | 402 t->seconds = kPartyTime2; |
391 file->Touch(nullptr, std::move(t), Capture(&error)); | 403 file->Touch(nullptr, std::move(t), Capture(&error)); |
392 ASSERT_TRUE(file.WaitForIncomingResponse()); | 404 ASSERT_TRUE(file.WaitForIncomingResponse()); |
393 EXPECT_EQ(FileError::OK, error); | 405 EXPECT_EQ(mojom::FileError::OK, error); |
394 | 406 |
395 // Stat again. | 407 // Stat again. |
396 error = FileError::FAILED; | 408 error = mojom::FileError::FAILED; |
397 file_info.reset(); | 409 file_info.reset(); |
398 file->Stat(Capture(&error, &file_info)); | 410 file->Stat(Capture(&error, &file_info)); |
399 ASSERT_TRUE(file.WaitForIncomingResponse()); | 411 ASSERT_TRUE(file.WaitForIncomingResponse()); |
400 EXPECT_EQ(FileError::OK, error); | 412 EXPECT_EQ(mojom::FileError::OK, error); |
401 ASSERT_FALSE(file_info.is_null()); | 413 ASSERT_FALSE(file_info.is_null()); |
402 EXPECT_EQ(kPartyTime1, file_info->atime); | 414 EXPECT_EQ(kPartyTime1, file_info->atime); |
403 EXPECT_EQ(kPartyTime2, file_info->mtime); | 415 EXPECT_EQ(kPartyTime2, file_info->mtime); |
404 | 416 |
405 // TODO(vtl): Also test non-zero file size. | 417 // TODO(vtl): Also test non-zero file size. |
406 // TODO(vtl): Also test Touch() "now" options. | 418 // TODO(vtl): Also test Touch() "now" options. |
407 // TODO(vtl): Also test touching both atime and mtime. | 419 // TODO(vtl): Also test touching both atime and mtime. |
408 } | 420 } |
409 | 421 |
410 TEST_F(FileImplTest, TellSeek) { | 422 TEST_F(FileImplTest, TellSeek) { |
411 DirectoryPtr directory; | 423 mojom::DirectoryPtr directory; |
412 GetTemporaryRoot(&directory); | 424 GetTemporaryRoot(&directory); |
413 FileError error; | 425 mojom::FileError error; |
414 | 426 |
415 // Create my_file. | 427 // Create my_file. |
416 FilePtr file; | 428 mojom::FilePtr file; |
417 error = FileError::FAILED; | 429 error = mojom::FileError::FAILED; |
418 directory->OpenFile("my_file", GetProxy(&file), kFlagWrite | kFlagCreate, | 430 directory->OpenFile("my_file", GetProxy(&file), |
419 Capture(&error)); | 431 mojom::kFlagWrite | mojom::kFlagCreate, Capture(&error)); |
420 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 432 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
421 EXPECT_EQ(FileError::OK, error); | 433 EXPECT_EQ(mojom::FileError::OK, error); |
422 | 434 |
423 // Write to it. | 435 // Write to it. |
424 std::vector<uint8_t> bytes_to_write(1000, '!'); | 436 std::vector<uint8_t> bytes_to_write(1000, '!'); |
425 error = FileError::FAILED; | 437 error = mojom::FileError::FAILED; |
426 uint32_t num_bytes_written = 0; | 438 uint32_t num_bytes_written = 0; |
427 file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, | 439 file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, |
428 Whence::FROM_CURRENT, Capture(&error, &num_bytes_written)); | 440 mojom::Whence::FROM_CURRENT, Capture(&error, &num_bytes_written)); |
429 ASSERT_TRUE(file.WaitForIncomingResponse()); | 441 ASSERT_TRUE(file.WaitForIncomingResponse()); |
430 EXPECT_EQ(FileError::OK, error); | 442 EXPECT_EQ(mojom::FileError::OK, error); |
431 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); | 443 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); |
432 const int size = static_cast<int>(num_bytes_written); | 444 const int size = static_cast<int>(num_bytes_written); |
433 | 445 |
434 // Tell. | 446 // Tell. |
435 error = FileError::FAILED; | 447 error = mojom::FileError::FAILED; |
436 int64_t position = -1; | 448 int64_t position = -1; |
437 file->Tell(Capture(&error, &position)); | 449 file->Tell(Capture(&error, &position)); |
438 ASSERT_TRUE(file.WaitForIncomingResponse()); | 450 ASSERT_TRUE(file.WaitForIncomingResponse()); |
439 // Should be at the end. | 451 // Should be at the end. |
440 EXPECT_EQ(FileError::OK, error); | 452 EXPECT_EQ(mojom::FileError::OK, error); |
441 EXPECT_EQ(size, position); | 453 EXPECT_EQ(size, position); |
442 | 454 |
443 // Seek back 100. | 455 // Seek back 100. |
444 error = FileError::FAILED; | 456 error = mojom::FileError::FAILED; |
445 position = -1; | 457 position = -1; |
446 file->Seek(-100, Whence::FROM_CURRENT, Capture(&error, &position)); | 458 file->Seek(-100, mojom::Whence::FROM_CURRENT, Capture(&error, &position)); |
447 ASSERT_TRUE(file.WaitForIncomingResponse()); | 459 ASSERT_TRUE(file.WaitForIncomingResponse()); |
448 EXPECT_EQ(FileError::OK, error); | 460 EXPECT_EQ(mojom::FileError::OK, error); |
449 EXPECT_EQ(size - 100, position); | 461 EXPECT_EQ(size - 100, position); |
450 | 462 |
451 // Tell. | 463 // Tell. |
452 error = FileError::FAILED; | 464 error = mojom::FileError::FAILED; |
453 position = -1; | 465 position = -1; |
454 file->Tell(Capture(&error, &position)); | 466 file->Tell(Capture(&error, &position)); |
455 ASSERT_TRUE(file.WaitForIncomingResponse()); | 467 ASSERT_TRUE(file.WaitForIncomingResponse()); |
456 EXPECT_EQ(FileError::OK, error); | 468 EXPECT_EQ(mojom::FileError::OK, error); |
457 EXPECT_EQ(size - 100, position); | 469 EXPECT_EQ(size - 100, position); |
458 | 470 |
459 // Seek to 123 from start. | 471 // Seek to 123 from start. |
460 error = FileError::FAILED; | 472 error = mojom::FileError::FAILED; |
461 position = -1; | 473 position = -1; |
462 file->Seek(123, Whence::FROM_BEGIN, Capture(&error, &position)); | 474 file->Seek(123, mojom::Whence::FROM_BEGIN, Capture(&error, &position)); |
463 ASSERT_TRUE(file.WaitForIncomingResponse()); | 475 ASSERT_TRUE(file.WaitForIncomingResponse()); |
464 EXPECT_EQ(FileError::OK, error); | 476 EXPECT_EQ(mojom::FileError::OK, error); |
465 EXPECT_EQ(123, position); | 477 EXPECT_EQ(123, position); |
466 | 478 |
467 // Tell. | 479 // Tell. |
468 error = FileError::FAILED; | 480 error = mojom::FileError::FAILED; |
469 position = -1; | 481 position = -1; |
470 file->Tell(Capture(&error, &position)); | 482 file->Tell(Capture(&error, &position)); |
471 ASSERT_TRUE(file.WaitForIncomingResponse()); | 483 ASSERT_TRUE(file.WaitForIncomingResponse()); |
472 EXPECT_EQ(FileError::OK, error); | 484 EXPECT_EQ(mojom::FileError::OK, error); |
473 EXPECT_EQ(123, position); | 485 EXPECT_EQ(123, position); |
474 | 486 |
475 // Seek to 123 back from end. | 487 // Seek to 123 back from end. |
476 error = FileError::FAILED; | 488 error = mojom::FileError::FAILED; |
477 position = -1; | 489 position = -1; |
478 file->Seek(-123, Whence::FROM_END, Capture(&error, &position)); | 490 file->Seek(-123, mojom::Whence::FROM_END, Capture(&error, &position)); |
479 ASSERT_TRUE(file.WaitForIncomingResponse()); | 491 ASSERT_TRUE(file.WaitForIncomingResponse()); |
480 EXPECT_EQ(FileError::OK, error); | 492 EXPECT_EQ(mojom::FileError::OK, error); |
481 EXPECT_EQ(size - 123, position); | 493 EXPECT_EQ(size - 123, position); |
482 | 494 |
483 // Tell. | 495 // Tell. |
484 error = FileError::FAILED; | 496 error = mojom::FileError::FAILED; |
485 position = -1; | 497 position = -1; |
486 file->Tell(Capture(&error, &position)); | 498 file->Tell(Capture(&error, &position)); |
487 ASSERT_TRUE(file.WaitForIncomingResponse()); | 499 ASSERT_TRUE(file.WaitForIncomingResponse()); |
488 EXPECT_EQ(FileError::OK, error); | 500 EXPECT_EQ(mojom::FileError::OK, error); |
489 EXPECT_EQ(size - 123, position); | 501 EXPECT_EQ(size - 123, position); |
490 | 502 |
491 // TODO(vtl): Check that seeking actually affects reading/writing. | 503 // TODO(vtl): Check that seeking actually affects reading/writing. |
492 // TODO(vtl): Check that seeking can extend the file? | 504 // TODO(vtl): Check that seeking can extend the file? |
493 } | 505 } |
494 | 506 |
495 TEST_F(FileImplTest, Dup) { | 507 TEST_F(FileImplTest, Dup) { |
496 DirectoryPtr directory; | 508 mojom::DirectoryPtr directory; |
497 GetTemporaryRoot(&directory); | 509 GetTemporaryRoot(&directory); |
498 FileError error; | 510 mojom::FileError error; |
499 | 511 |
500 // Create my_file. | 512 // Create my_file. |
501 FilePtr file1; | 513 mojom::FilePtr file1; |
502 error = FileError::FAILED; | 514 error = mojom::FileError::FAILED; |
503 directory->OpenFile("my_file", GetProxy(&file1), | 515 directory->OpenFile("my_file", GetProxy(&file1), |
504 kFlagRead | kFlagWrite | kFlagCreate, Capture(&error)); | 516 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, |
| 517 Capture(&error)); |
505 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 518 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
506 EXPECT_EQ(FileError::OK, error); | 519 EXPECT_EQ(mojom::FileError::OK, error); |
507 | 520 |
508 // Write to it. | 521 // Write to it. |
509 std::vector<uint8_t> bytes_to_write; | 522 std::vector<uint8_t> bytes_to_write; |
510 bytes_to_write.push_back(static_cast<uint8_t>('h')); | 523 bytes_to_write.push_back(static_cast<uint8_t>('h')); |
511 bytes_to_write.push_back(static_cast<uint8_t>('e')); | 524 bytes_to_write.push_back(static_cast<uint8_t>('e')); |
512 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 525 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
513 bytes_to_write.push_back(static_cast<uint8_t>('l')); | 526 bytes_to_write.push_back(static_cast<uint8_t>('l')); |
514 bytes_to_write.push_back(static_cast<uint8_t>('o')); | 527 bytes_to_write.push_back(static_cast<uint8_t>('o')); |
515 error = FileError::FAILED; | 528 error = mojom::FileError::FAILED; |
516 uint32_t num_bytes_written = 0; | 529 uint32_t num_bytes_written = 0; |
517 file1->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, | 530 file1->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, |
518 Whence::FROM_CURRENT, Capture(&error, &num_bytes_written)); | 531 mojom::Whence::FROM_CURRENT, |
| 532 Capture(&error, &num_bytes_written)); |
519 ASSERT_TRUE(file1.WaitForIncomingResponse()); | 533 ASSERT_TRUE(file1.WaitForIncomingResponse()); |
520 EXPECT_EQ(FileError::OK, error); | 534 EXPECT_EQ(mojom::FileError::OK, error); |
521 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); | 535 EXPECT_EQ(bytes_to_write.size(), num_bytes_written); |
522 const int end_hello_pos = static_cast<int>(num_bytes_written); | 536 const int end_hello_pos = static_cast<int>(num_bytes_written); |
523 | 537 |
524 // Dup it. | 538 // Dup it. |
525 FilePtr file2; | 539 mojom::FilePtr file2; |
526 error = FileError::FAILED; | 540 error = mojom::FileError::FAILED; |
527 file1->Dup(GetProxy(&file2), Capture(&error)); | 541 file1->Dup(GetProxy(&file2), Capture(&error)); |
528 ASSERT_TRUE(file1.WaitForIncomingResponse()); | 542 ASSERT_TRUE(file1.WaitForIncomingResponse()); |
529 EXPECT_EQ(FileError::OK, error); | 543 EXPECT_EQ(mojom::FileError::OK, error); |
530 | 544 |
531 // |file2| should have the same position. | 545 // |file2| should have the same position. |
532 error = FileError::FAILED; | 546 error = mojom::FileError::FAILED; |
533 int64_t position = -1; | 547 int64_t position = -1; |
534 file2->Tell(Capture(&error, &position)); | 548 file2->Tell(Capture(&error, &position)); |
535 ASSERT_TRUE(file2.WaitForIncomingResponse()); | 549 ASSERT_TRUE(file2.WaitForIncomingResponse()); |
536 EXPECT_EQ(FileError::OK, error); | 550 EXPECT_EQ(mojom::FileError::OK, error); |
537 EXPECT_EQ(end_hello_pos, position); | 551 EXPECT_EQ(end_hello_pos, position); |
538 | 552 |
539 // Write using |file2|. | 553 // Write using |file2|. |
540 std::vector<uint8_t> more_bytes_to_write; | 554 std::vector<uint8_t> more_bytes_to_write; |
541 more_bytes_to_write.push_back(static_cast<uint8_t>('w')); | 555 more_bytes_to_write.push_back(static_cast<uint8_t>('w')); |
542 more_bytes_to_write.push_back(static_cast<uint8_t>('o')); | 556 more_bytes_to_write.push_back(static_cast<uint8_t>('o')); |
543 more_bytes_to_write.push_back(static_cast<uint8_t>('r')); | 557 more_bytes_to_write.push_back(static_cast<uint8_t>('r')); |
544 more_bytes_to_write.push_back(static_cast<uint8_t>('l')); | 558 more_bytes_to_write.push_back(static_cast<uint8_t>('l')); |
545 more_bytes_to_write.push_back(static_cast<uint8_t>('d')); | 559 more_bytes_to_write.push_back(static_cast<uint8_t>('d')); |
546 error = FileError::FAILED; | 560 error = mojom::FileError::FAILED; |
547 num_bytes_written = 0; | 561 num_bytes_written = 0; |
548 file2->Write(mojo::Array<uint8_t>::From(more_bytes_to_write), 0, | 562 file2->Write(mojo::Array<uint8_t>::From(more_bytes_to_write), 0, |
549 Whence::FROM_CURRENT, Capture(&error, &num_bytes_written)); | 563 mojom::Whence::FROM_CURRENT, |
| 564 Capture(&error, &num_bytes_written)); |
550 ASSERT_TRUE(file2.WaitForIncomingResponse()); | 565 ASSERT_TRUE(file2.WaitForIncomingResponse()); |
551 EXPECT_EQ(FileError::OK, error); | 566 EXPECT_EQ(mojom::FileError::OK, error); |
552 EXPECT_EQ(more_bytes_to_write.size(), num_bytes_written); | 567 EXPECT_EQ(more_bytes_to_write.size(), num_bytes_written); |
553 const int end_world_pos = end_hello_pos + static_cast<int>(num_bytes_written); | 568 const int end_world_pos = end_hello_pos + static_cast<int>(num_bytes_written); |
554 | 569 |
555 // |file1| should have the same position. | 570 // |file1| should have the same position. |
556 error = FileError::FAILED; | 571 error = mojom::FileError::FAILED; |
557 position = -1; | 572 position = -1; |
558 file1->Tell(Capture(&error, &position)); | 573 file1->Tell(Capture(&error, &position)); |
559 ASSERT_TRUE(file1.WaitForIncomingResponse()); | 574 ASSERT_TRUE(file1.WaitForIncomingResponse()); |
560 EXPECT_EQ(FileError::OK, error); | 575 EXPECT_EQ(mojom::FileError::OK, error); |
561 EXPECT_EQ(end_world_pos, position); | 576 EXPECT_EQ(end_world_pos, position); |
562 | 577 |
563 // Close |file1|. | 578 // Close |file1|. |
564 error = FileError::FAILED; | 579 error = mojom::FileError::FAILED; |
565 file1->Close(Capture(&error)); | 580 file1->Close(Capture(&error)); |
566 ASSERT_TRUE(file1.WaitForIncomingResponse()); | 581 ASSERT_TRUE(file1.WaitForIncomingResponse()); |
567 EXPECT_EQ(FileError::OK, error); | 582 EXPECT_EQ(mojom::FileError::OK, error); |
568 | 583 |
569 // Read everything using |file2|. | 584 // Read everything using |file2|. |
570 mojo::Array<uint8_t> bytes_read; | 585 mojo::Array<uint8_t> bytes_read; |
571 error = FileError::FAILED; | 586 error = mojom::FileError::FAILED; |
572 file2->Read(1000, 0, Whence::FROM_BEGIN, Capture(&error, &bytes_read)); | 587 file2->Read(1000, 0, mojom::Whence::FROM_BEGIN, Capture(&error, &bytes_read)); |
573 ASSERT_TRUE(file2.WaitForIncomingResponse()); | 588 ASSERT_TRUE(file2.WaitForIncomingResponse()); |
574 EXPECT_EQ(FileError::OK, error); | 589 EXPECT_EQ(mojom::FileError::OK, error); |
575 ASSERT_EQ(static_cast<size_t>(end_world_pos), bytes_read.size()); | 590 ASSERT_EQ(static_cast<size_t>(end_world_pos), bytes_read.size()); |
576 // Just check the first and last bytes. | 591 // Just check the first and last bytes. |
577 EXPECT_EQ(static_cast<uint8_t>('h'), bytes_read[0]); | 592 EXPECT_EQ(static_cast<uint8_t>('h'), bytes_read[0]); |
578 EXPECT_EQ(static_cast<uint8_t>('d'), bytes_read[end_world_pos - 1]); | 593 EXPECT_EQ(static_cast<uint8_t>('d'), bytes_read[end_world_pos - 1]); |
579 | 594 |
580 // TODO(vtl): Test that |file2| has the same open options as |file1|. | 595 // TODO(vtl): Test that |file2| has the same open options as |file1|. |
581 } | 596 } |
582 | 597 |
583 TEST_F(FileImplTest, Truncate) { | 598 TEST_F(FileImplTest, Truncate) { |
584 const uint32_t kInitialSize = 1000; | 599 const uint32_t kInitialSize = 1000; |
585 const uint32_t kTruncatedSize = 654; | 600 const uint32_t kTruncatedSize = 654; |
586 | 601 |
587 DirectoryPtr directory; | 602 mojom::DirectoryPtr directory; |
588 GetTemporaryRoot(&directory); | 603 GetTemporaryRoot(&directory); |
589 FileError error; | 604 mojom::FileError error; |
590 | 605 |
591 // Create my_file. | 606 // Create my_file. |
592 FilePtr file; | 607 mojom::FilePtr file; |
593 error = FileError::FAILED; | 608 error = mojom::FileError::FAILED; |
594 directory->OpenFile("my_file", GetProxy(&file), kFlagWrite | kFlagCreate, | 609 directory->OpenFile("my_file", GetProxy(&file), |
595 Capture(&error)); | 610 mojom::kFlagWrite | mojom::kFlagCreate, Capture(&error)); |
596 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 611 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
597 EXPECT_EQ(FileError::OK, error); | 612 EXPECT_EQ(mojom::FileError::OK, error); |
598 | 613 |
599 // Write to it. | 614 // Write to it. |
600 std::vector<uint8_t> bytes_to_write(kInitialSize, '!'); | 615 std::vector<uint8_t> bytes_to_write(kInitialSize, '!'); |
601 error = FileError::FAILED; | 616 error = mojom::FileError::FAILED; |
602 uint32_t num_bytes_written = 0; | 617 uint32_t num_bytes_written = 0; |
603 file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, | 618 file->Write(mojo::Array<uint8_t>::From(bytes_to_write), 0, |
604 Whence::FROM_CURRENT, Capture(&error, &num_bytes_written)); | 619 mojom::Whence::FROM_CURRENT, Capture(&error, &num_bytes_written)); |
605 ASSERT_TRUE(file.WaitForIncomingResponse()); | 620 ASSERT_TRUE(file.WaitForIncomingResponse()); |
606 EXPECT_EQ(FileError::OK, error); | 621 EXPECT_EQ(mojom::FileError::OK, error); |
607 EXPECT_EQ(kInitialSize, num_bytes_written); | 622 EXPECT_EQ(kInitialSize, num_bytes_written); |
608 | 623 |
609 // Stat it. | 624 // Stat it. |
610 error = FileError::FAILED; | 625 error = mojom::FileError::FAILED; |
611 FileInformationPtr file_info; | 626 mojom::FileInformationPtr file_info; |
612 file->Stat(Capture(&error, &file_info)); | 627 file->Stat(Capture(&error, &file_info)); |
613 ASSERT_TRUE(file.WaitForIncomingResponse()); | 628 ASSERT_TRUE(file.WaitForIncomingResponse()); |
614 EXPECT_EQ(FileError::OK, error); | 629 EXPECT_EQ(mojom::FileError::OK, error); |
615 ASSERT_FALSE(file_info.is_null()); | 630 ASSERT_FALSE(file_info.is_null()); |
616 EXPECT_EQ(kInitialSize, file_info->size); | 631 EXPECT_EQ(kInitialSize, file_info->size); |
617 | 632 |
618 // Truncate it. | 633 // Truncate it. |
619 error = FileError::FAILED; | 634 error = mojom::FileError::FAILED; |
620 file->Truncate(kTruncatedSize, Capture(&error)); | 635 file->Truncate(kTruncatedSize, Capture(&error)); |
621 ASSERT_TRUE(file.WaitForIncomingResponse()); | 636 ASSERT_TRUE(file.WaitForIncomingResponse()); |
622 EXPECT_EQ(FileError::OK, error); | 637 EXPECT_EQ(mojom::FileError::OK, error); |
623 | 638 |
624 // Stat again. | 639 // Stat again. |
625 error = FileError::FAILED; | 640 error = mojom::FileError::FAILED; |
626 file_info.reset(); | 641 file_info.reset(); |
627 file->Stat(Capture(&error, &file_info)); | 642 file->Stat(Capture(&error, &file_info)); |
628 ASSERT_TRUE(file.WaitForIncomingResponse()); | 643 ASSERT_TRUE(file.WaitForIncomingResponse()); |
629 EXPECT_EQ(FileError::OK, error); | 644 EXPECT_EQ(mojom::FileError::OK, error); |
630 ASSERT_FALSE(file_info.is_null()); | 645 ASSERT_FALSE(file_info.is_null()); |
631 EXPECT_EQ(kTruncatedSize, file_info->size); | 646 EXPECT_EQ(kTruncatedSize, file_info->size); |
632 } | 647 } |
633 | 648 |
634 TEST_F(FileImplTest, AsHandle) { | 649 TEST_F(FileImplTest, AsHandle) { |
635 DirectoryPtr directory; | 650 mojom::DirectoryPtr directory; |
636 GetTemporaryRoot(&directory); | 651 GetTemporaryRoot(&directory); |
637 FileError error; | 652 mojom::FileError error; |
638 | 653 |
639 { | 654 { |
640 // Create my_file. | 655 // Create my_file. |
641 FilePtr file1; | 656 mojom::FilePtr file1; |
642 error = FileError::FAILED; | 657 error = mojom::FileError::FAILED; |
643 directory->OpenFile("my_file", GetProxy(&file1), | 658 directory->OpenFile( |
644 kFlagRead | kFlagWrite | kFlagCreate, Capture(&error)); | 659 "my_file", GetProxy(&file1), |
| 660 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, |
| 661 Capture(&error)); |
645 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 662 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
646 EXPECT_EQ(FileError::OK, error); | 663 EXPECT_EQ(mojom::FileError::OK, error); |
647 | 664 |
648 // Fetch the handle | 665 // Fetch the handle |
649 error = FileError::FAILED; | 666 error = mojom::FileError::FAILED; |
650 mojo::ScopedHandle handle; | 667 mojo::ScopedHandle handle; |
651 file1->AsHandle(Capture(&error, &handle)); | 668 file1->AsHandle(Capture(&error, &handle)); |
652 ASSERT_TRUE(file1.WaitForIncomingResponse()); | 669 ASSERT_TRUE(file1.WaitForIncomingResponse()); |
653 EXPECT_EQ(FileError::OK, error); | 670 EXPECT_EQ(mojom::FileError::OK, error); |
654 | 671 |
655 // Pull a file descriptor out of the scoped handle. | 672 // Pull a file descriptor out of the scoped handle. |
656 MojoPlatformHandle platform_handle; | 673 MojoPlatformHandle platform_handle; |
657 MojoResult extract_result = | 674 MojoResult extract_result = |
658 MojoExtractPlatformHandle(handle.release().value(), &platform_handle); | 675 MojoExtractPlatformHandle(handle.release().value(), &platform_handle); |
659 EXPECT_EQ(MOJO_RESULT_OK, extract_result); | 676 EXPECT_EQ(MOJO_RESULT_OK, extract_result); |
660 | 677 |
661 // Pass this raw file descriptor to a base::File. | 678 // Pass this raw file descriptor to a base::File. |
662 base::File raw_file(platform_handle); | 679 base::File raw_file(platform_handle); |
663 ASSERT_TRUE(raw_file.IsValid()); | 680 ASSERT_TRUE(raw_file.IsValid()); |
664 EXPECT_EQ(5, raw_file.WriteAtCurrentPos("hello", 5)); | 681 EXPECT_EQ(5, raw_file.WriteAtCurrentPos("hello", 5)); |
665 } | 682 } |
666 | 683 |
667 { | 684 { |
668 // Reopen my_file. | 685 // Reopen my_file. |
669 FilePtr file2; | 686 mojom::FilePtr file2; |
670 error = FileError::FAILED; | 687 error = mojom::FileError::FAILED; |
671 directory->OpenFile("my_file", GetProxy(&file2), kFlagRead | kFlagOpen, | 688 directory->OpenFile("my_file", GetProxy(&file2), |
672 Capture(&error)); | 689 mojom::kFlagRead | mojom::kFlagOpen, Capture(&error)); |
673 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 690 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
674 EXPECT_EQ(FileError::OK, error); | 691 EXPECT_EQ(mojom::FileError::OK, error); |
675 | 692 |
676 // Verify that we wrote data raw on the file descriptor. | 693 // Verify that we wrote data raw on the file descriptor. |
677 mojo::Array<uint8_t> bytes_read; | 694 mojo::Array<uint8_t> bytes_read; |
678 error = FileError::FAILED; | 695 error = mojom::FileError::FAILED; |
679 file2->Read(5, 0, Whence::FROM_BEGIN, Capture(&error, &bytes_read)); | 696 file2->Read(5, 0, mojom::Whence::FROM_BEGIN, Capture(&error, &bytes_read)); |
680 ASSERT_TRUE(file2.WaitForIncomingResponse()); | 697 ASSERT_TRUE(file2.WaitForIncomingResponse()); |
681 EXPECT_EQ(FileError::OK, error); | 698 EXPECT_EQ(mojom::FileError::OK, error); |
682 ASSERT_EQ(5u, bytes_read.size()); | 699 ASSERT_EQ(5u, bytes_read.size()); |
683 EXPECT_EQ(static_cast<uint8_t>('h'), bytes_read[0]); | 700 EXPECT_EQ(static_cast<uint8_t>('h'), bytes_read[0]); |
684 EXPECT_EQ(static_cast<uint8_t>('e'), bytes_read[1]); | 701 EXPECT_EQ(static_cast<uint8_t>('e'), bytes_read[1]); |
685 EXPECT_EQ(static_cast<uint8_t>('l'), bytes_read[2]); | 702 EXPECT_EQ(static_cast<uint8_t>('l'), bytes_read[2]); |
686 EXPECT_EQ(static_cast<uint8_t>('l'), bytes_read[3]); | 703 EXPECT_EQ(static_cast<uint8_t>('l'), bytes_read[3]); |
687 EXPECT_EQ(static_cast<uint8_t>('o'), bytes_read[4]); | 704 EXPECT_EQ(static_cast<uint8_t>('o'), bytes_read[4]); |
688 } | 705 } |
689 } | 706 } |
690 | 707 |
691 TEST_F(FileImplTest, SimpleLockUnlock) { | 708 TEST_F(FileImplTest, SimpleLockUnlock) { |
692 DirectoryPtr directory; | 709 mojom::DirectoryPtr directory; |
693 GetTemporaryRoot(&directory); | 710 GetTemporaryRoot(&directory); |
694 FileError error; | 711 mojom::FileError error; |
695 | 712 |
696 // Create my_file. | 713 // Create my_file. |
697 FilePtr file; | 714 mojom::FilePtr file; |
698 error = FileError::FAILED; | 715 error = mojom::FileError::FAILED; |
699 directory->OpenFile("my_file", GetProxy(&file), | 716 directory->OpenFile("my_file", GetProxy(&file), |
700 kFlagRead | kFlagWrite | kFlagCreate, Capture(&error)); | 717 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, |
| 718 Capture(&error)); |
701 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 719 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
702 EXPECT_EQ(FileError::OK, error); | 720 EXPECT_EQ(mojom::FileError::OK, error); |
703 | 721 |
704 // Lock the file. | 722 // Lock the file. |
705 error = FileError::FAILED; | 723 error = mojom::FileError::FAILED; |
706 file->Lock(Capture(&error)); | 724 file->Lock(Capture(&error)); |
707 ASSERT_TRUE(file.WaitForIncomingResponse()); | 725 ASSERT_TRUE(file.WaitForIncomingResponse()); |
708 EXPECT_EQ(FileError::OK, error); | 726 EXPECT_EQ(mojom::FileError::OK, error); |
709 | 727 |
710 // Unlock the file. | 728 // Unlock the file. |
711 error = FileError::FAILED; | 729 error = mojom::FileError::FAILED; |
712 file->Unlock(Capture(&error)); | 730 file->Unlock(Capture(&error)); |
713 ASSERT_TRUE(file.WaitForIncomingResponse()); | 731 ASSERT_TRUE(file.WaitForIncomingResponse()); |
714 EXPECT_EQ(FileError::OK, error); | 732 EXPECT_EQ(mojom::FileError::OK, error); |
715 } | 733 } |
716 | 734 |
717 TEST_F(FileImplTest, CantDoubleLock) { | 735 TEST_F(FileImplTest, CantDoubleLock) { |
718 DirectoryPtr directory; | 736 mojom::DirectoryPtr directory; |
719 GetTemporaryRoot(&directory); | 737 GetTemporaryRoot(&directory); |
720 FileError error; | 738 mojom::FileError error; |
721 | 739 |
722 // Create my_file. | 740 // Create my_file. |
723 FilePtr file; | 741 mojom::FilePtr file; |
724 error = FileError::FAILED; | 742 error = mojom::FileError::FAILED; |
725 directory->OpenFile("my_file", GetProxy(&file), | 743 directory->OpenFile("my_file", GetProxy(&file), |
726 kFlagRead | kFlagWrite | kFlagCreate, Capture(&error)); | 744 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, |
| 745 Capture(&error)); |
727 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 746 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
728 EXPECT_EQ(FileError::OK, error); | 747 EXPECT_EQ(mojom::FileError::OK, error); |
729 | 748 |
730 // Lock the file. | 749 // Lock the file. |
731 error = FileError::FAILED; | 750 error = mojom::FileError::FAILED; |
732 file->Lock(Capture(&error)); | 751 file->Lock(Capture(&error)); |
733 ASSERT_TRUE(file.WaitForIncomingResponse()); | 752 ASSERT_TRUE(file.WaitForIncomingResponse()); |
734 EXPECT_EQ(FileError::OK, error); | 753 EXPECT_EQ(mojom::FileError::OK, error); |
735 | 754 |
736 // Lock the file again. | 755 // Lock the file again. |
737 error = FileError::OK; | 756 error = mojom::FileError::OK; |
738 file->Lock(Capture(&error)); | 757 file->Lock(Capture(&error)); |
739 ASSERT_TRUE(file.WaitForIncomingResponse()); | 758 ASSERT_TRUE(file.WaitForIncomingResponse()); |
740 EXPECT_EQ(FileError::FAILED, error); | 759 EXPECT_EQ(mojom::FileError::FAILED, error); |
741 } | 760 } |
742 | 761 |
743 TEST_F(FileImplTest, ClosingFileClearsLock) { | 762 TEST_F(FileImplTest, ClosingFileClearsLock) { |
744 DirectoryPtr directory; | 763 mojom::DirectoryPtr directory; |
745 GetTemporaryRoot(&directory); | 764 GetTemporaryRoot(&directory); |
746 FileError error; | 765 mojom::FileError error; |
747 | 766 |
748 { | 767 { |
749 // Create my_file. | 768 // Create my_file. |
750 FilePtr file; | 769 mojom::FilePtr file; |
751 error = FileError::FAILED; | 770 error = mojom::FileError::FAILED; |
752 directory->OpenFile("my_file", GetProxy(&file), | 771 directory->OpenFile( |
753 kFlagRead | kFlagWrite | kFlagOpenAlways, | 772 "my_file", GetProxy(&file), |
754 Capture(&error)); | 773 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagOpenAlways, |
| 774 Capture(&error)); |
755 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 775 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
756 EXPECT_EQ(FileError::OK, error); | 776 EXPECT_EQ(mojom::FileError::OK, error); |
757 | 777 |
758 // Lock the file. | 778 // Lock the file. |
759 error = FileError::FAILED; | 779 error = mojom::FileError::FAILED; |
760 file->Lock(Capture(&error)); | 780 file->Lock(Capture(&error)); |
761 ASSERT_TRUE(file.WaitForIncomingResponse()); | 781 ASSERT_TRUE(file.WaitForIncomingResponse()); |
762 EXPECT_EQ(FileError::OK, error); | 782 EXPECT_EQ(mojom::FileError::OK, error); |
763 } | 783 } |
764 | 784 |
765 { | 785 { |
766 // Open the file again. | 786 // Open the file again. |
767 FilePtr file; | 787 mojom::FilePtr file; |
768 error = FileError::FAILED; | 788 error = mojom::FileError::FAILED; |
769 directory->OpenFile("my_file", GetProxy(&file), | 789 directory->OpenFile( |
770 kFlagRead | kFlagWrite | kFlagOpenAlways, | 790 "my_file", GetProxy(&file), |
771 Capture(&error)); | 791 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagOpenAlways, |
| 792 Capture(&error)); |
772 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 793 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
773 EXPECT_EQ(FileError::OK, error); | 794 EXPECT_EQ(mojom::FileError::OK, error); |
774 | 795 |
775 // The file shouldn't be locked (and we check by trying to lock it). | 796 // The file shouldn't be locked (and we check by trying to lock it). |
776 error = FileError::FAILED; | 797 error = mojom::FileError::FAILED; |
777 file->Lock(Capture(&error)); | 798 file->Lock(Capture(&error)); |
778 ASSERT_TRUE(file.WaitForIncomingResponse()); | 799 ASSERT_TRUE(file.WaitForIncomingResponse()); |
779 EXPECT_EQ(FileError::OK, error); | 800 EXPECT_EQ(mojom::FileError::OK, error); |
780 } | 801 } |
781 } | 802 } |
782 | 803 |
783 } // namespace | 804 } // namespace |
784 } // namespace filesystem | 805 } // namespace filesystem |
OLD | NEW |