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 | 386 // Any other path than / should fail. |
396 ASSERT_EQ(0, fs.Access(Path("/"), R_OK)); | 387 ScopedNode node; |
397 ASSERT_EQ(EACCES, fs.Access(Path("/"), W_OK)); | 388 ASSERT_EQ(ENOENT, fs.Open(Path("/blah"), R_OK, &node)); |
398 ASSERT_EQ(EACCES, fs.Access(Path("/"), X_OK)); | |
399 | 389 |
400 // Any other path will fail. | 390 // Check access to blob file |
401 ScopedNode foo; | 391 ASSERT_EQ(0, fs.Open(Path("/"), O_RDONLY, &node)); |
402 ASSERT_EQ(ENOENT, fs.Access(Path("/blah"), R_OK)); | 392 ASSERT_EQ(true, node->IsaFile()); |
403 | 393 |
404 // Verify file size | 394 // Verify file size and permissions |
405 ScopedNode node; | 395 struct stat buf; |
406 struct stat statbuf; | 396 ASSERT_EQ(0, node->GetStat(&buf)); |
407 ASSERT_EQ(0, fs.Open(Path("/"), O_RDONLY, &node)); | 397 ASSERT_EQ(S_IRUSR, buf.st_mode & S_IRWXU); |
408 ASSERT_EQ(0, node->GetStat(&statbuf)); | 398 ASSERT_EQ(strlen(kContent), buf.st_size); |
409 ASSERT_EQ(0, node->GetStat(&statbuf)); | |
410 ASSERT_EQ(strlen(kContent), statbuf.st_size); | |
411 } | 399 } |
OLD | NEW |