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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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")); | 247 EXPECT_FALSE(fs->Exists("/foo")); |
248 | 248 |
249 Path path("/foo"); | 249 Path path("/foo"); |
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 const 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, strlen(contents), |
257 &bytes_written)); | 257 &bytes_written)); |
258 EXPECT_EQ(strlen(contents), bytes_written); | 258 EXPECT_EQ(strlen(contents), bytes_written); |
259 | 259 |
260 // Create again. | 260 // Create again. |
261 ASSERT_EQ(0, fs->Open(path, O_CREAT, &node)); | 261 ASSERT_EQ(0, fs->Open(path, O_CREAT, &node)); |
262 | 262 |
263 // Check that the file still has data. | 263 // Check that the file still has data. |
264 off_t size; | 264 off_t size; |
265 EXPECT_EQ(0, node->GetSize(&size)); | 265 EXPECT_EQ(0, node->GetSize(&size)); |
266 EXPECT_EQ(strlen(contents), size); | 266 EXPECT_EQ(strlen(contents), size); |
267 | 267 |
268 // Open exclusively. | 268 // Open exclusively. |
269 EXPECT_EQ(EEXIST, fs->Open(path, O_CREAT | O_EXCL, &node)); | 269 EXPECT_EQ(EEXIST, fs->Open(path, O_CREAT | O_EXCL, &node)); |
270 | 270 |
271 // Try to truncate without write access. | 271 // Try to truncate without write access. |
272 EXPECT_EQ(EINVAL, fs->Open(path, O_CREAT | O_TRUNC, &node)); | 272 EXPECT_EQ(EINVAL, fs->Open(path, O_CREAT | O_TRUNC, &node)); |
273 | 273 |
274 // Open and truncate. | 274 // Open and truncate. |
275 ASSERT_EQ(0, fs->Open(path, O_CREAT | O_TRUNC | O_WRONLY, &node)); | 275 ASSERT_EQ(0, fs->Open(path, O_CREAT | O_TRUNC | O_WRONLY, &node)); |
276 | 276 |
277 // File should be empty. | 277 // File should be empty. |
278 EXPECT_EQ(0, node->GetSize(&size)); | 278 EXPECT_EQ(0, node->GetSize(&size)); |
279 EXPECT_EQ(0, size); | 279 EXPECT_EQ(0, size); |
280 } | 280 } |
281 | 281 |
282 TEST_F(Html5FsTest, Read) { | 282 TEST_F(Html5FsTest, Read) { |
283 const char contents[] = "contents"; | 283 const char* contents = "contents"; |
284 ASSERT_TRUE( | 284 ASSERT_TRUE( |
285 ppapi_html5_.filesystem_template()->AddFile("/file", contents, NULL)); | 285 ppapi_html5_.filesystem_template()->AddFile("/file", contents, NULL)); |
286 ASSERT_TRUE(ppapi_html5_.filesystem_template()->AddDirectory("/dir", NULL)); | 286 ASSERT_TRUE(ppapi_html5_.filesystem_template()->AddDirectory("/dir", NULL)); |
287 StringMap_t map; | 287 StringMap_t map; |
288 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); | 288 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); |
289 | 289 |
290 ScopedNode node; | 290 ScopedNode node; |
291 ASSERT_EQ(0, fs->Open(Path("/file"), O_RDONLY, &node)); | 291 ASSERT_EQ(0, fs->Open(Path("/file"), O_RDONLY, &node)); |
292 | 292 |
293 char buffer[10] = {0}; | 293 char buffer[10] = {0}; |
(...skipping 21 matching lines...) Expand all Loading... |
315 ASSERT_EQ(EACCES, | 315 ASSERT_EQ(EACCES, |
316 node->Write(attr, &buffer[0], sizeof(buffer), &bytes_written)); | 316 node->Write(attr, &buffer[0], sizeof(buffer), &bytes_written)); |
317 ASSERT_EQ(0, bytes_written); | 317 ASSERT_EQ(0, bytes_written); |
318 | 318 |
319 // Reading from a directory should fail. | 319 // Reading from a directory should fail. |
320 ASSERT_EQ(0, fs->Open(Path("/dir"), O_RDONLY, &node)); | 320 ASSERT_EQ(0, fs->Open(Path("/dir"), O_RDONLY, &node)); |
321 ASSERT_EQ(EISDIR, node->Read(attr, &buffer[0], sizeof(buffer), &bytes_read)); | 321 ASSERT_EQ(EISDIR, node->Read(attr, &buffer[0], sizeof(buffer), &bytes_read)); |
322 } | 322 } |
323 | 323 |
324 TEST_F(Html5FsTest, Write) { | 324 TEST_F(Html5FsTest, Write) { |
325 const char contents[] = "contents"; | 325 const char* contents = "contents"; |
326 EXPECT_TRUE( | 326 EXPECT_TRUE( |
327 ppapi_html5_.filesystem_template()->AddFile("/file", contents, NULL)); | 327 ppapi_html5_.filesystem_template()->AddFile("/file", contents, NULL)); |
328 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddDirectory("/dir", NULL)); | 328 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddDirectory("/dir", NULL)); |
329 | 329 |
330 StringMap_t map; | 330 StringMap_t map; |
331 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); | 331 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); |
332 | 332 |
333 ScopedNode node; | 333 ScopedNode node; |
334 ASSERT_EQ(0, fs->Open(Path("/file"), O_WRONLY, &node)); | 334 ASSERT_EQ(0, fs->Open(Path("/file"), O_WRONLY, &node)); |
335 | 335 |
(...skipping 20 matching lines...) Expand all Loading... |
356 | 356 |
357 // Writing to a directory should fail. | 357 // Writing to a directory should fail. |
358 EXPECT_EQ(0, fs->Open(Path("/dir"), O_RDWR, &node)); | 358 EXPECT_EQ(0, fs->Open(Path("/dir"), O_RDWR, &node)); |
359 EXPECT_EQ(EISDIR, node->Write(attr, &buffer[0], sizeof(buffer), &bytes_read)); | 359 EXPECT_EQ(EISDIR, node->Write(attr, &buffer[0], sizeof(buffer), &bytes_read)); |
360 } | 360 } |
361 | 361 |
362 TEST_F(Html5FsTest, GetStat) { | 362 TEST_F(Html5FsTest, GetStat) { |
363 const int creation_time = 1000; | 363 const int creation_time = 1000; |
364 const int access_time = 2000; | 364 const int access_time = 2000; |
365 const int modified_time = 3000; | 365 const int modified_time = 3000; |
366 const char contents[] = "contents"; | 366 const char* contents = "contents"; |
367 | 367 |
368 // Create fake file. | 368 // Create fake file. |
369 FakeHtml5FsNode* fake_node; | 369 FakeHtml5FsNode* fake_node; |
370 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddFile( | 370 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddFile( |
371 "/file", contents, &fake_node)); | 371 "/file", contents, &fake_node)); |
372 fake_node->set_creation_time(creation_time); | 372 fake_node->set_creation_time(creation_time); |
373 fake_node->set_last_access_time(access_time); | 373 fake_node->set_last_access_time(access_time); |
374 fake_node->set_last_modified_time(modified_time); | 374 fake_node->set_last_modified_time(modified_time); |
375 | 375 |
376 // Create fake directory. | 376 // Create fake directory. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 | 415 |
416 // Test Get* and Isa* methods. | 416 // Test Get* and Isa* methods. |
417 EXPECT_EQ(0, node->GetSize(&size)); | 417 EXPECT_EQ(0, node->GetSize(&size)); |
418 EXPECT_EQ(0, size); | 418 EXPECT_EQ(0, size); |
419 EXPECT_TRUE(node->IsaDir()); | 419 EXPECT_TRUE(node->IsaDir()); |
420 EXPECT_FALSE(node->IsaFile()); | 420 EXPECT_FALSE(node->IsaFile()); |
421 EXPECT_EQ(ENOTTY, node->Isatty()); | 421 EXPECT_EQ(ENOTTY, node->Isatty()); |
422 } | 422 } |
423 | 423 |
424 TEST_F(Html5FsTest, FTruncate) { | 424 TEST_F(Html5FsTest, FTruncate) { |
425 const char contents[] = "contents"; | 425 const char* contents = "contents"; |
426 EXPECT_TRUE( | 426 EXPECT_TRUE( |
427 ppapi_html5_.filesystem_template()->AddFile("/file", contents, NULL)); | 427 ppapi_html5_.filesystem_template()->AddFile("/file", contents, NULL)); |
428 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddDirectory("/dir", NULL)); | 428 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddDirectory("/dir", NULL)); |
429 | 429 |
430 StringMap_t map; | 430 StringMap_t map; |
431 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); | 431 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); |
432 | 432 |
433 ScopedNode node; | 433 ScopedNode node; |
434 ASSERT_EQ(0, fs->Open(Path("/file"), O_RDWR, &node)); | 434 ASSERT_EQ(0, fs->Open(Path("/file"), O_RDWR, &node)); |
435 | 435 |
(...skipping 22 matching lines...) Expand all Loading... |
458 | 458 |
459 TEST_F(Html5FsTest, Chmod) { | 459 TEST_F(Html5FsTest, Chmod) { |
460 StringMap_t map; | 460 StringMap_t map; |
461 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); | 461 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); |
462 ScopedNode node; | 462 ScopedNode node; |
463 ASSERT_EQ(0, fs->Open(Path("/"), O_RDONLY, &node)); | 463 ASSERT_EQ(0, fs->Open(Path("/"), O_RDONLY, &node)); |
464 ASSERT_EQ(0, node->Fchmod(0777)); | 464 ASSERT_EQ(0, node->Fchmod(0777)); |
465 } | 465 } |
466 | 466 |
467 TEST_F(Html5FsTest, GetDents) { | 467 TEST_F(Html5FsTest, GetDents) { |
468 const char contents[] = "contents"; | 468 const char* contents = "contents"; |
469 EXPECT_TRUE( | 469 EXPECT_TRUE( |
470 ppapi_html5_.filesystem_template()->AddFile("/file", contents, NULL)); | 470 ppapi_html5_.filesystem_template()->AddFile("/file", contents, NULL)); |
471 | 471 |
472 StringMap_t map; | 472 StringMap_t map; |
473 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); | 473 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); |
474 | 474 |
475 ScopedNode root; | 475 ScopedNode root; |
476 ASSERT_EQ(0, fs->Open(Path("/"), O_RDONLY, &root)); | 476 ASSERT_EQ(0, fs->Open(Path("/"), O_RDONLY, &root)); |
477 | 477 |
478 ScopedNode node; | 478 ScopedNode node; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 EXPECT_EQ(dirents[i].d_ino, file2_ino); | 546 EXPECT_EQ(dirents[i].d_ino, file2_ino); |
547 } | 547 } |
548 } | 548 } |
549 | 549 |
550 EXPECT_EQ(1, dirnames.count("file")); | 550 EXPECT_EQ(1, dirnames.count("file")); |
551 EXPECT_EQ(1, dirnames.count("file2")); | 551 EXPECT_EQ(1, dirnames.count("file2")); |
552 EXPECT_EQ(1, dirnames.count(".")); | 552 EXPECT_EQ(1, dirnames.count(".")); |
553 EXPECT_EQ(1, dirnames.count("..")); | 553 EXPECT_EQ(1, dirnames.count("..")); |
554 } | 554 } |
555 } | 555 } |
OLD | NEW |