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 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // Attempt to open that directory as a file. This must fail! | 147 // Attempt to open that directory as a file. This must fail! |
148 FilePtr file; | 148 FilePtr file; |
149 error = FileError::FAILED; | 149 error = FileError::FAILED; |
150 directory->OpenFile("my_file", GetProxy(&file), kFlagRead | kFlagOpen, | 150 directory->OpenFile("my_file", GetProxy(&file), kFlagRead | kFlagOpen, |
151 Capture(&error)); | 151 Capture(&error)); |
152 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 152 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
153 EXPECT_EQ(FileError::NOT_A_FILE, error); | 153 EXPECT_EQ(FileError::NOT_A_FILE, error); |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
| 157 TEST_F(DirectoryImplTest, Clone) { |
| 158 DirectoryPtr clone_one; |
| 159 DirectoryPtr clone_two; |
| 160 FileError error; |
| 161 |
| 162 { |
| 163 DirectoryPtr directory; |
| 164 GetTemporaryRoot(&directory); |
| 165 |
| 166 directory->Clone(GetProxy(&clone_one)); |
| 167 directory->Clone(GetProxy(&clone_two)); |
| 168 |
| 169 // Original temporary directory goes out of scope here; shouldn't be |
| 170 // deleted since it has clones. |
| 171 } |
| 172 |
| 173 std::string data("one two three"); |
| 174 { |
| 175 clone_one->WriteFile("data", mojo::Array<uint8_t>::From(data), |
| 176 Capture(&error)); |
| 177 ASSERT_TRUE(clone_one.WaitForIncomingResponse()); |
| 178 EXPECT_EQ(FileError::OK, error); |
| 179 } |
| 180 |
| 181 { |
| 182 mojo::Array<uint8_t> file_contents; |
| 183 clone_two->ReadEntireFile("data", Capture(&error, &file_contents)); |
| 184 ASSERT_TRUE(clone_two.WaitForIncomingResponse()); |
| 185 EXPECT_EQ(FileError::OK, error); |
| 186 |
| 187 EXPECT_EQ(data, file_contents.To<std::string>()); |
| 188 } |
| 189 } |
| 190 |
157 TEST_F(DirectoryImplTest, WriteFileReadFile) { | 191 TEST_F(DirectoryImplTest, WriteFileReadFile) { |
158 DirectoryPtr directory; | 192 DirectoryPtr directory; |
159 GetTemporaryRoot(&directory); | 193 GetTemporaryRoot(&directory); |
160 FileError error; | 194 FileError error; |
161 | 195 |
162 std::string data("one two three"); | 196 std::string data("one two three"); |
163 { | 197 { |
164 directory->WriteFile("data", mojo::Array<uint8_t>::From(data), | 198 directory->WriteFile("data", mojo::Array<uint8_t>::From(data), |
165 Capture(&error)); | 199 Capture(&error)); |
166 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 200 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 Capture(&error)); | 273 Capture(&error)); |
240 ASSERT_TRUE(directory.WaitForIncomingResponse()); | 274 ASSERT_TRUE(directory.WaitForIncomingResponse()); |
241 EXPECT_EQ(FileError::NOT_A_FILE, error); | 275 EXPECT_EQ(FileError::NOT_A_FILE, error); |
242 } | 276 } |
243 } | 277 } |
244 | 278 |
245 // TODO(vtl): Test delete flags. | 279 // TODO(vtl): Test delete flags. |
246 | 280 |
247 } // namespace | 281 } // namespace |
248 } // namespace filesystem | 282 } // namespace filesystem |
OLD | NEW |