Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(735)

Side by Side Diff: native_client_sdk/src/tests/nacl_io_test/http_fs_test.cc

Issue 547713002: [NaCl SDK] nacl_io: Always create directory node in http filesystem root. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/node.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 171
172 TEST_P(HttpFsTest, GetStat) { 172 TEST_P(HttpFsTest, GetStat) {
173 const char contents[] = "contents"; 173 const char contents[] = "contents";
174 ASSERT_TRUE(ppapi_.server_template()->AddEntity("file", contents, NULL)); 174 ASSERT_TRUE(ppapi_.server_template()->AddEntity("file", contents, NULL));
175 175
176 ScopedNode node; 176 ScopedNode node;
177 ASSERT_EQ(0, fs_.Open(Path("/file"), O_RDONLY, &node)); 177 ASSERT_EQ(0, fs_.Open(Path("/file"), O_RDONLY, &node));
178 178
179 struct stat statbuf; 179 struct stat statbuf;
180 EXPECT_EQ(0, node->GetStat(&statbuf)); 180 EXPECT_EQ(0, node->GetStat(&statbuf));
181 EXPECT_EQ(S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, 181 EXPECT_EQ(S_IFREG | S_IRUSR | S_IRGRP | S_IROTH, statbuf.st_mode);
182 statbuf.st_mode);
183 EXPECT_EQ(strlen(contents), statbuf.st_size); 182 EXPECT_EQ(strlen(contents), statbuf.st_size);
184 // These are not currently set. 183 // These are not currently set.
185 EXPECT_EQ(0, statbuf.st_atime); 184 EXPECT_EQ(0, statbuf.st_atime);
186 EXPECT_EQ(0, statbuf.st_ctime); 185 EXPECT_EQ(0, statbuf.st_ctime);
187 EXPECT_EQ(0, statbuf.st_mtime); 186 EXPECT_EQ(0, statbuf.st_mtime);
188 } 187 }
189 188
190 TEST_P(HttpFsTest, FTruncate) { 189 TEST_P(HttpFsTest, FTruncate) {
191 const char contents[] = "contents"; 190 const char contents[] = "contents";
192 ASSERT_TRUE(ppapi_.server_template()->AddEntity("file", contents, NULL)); 191 ASSERT_TRUE(ppapi_.server_template()->AddEntity("file", contents, NULL));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // TODO(binji): If the server doesn't send the content length, this operation 245 // TODO(binji): If the server doesn't send the content length, this operation
247 // will be incredibly slow; it will attempt to read all of the data from the 246 // will be incredibly slow; it will attempt to read all of the data from the
248 // server to find the file length. Can we do anything smarter? 247 // server to find the file length. Can we do anything smarter?
249 ppapi_.server_template()->set_send_content_length(true); 248 ppapi_.server_template()->set_send_content_length(true);
250 249
251 ScopedNode node; 250 ScopedNode node;
252 ASSERT_EQ(0, fs_.Open(Path("/file"), O_RDONLY, &node)); 251 ASSERT_EQ(0, fs_.Open(Path("/file"), O_RDONLY, &node));
253 252
254 struct stat statbuf; 253 struct stat statbuf;
255 EXPECT_EQ(0, node->GetStat(&statbuf)); 254 EXPECT_EQ(0, node->GetStat(&statbuf));
256 EXPECT_EQ(S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, 255 EXPECT_EQ(S_IFREG | S_IRUSR | S_IRGRP | S_IROTH, statbuf.st_mode);
257 statbuf.st_mode);
258 EXPECT_EQ(size, statbuf.st_size); 256 EXPECT_EQ(size, statbuf.st_size);
259 // These are not currently set. 257 // These are not currently set.
260 EXPECT_EQ(0, statbuf.st_atime); 258 EXPECT_EQ(0, statbuf.st_atime);
261 EXPECT_EQ(0, statbuf.st_ctime); 259 EXPECT_EQ(0, statbuf.st_ctime);
262 EXPECT_EQ(0, statbuf.st_mtime); 260 EXPECT_EQ(0, statbuf.st_mtime);
263 } 261 }
264 262
265 // Instantiate the large file tests, only when cache content is off. 263 // Instantiate the large file tests, only when cache content is off.
266 // TODO(binji): make cache content smarter, so it doesn't try to cache enormous 264 // TODO(binji): make cache content smarter, so it doesn't try to cache enormous
267 // files. See http://crbug.com/369279. 265 // files. See http://crbug.com/369279.
268 INSTANTIATE_TEST_CASE_P(Default, 266 INSTANTIATE_TEST_CASE_P(Default,
269 HttpFsLargeFileTest, 267 HttpFsLargeFileTest,
270 ::testing::Values((uint32_t)kStringMapParamCacheNone, 268 ::testing::Values((uint32_t)kStringMapParamCacheNone,
271 (uint32_t)kStringMapParamCacheStat)); 269 (uint32_t)kStringMapParamCacheStat));
272 270
271 TEST(HttpFsDirTest, Root) {
272 StringMap_t args;
273 HttpFsForTesting fs(args, NULL);
274
275 // Check root node is directory
276 ScopedNode node;
277 ASSERT_EQ(0, fs.Open(Path("/"), O_RDONLY, &node));
278 ASSERT_TRUE(node->IsaDir());
279
280 // We have to r+w access to the root node
281 ASSERT_EQ(0, fs.Access(Path("/"), R_OK));
282 ASSERT_EQ(0, fs.Access(Path("/"), X_OK));
283 ASSERT_EQ(EACCES, fs.Access(Path("/"), W_OK));
284 }
285
273 TEST(HttpFsDirTest, Mkdir) { 286 TEST(HttpFsDirTest, Mkdir) {
274 StringMap_t args; 287 StringMap_t args;
275 HttpFsForTesting fs(args, NULL); 288 HttpFsForTesting fs(args, NULL);
276 char manifest[] = "-r-- 123 /mydir/foo\n-rw- 234 /thatdir/bar\n"; 289 char manifest[] = "-r-- 123 /mydir/foo\n-rw- 234 /thatdir/bar\n";
277 ASSERT_EQ(0, fs.ParseManifest(manifest)); 290 ASSERT_EQ(0, fs.ParseManifest(manifest));
278 // mkdir of existing directories should give "File exists". 291 // mkdir of existing directories should give "File exists".
279 EXPECT_EQ(EEXIST, fs.Mkdir(Path("/"), 0)); 292 EXPECT_EQ(EEXIST, fs.Mkdir(Path("/"), 0));
280 EXPECT_EQ(EEXIST, fs.Mkdir(Path("/mydir"), 0)); 293 EXPECT_EQ(EEXIST, fs.Mkdir(Path("/mydir"), 0));
281 // mkdir of non-existent directories should give "Permission denied". 294 // mkdir of non-existent directories should give "Permission denied".
282 EXPECT_EQ(EACCES, fs.Mkdir(Path("/non_existent"), 0)); 295 EXPECT_EQ(EACCES, fs.Mkdir(Path("/non_existent"), 0));
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 EXPECT_FALSE(bar->GetStat(&sbar)); 375 EXPECT_FALSE(bar->GetStat(&sbar));
363 376
364 EXPECT_EQ(123, sfoo.st_size); 377 EXPECT_EQ(123, sfoo.st_size);
365 EXPECT_EQ(S_IFREG | S_IRALL, sfoo.st_mode); 378 EXPECT_EQ(S_IFREG | S_IRALL, sfoo.st_mode);
366 379
367 EXPECT_EQ(234, sbar.st_size); 380 EXPECT_EQ(234, sbar.st_size);
368 EXPECT_EQ(S_IFREG | S_IRALL | S_IWALL, sbar.st_mode); 381 EXPECT_EQ(S_IFREG | S_IRALL | S_IWALL, sbar.st_mode);
369 } 382 }
370 383
371 TEST(HttpFsBlobUrlTest, Basic) { 384 TEST(HttpFsBlobUrlTest, Basic) {
372 const char* kUrl = 385 const char* kUrl = "blob:http%3A//example.com/6b87a5a6-713e";
373 "blob:http%3A//example.com/6b87a5a6-713e-46a4-9f0c-78066406455d"; 386 const char* kContent = "hello";
374 FakePepperInterfaceURLLoader ppapi; 387 FakePepperInterfaceURLLoader ppapi;
375 ASSERT_TRUE(ppapi.server_template()->SetBlobEntity(kUrl, "", NULL)); 388 ASSERT_TRUE(ppapi.server_template()->SetBlobEntity(kUrl, kContent, NULL));
376 389
377 StringMap_t args; 390 StringMap_t args;
378 args["SOURCE"] = kUrl; 391 args["SOURCE"] = kUrl;
379 392
380 HttpFsForTesting fs(args, &ppapi); 393 HttpFsForTesting fs(args, &ppapi);
381 394
382 // We have to read from the mount root to read a Blob URL. 395 // Check access to root folder
383 ASSERT_EQ(0, fs.Access(Path("/"), R_OK)); 396 ASSERT_EQ(0, fs.Access(Path("/"), R_OK));
384 ASSERT_EQ(EACCES, fs.Access(Path("/"), W_OK)); 397 ASSERT_EQ(EACCES, fs.Access(Path("/"), W_OK));
385 ASSERT_EQ(EACCES, fs.Access(Path("/"), X_OK)); 398 ASSERT_EQ(EACCES, fs.Access(Path("/"), X_OK));
386 399
387 // Any other path will fail. 400 // Any other path will fail.
388 ScopedNode foo; 401 ScopedNode foo;
389 ASSERT_EQ(ENOENT, fs.Access(Path(""), R_OK)); 402 ASSERT_EQ(ENOENT, fs.Access(Path("/blah"), R_OK));
390 ASSERT_EQ(ENOENT, fs.Access(Path("."), R_OK)); 403
391 ASSERT_EQ(ENOENT, fs.Access(Path("blah"), R_OK)); 404 // Verify file size
405 ScopedNode node;
406 struct stat statbuf;
407 ASSERT_EQ(0, fs.Open(Path("/"), O_RDONLY, &node));
408 ASSERT_EQ(0, node->GetStat(&statbuf));
409 ASSERT_EQ(0, node->GetStat(&statbuf));
410 ASSERT_EQ(strlen(kContent), statbuf.st_size);
392 } 411 }
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/node.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698