OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <errno.h> | 5 #include <errno.h> |
6 #include <fcntl.h> | 6 #include <fcntl.h> |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 class Html5FsForTesting : public Html5Fs { | 41 class Html5FsForTesting : public Html5Fs { |
42 public: | 42 public: |
43 Html5FsForTesting(StringMap_t& string_map, PepperInterface* ppapi, | 43 Html5FsForTesting(StringMap_t& string_map, PepperInterface* ppapi, |
44 int expected_error = 0) { | 44 int expected_error = 0) { |
45 FsInitArgs args; | 45 FsInitArgs args; |
46 args.string_map = string_map; | 46 args.string_map = string_map; |
47 args.ppapi = ppapi; | 47 args.ppapi = ppapi; |
48 Error error = Init(args); | 48 Error error = Init(args); |
49 EXPECT_EQ(expected_error, error); | 49 EXPECT_EQ(expected_error, error); |
50 } | 50 } |
| 51 |
| 52 bool Exists(const char* filename) { |
| 53 ScopedNode node; |
| 54 if (Open(Path(filename), O_RDONLY, &node)) |
| 55 return false; |
| 56 |
| 57 struct stat buf; |
| 58 return node->GetStat(&buf) == 0; |
| 59 } |
51 }; | 60 }; |
52 | 61 |
53 class Html5FsTest : public ::testing::Test { | 62 class Html5FsTest : public ::testing::Test { |
54 public: | 63 public: |
55 Html5FsTest(); | 64 Html5FsTest(); |
56 | 65 |
57 protected: | 66 protected: |
58 FakePepperInterfaceHtml5Fs ppapi_html5_; | 67 FakePepperInterfaceHtml5Fs ppapi_html5_; |
59 PepperInterfaceMock ppapi_mock_; | 68 PepperInterfaceMock ppapi_mock_; |
60 PepperInterfaceDelegate ppapi_; | 69 PepperInterfaceDelegate ppapi_; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 ASSERT_EQ(int32_t(PP_OK), ppapi_html5_.GetFileSystemInterface()->Open( | 145 ASSERT_EQ(int32_t(PP_OK), ppapi_html5_.GetFileSystemInterface()->Open( |
137 filesystem, 0, PP_BlockUntilComplete())); | 146 filesystem, 0, PP_BlockUntilComplete())); |
138 | 147 |
139 StringMap_t map; | 148 StringMap_t map; |
140 char buffer[30]; | 149 char buffer[30]; |
141 snprintf(buffer, 30, "%d", filesystem); | 150 snprintf(buffer, 30, "%d", filesystem); |
142 map["filesystem_resource"] = buffer; | 151 map["filesystem_resource"] = buffer; |
143 ScopedRef<Html5FsForTesting> fs( | 152 ScopedRef<Html5FsForTesting> fs( |
144 new Html5FsForTesting(map, &ppapi_)); | 153 new Html5FsForTesting(map, &ppapi_)); |
145 | 154 |
146 ASSERT_EQ(0, fs->Access(Path("/foo"), R_OK | W_OK | X_OK)); | 155 ASSERT_TRUE(fs->Exists("/foo")); |
147 | 156 |
148 ppapi_html5_.GetCoreInterface()->ReleaseResource(filesystem); | 157 ppapi_html5_.GetCoreInterface()->ReleaseResource(filesystem); |
149 } | 158 } |
150 } | 159 } |
151 | 160 |
152 TEST_F(Html5FsTest, MountSubtree) { | 161 TEST_F(Html5FsTest, MountSubtree) { |
153 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/foo/bar", | 162 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/foo/bar", |
154 NULL)); | 163 NULL)); |
155 StringMap_t map; | 164 StringMap_t map; |
156 map["SOURCE"] = "/foo"; | 165 map["SOURCE"] = "/foo"; |
157 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); | 166 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); |
158 | 167 |
159 ASSERT_EQ(0, fs->Access(Path("/bar"), R_OK | W_OK | X_OK)); | 168 ASSERT_TRUE(fs->Exists("/bar")); |
160 ASSERT_EQ(ENOENT, fs->Access(Path("/foo/bar"), F_OK)); | 169 ASSERT_FALSE(fs->Exists("/foo/bar")); |
161 } | |
162 | |
163 TEST_F(Html5FsTest, Access) { | |
164 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/foo", NULL)); | |
165 | |
166 StringMap_t map; | |
167 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); | |
168 | |
169 ASSERT_EQ(0, fs->Access(Path("/foo"), R_OK | W_OK | X_OK)); | |
170 ASSERT_EQ(ENOENT, fs->Access(Path("/bar"), F_OK)); | |
171 } | 170 } |
172 | 171 |
173 TEST_F(Html5FsTest, Mkdir) { | 172 TEST_F(Html5FsTest, Mkdir) { |
174 StringMap_t map; | 173 StringMap_t map; |
175 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); | 174 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); |
176 | 175 |
177 // mkdir at the root should return EEXIST, not EACCES. | 176 // mkdir at the root should return EEXIST, not EACCES. |
178 EXPECT_EQ(EEXIST, fs->Mkdir(Path("/"), 0644)); | 177 EXPECT_EQ(EEXIST, fs->Mkdir(Path("/"), 0644)); |
179 | 178 |
180 Path path("/foo"); | 179 Path path("/foo"); |
181 ASSERT_EQ(ENOENT, fs->Access(path, F_OK)); | 180 ASSERT_FALSE(fs->Exists("/foo")); |
182 ASSERT_EQ(0, fs->Mkdir(path, 0644)); | 181 ASSERT_EQ(0, fs->Mkdir(path, 0644)); |
183 | 182 |
184 struct stat stat; | 183 struct stat stat; |
185 ScopedNode node; | 184 ScopedNode node; |
186 ASSERT_EQ(0, fs->Open(path, O_RDONLY, &node)); | 185 ASSERT_EQ(0, fs->Open(path, O_RDONLY, &node)); |
187 EXPECT_EQ(0, node->GetStat(&stat)); | 186 EXPECT_EQ(0, node->GetStat(&stat)); |
188 EXPECT_EQ(S_IFDIR, stat.st_mode & S_IFDIR); | 187 EXPECT_EQ(S_IFDIR, stat.st_mode & S_IFDIR); |
189 } | 188 } |
190 | 189 |
191 TEST_F(Html5FsTest, Remove) { | 190 TEST_F(Html5FsTest, Remove) { |
192 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/foo", NULL)); | 191 const char* kPath = "/foo"; |
| 192 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile(kPath, NULL)); |
193 | 193 |
194 StringMap_t map; | 194 StringMap_t map; |
195 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); | 195 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); |
196 | 196 |
197 Path path("/foo"); | 197 Path path(kPath); |
198 ASSERT_EQ(0, fs->Access(path, F_OK)); | 198 ASSERT_TRUE(fs->Exists(kPath)); |
199 ASSERT_EQ(0, fs->Remove(path)); | 199 ASSERT_EQ(0, fs->Remove(path)); |
200 EXPECT_EQ(ENOENT, fs->Access(path, F_OK)); | 200 EXPECT_FALSE(fs->Exists(kPath)); |
201 } | 201 } |
202 | 202 |
203 TEST_F(Html5FsTest, Unlink) { | 203 TEST_F(Html5FsTest, Unlink) { |
204 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/file", NULL)); | 204 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/file", NULL)); |
205 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddDirectory("/dir", NULL)); | 205 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddDirectory("/dir", NULL)); |
206 | 206 |
207 StringMap_t map; | 207 StringMap_t map; |
208 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); | 208 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); |
209 | 209 |
| 210 ASSERT_TRUE(fs->Exists("/dir")); |
| 211 ASSERT_TRUE(fs->Exists("/file")); |
| 212 ASSERT_EQ(0, fs->Unlink(Path("/file"))); |
210 ASSERT_EQ(EISDIR, fs->Unlink(Path("/dir"))); | 213 ASSERT_EQ(EISDIR, fs->Unlink(Path("/dir"))); |
211 EXPECT_EQ(0, fs->Unlink(Path("/file"))); | 214 EXPECT_FALSE(fs->Exists("/file")); |
212 EXPECT_EQ(ENOENT, fs->Access(Path("/file"), F_OK)); | 215 EXPECT_TRUE(fs->Exists("/dir")); |
213 EXPECT_EQ(0, fs->Access(Path("/dir"), F_OK)); | |
214 } | 216 } |
215 | 217 |
216 TEST_F(Html5FsTest, Rmdir) { | 218 TEST_F(Html5FsTest, Rmdir) { |
217 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/file", NULL)); | 219 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/file", NULL)); |
218 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddDirectory("/dir", NULL)); | 220 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddDirectory("/dir", NULL)); |
219 | 221 |
220 StringMap_t map; | 222 StringMap_t map; |
221 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); | 223 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); |
222 | 224 |
223 ASSERT_EQ(ENOTDIR, fs->Rmdir(Path("/file"))); | 225 ASSERT_EQ(ENOTDIR, fs->Rmdir(Path("/file"))); |
224 EXPECT_EQ(0, fs->Rmdir(Path("/dir"))); | 226 EXPECT_EQ(0, fs->Rmdir(Path("/dir"))); |
225 EXPECT_EQ(ENOENT, fs->Access(Path("/dir"), F_OK)); | 227 EXPECT_FALSE(fs->Exists("/dir")); |
226 EXPECT_EQ(0, fs->Access(Path("/file"), F_OK)); | 228 EXPECT_TRUE(fs->Exists("/file")); |
227 } | 229 } |
228 | 230 |
229 TEST_F(Html5FsTest, Rename) { | 231 TEST_F(Html5FsTest, Rename) { |
230 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/foo", NULL)); | 232 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/foo", NULL)); |
231 | 233 |
232 StringMap_t map; | 234 StringMap_t map; |
233 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); | 235 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); |
234 | 236 |
235 Path path("/foo"); | 237 ASSERT_TRUE(fs->Exists("/foo")); |
236 Path newpath("/bar"); | 238 ASSERT_EQ(0, fs->Rename(Path("/foo"), Path("/bar"))); |
237 ASSERT_EQ(0, fs->Access(path, F_OK)); | 239 EXPECT_FALSE(fs->Exists("/foo")); |
238 ASSERT_EQ(0, fs->Rename(path, newpath)); | 240 EXPECT_TRUE(fs->Exists("/bar")); |
239 EXPECT_EQ(ENOENT, fs->Access(path, F_OK)); | |
240 EXPECT_EQ(0, fs->Access(newpath, F_OK)); | |
241 } | 241 } |
242 | 242 |
243 TEST_F(Html5FsTest, OpenForCreate) { | 243 TEST_F(Html5FsTest, OpenForCreate) { |
244 StringMap_t map; | 244 StringMap_t map; |
245 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); | 245 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); |
246 | 246 |
| 247 EXPECT_FALSE(fs->Exists("/foo")); |
| 248 |
247 Path path("/foo"); | 249 Path path("/foo"); |
248 EXPECT_EQ(ENOENT, fs->Access(path, F_OK)); | |
249 | |
250 ScopedNode node; | 250 ScopedNode node; |
251 ASSERT_EQ(0, fs->Open(path, O_CREAT | O_RDWR, &node)); | 251 ASSERT_EQ(0, fs->Open(path, O_CREAT | O_RDWR, &node)); |
252 | 252 |
253 // Write some data. | 253 // Write some data. |
254 char contents[] = "contents"; | 254 char contents[] = "contents"; |
255 int bytes_written = 0; | 255 int bytes_written = 0; |
256 EXPECT_EQ(0, node->Write(HandleAttr(), &contents[0], strlen(contents), | 256 EXPECT_EQ(0, node->Write(HandleAttr(), &contents[0], strlen(contents), |
257 &bytes_written)); | 257 &bytes_written)); |
258 EXPECT_EQ(strlen(contents), bytes_written); | 258 EXPECT_EQ(strlen(contents), bytes_written); |
259 | 259 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 EXPECT_EQ(sizeof(dirent), dirents[i].d_reclen); | 524 EXPECT_EQ(sizeof(dirent), dirents[i].d_reclen); |
525 dirnames.insert(dirents[i].d_name); | 525 dirnames.insert(dirents[i].d_name); |
526 } | 526 } |
527 | 527 |
528 EXPECT_EQ(1, dirnames.count("file")); | 528 EXPECT_EQ(1, dirnames.count("file")); |
529 EXPECT_EQ(1, dirnames.count("file2")); | 529 EXPECT_EQ(1, dirnames.count("file2")); |
530 EXPECT_EQ(1, dirnames.count(".")); | 530 EXPECT_EQ(1, dirnames.count(".")); |
531 EXPECT_EQ(1, dirnames.count("..")); | 531 EXPECT_EQ(1, dirnames.count("..")); |
532 } | 532 } |
533 } | 533 } |
OLD | NEW |