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 <fcntl.h> | 5 #include <fcntl.h> |
6 #include <gmock/gmock.h> | 6 #include <gmock/gmock.h> |
7 #include <ppapi/c/ppb_file_io.h> | 7 #include <ppapi/c/ppb_file_io.h> |
8 #include <ppapi/c/pp_errors.h> | 8 #include <ppapi/c/pp_errors.h> |
9 #include <ppapi/c/pp_instance.h> | 9 #include <ppapi/c/pp_instance.h> |
10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 71 |
72 HttpFsTest::HttpFsTest() : fs_(MakeStringMap(GetParam()), &ppapi_) {} | 72 HttpFsTest::HttpFsTest() : fs_(MakeStringMap(GetParam()), &ppapi_) {} |
73 | 73 |
74 class HttpFsLargeFileTest : public HttpFsTest { | 74 class HttpFsLargeFileTest : public HttpFsTest { |
75 public: | 75 public: |
76 HttpFsLargeFileTest() {} | 76 HttpFsLargeFileTest() {} |
77 }; | 77 }; |
78 | 78 |
79 } // namespace | 79 } // namespace |
80 | 80 |
81 TEST_P(HttpFsTest, Access) { | |
82 ASSERT_TRUE(ppapi_.server_template()->AddEntity("foo", "", NULL)); | |
83 | |
84 ASSERT_EQ(0, fs_.Access(Path("/foo"), R_OK)); | |
85 ASSERT_EQ(EACCES, fs_.Access(Path("/foo"), W_OK)); | |
86 ASSERT_EQ(EACCES, fs_.Access(Path("/foo"), X_OK)); | |
87 ASSERT_EQ(ENOENT, fs_.Access(Path("/bar"), F_OK)); | |
88 } | |
89 | |
90 TEST_P(HttpFsTest, OpenAndCloseServerError) { | 81 TEST_P(HttpFsTest, OpenAndCloseServerError) { |
91 EXPECT_TRUE(ppapi_.server_template()->AddError("file", 500)); | 82 EXPECT_TRUE(ppapi_.server_template()->AddError("file", 500)); |
92 | 83 |
93 ScopedNode node; | 84 ScopedNode node; |
94 ASSERT_EQ(EIO, fs_.Open(Path("/file"), O_RDONLY, &node)); | 85 ASSERT_EQ(EIO, fs_.Open(Path("/file"), O_RDONLY, &node)); |
95 } | 86 } |
96 | 87 |
97 TEST_P(HttpFsTest, ReadPartial) { | 88 TEST_P(HttpFsTest, ReadPartial) { |
98 const char contents[] = "0123456789abcdefg"; | 89 const char contents[] = "0123456789abcdefg"; |
99 ASSERT_TRUE(ppapi_.server_template()->AddEntity("file", contents, NULL)); | 90 ASSERT_TRUE(ppapi_.server_template()->AddEntity("file", contents, NULL)); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 TEST(HttpFsDirTest, Root) { | 262 TEST(HttpFsDirTest, Root) { |
272 StringMap_t args; | 263 StringMap_t args; |
273 HttpFsForTesting fs(args, NULL); | 264 HttpFsForTesting fs(args, NULL); |
274 | 265 |
275 // Check root node is directory | 266 // Check root node is directory |
276 ScopedNode node; | 267 ScopedNode node; |
277 ASSERT_EQ(0, fs.Open(Path("/"), O_RDONLY, &node)); | 268 ASSERT_EQ(0, fs.Open(Path("/"), O_RDONLY, &node)); |
278 ASSERT_TRUE(node->IsaDir()); | 269 ASSERT_TRUE(node->IsaDir()); |
279 | 270 |
280 // We have to r+w access to the root node | 271 // We have to r+w access to the root node |
281 ASSERT_EQ(0, fs.Access(Path("/"), R_OK)); | 272 struct stat buf; |
282 ASSERT_EQ(0, fs.Access(Path("/"), X_OK)); | 273 ASSERT_EQ(0, node->GetStat(&buf)); |
283 ASSERT_EQ(EACCES, fs.Access(Path("/"), W_OK)); | 274 ASSERT_EQ(S_IXUSR | S_IRUSR, buf.st_mode & S_IRWXU); |
284 } | 275 } |
285 | 276 |
286 TEST(HttpFsDirTest, Mkdir) { | 277 TEST(HttpFsDirTest, Mkdir) { |
287 StringMap_t args; | 278 StringMap_t args; |
288 HttpFsForTesting fs(args, NULL); | 279 HttpFsForTesting fs(args, NULL); |
289 char manifest[] = "-r-- 123 /mydir/foo\n-rw- 234 /thatdir/bar\n"; | 280 char manifest[] = "-r-- 123 /mydir/foo\n-rw- 234 /thatdir/bar\n"; |
290 ASSERT_EQ(0, fs.ParseManifest(manifest)); | 281 ASSERT_EQ(0, fs.ParseManifest(manifest)); |
291 // mkdir of existing directories should give "File exists". | 282 // mkdir of existing directories should give "File exists". |
292 EXPECT_EQ(EEXIST, fs.Mkdir(Path("/"), 0)); | 283 EXPECT_EQ(EEXIST, fs.Mkdir(Path("/"), 0)); |
293 EXPECT_EQ(EEXIST, fs.Mkdir(Path("/mydir"), 0)); | 284 EXPECT_EQ(EEXIST, fs.Mkdir(Path("/mydir"), 0)); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 const char* kUrl = "blob:http%3A//example.com/6b87a5a6-713e"; | 376 const char* kUrl = "blob:http%3A//example.com/6b87a5a6-713e"; |
386 const char* kContent = "hello"; | 377 const char* kContent = "hello"; |
387 FakePepperInterfaceURLLoader ppapi; | 378 FakePepperInterfaceURLLoader ppapi; |
388 ASSERT_TRUE(ppapi.server_template()->SetBlobEntity(kUrl, kContent, NULL)); | 379 ASSERT_TRUE(ppapi.server_template()->SetBlobEntity(kUrl, kContent, NULL)); |
389 | 380 |
390 StringMap_t args; | 381 StringMap_t args; |
391 args["SOURCE"] = kUrl; | 382 args["SOURCE"] = kUrl; |
392 | 383 |
393 HttpFsForTesting fs(args, &ppapi); | 384 HttpFsForTesting fs(args, &ppapi); |
394 | 385 |
395 // Check access to root folder | |
396 ASSERT_EQ(0, fs.Access(Path("/"), R_OK)); | |
397 ASSERT_EQ(0, fs.Access(Path("/"), X_OK)); | |
398 ASSERT_EQ(EACCES, fs.Access(Path("/"), W_OK)); | |
399 | |
400 // Verify the root is a directory containing a single file | 386 // Verify the root is a directory containing a single file |
401 ScopedNode node; | 387 ScopedNode node; |
402 ASSERT_EQ(0, fs.Open(Path("/"), O_RDONLY, &node)); | 388 ASSERT_EQ(0, fs.Open(Path("/"), O_RDONLY, &node)); |
403 ASSERT_EQ(true, node->IsaDir()); | 389 ASSERT_EQ(true, node->IsaDir()); |
404 struct dirent contents[10]; | 390 struct dirent contents[10]; |
405 int byte_count = 0; | 391 int byte_count = 0; |
406 ASSERT_EQ(0, node->GetDents(0, contents, sizeof(contents), &byte_count)); | 392 ASSERT_EQ(0, node->GetDents(0, contents, sizeof(contents), &byte_count)); |
407 ASSERT_EQ(byte_count, 3 * sizeof(struct dirent)); | 393 ASSERT_EQ(byte_count, 3 * sizeof(struct dirent)); |
408 ASSERT_STREQ(".", contents[0].d_name); | 394 ASSERT_STREQ(".", contents[0].d_name); |
409 ASSERT_STREQ("..", contents[1].d_name); | 395 ASSERT_STREQ("..", contents[1].d_name); |
410 ASSERT_STREQ("blob", contents[2].d_name); | 396 ASSERT_STREQ("blob", contents[2].d_name); |
411 | 397 |
412 // Verify file size | 398 // Verify file size |
413 struct stat statbuf; | 399 struct stat statbuf; |
414 ASSERT_EQ(0, fs.Open(Path("/blob"), O_RDONLY, &node)); | 400 ASSERT_EQ(0, fs.Open(Path("/blob"), O_RDONLY, &node)); |
415 ASSERT_EQ(0, node->GetStat(&statbuf)); | 401 ASSERT_EQ(0, node->GetStat(&statbuf)); |
416 ASSERT_EQ(0, node->GetStat(&statbuf)); | 402 ASSERT_EQ(0, node->GetStat(&statbuf)); |
417 ASSERT_EQ(strlen(kContent), statbuf.st_size); | 403 ASSERT_EQ(strlen(kContent), statbuf.st_size); |
418 | |
419 } | 404 } |
OLD | NEW |