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

Side by Side Diff: native_client_sdk/src/libraries/nacl_mounts_test/mount_http_test.cc

Issue 12194030: Rename mount (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix whitespace Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6 #include <fcntl.h>
7 #include <gmock/gmock.h>
8 #include <ppapi/c/ppb_file_io.h>
9 #include <ppapi/c/pp_errors.h>
10 #include <ppapi/c/pp_instance.h>
11 #include <sys/stat.h>
12 #include <sys/types.h>
13
14 #include "nacl_mounts/kernel_intercept.h"
15 #include "nacl_mounts/mount_http.h"
16 #include "nacl_mounts/mount_node_dir.h"
17 #include "nacl_mounts/osdirent.h"
18 #include "pepper_interface_mock.h"
19
20 using ::testing::_;
21 using ::testing::DoAll;
22 using ::testing::Return;
23 using ::testing::SetArgPointee;
24 using ::testing::StrEq;
25
26 class MountHttpTest : public ::testing::Test {
27 public:
28 MountHttpTest() {
29 ki_init(NULL);
30 }
31
32 ~MountHttpTest() {
33 ki_uninit();
34 }
35 };
36
37 class MountHttpMock : public MountHttp {
38 public:
39 MountHttpMock() : MountHttp() {};
40
41 virtual bool Init(int dev, StringMap_t& args, PepperInterface* ppapi) {
42 return MountHttp::Init(dev, args, ppapi);
43 }
44
45 bool ParseManifest(char *txt) {
46 return MountHttp::ParseManifest(txt);
47 }
48
49 MountNodeDir* FindOrCreateDir(const Path& path) {
50 return MountHttp::FindOrCreateDir(path);
51 }
52
53 NodeMap_t& GetMap() { return node_cache_; }
54
55 friend class MountHttpTest;
56 };
57
58 TEST_F(MountHttpTest, MountEmpty) {
59 MountHttpMock mnt;
60 StringMap_t args;
61
62 EXPECT_TRUE(mnt.Init(1, args, NULL));
63 }
64
65 TEST_F(MountHttpTest, ParseManifest) {
66 MountHttpMock mnt;
67 StringMap_t args;
68
69 char manifest[] = "-r-- 123 /mydir/foo\n-rw- 234 /thatdir/bar\n";
70 EXPECT_TRUE(mnt.Init(1, args, NULL));
71 EXPECT_TRUE(mnt.ParseManifest(manifest));
72
73 MountNodeDir* root = mnt.FindOrCreateDir(Path("/"));
74 EXPECT_EQ(2, root->ChildCount());
75
76 MountNodeDir* dir = mnt.FindOrCreateDir(Path("/mydir"));
77 EXPECT_EQ(1, dir->ChildCount());
78
79 MountNode* node = mnt.GetMap()["/mydir/foo"];
80 EXPECT_TRUE(node);
81 EXPECT_EQ(123, node->GetSize());
82
83 // Since these files are cached thanks to the manifest, we can open them
84 // without accessing the PPAPI URL API.
85 MountNode* foo = mnt.Open(Path("/mydir/foo"), O_RDONLY);
86 MountNode* bar = mnt.Open(Path("/thatdir/bar"), O_RDWR);
87
88 struct stat sfoo;
89 struct stat sbar;
90
91 EXPECT_FALSE(foo->GetStat(&sfoo));
92 EXPECT_FALSE(bar->GetStat(&sbar));
93
94 EXPECT_EQ(123, sfoo.st_size);
95 EXPECT_EQ(S_IFREG | S_IREAD, sfoo.st_mode);
96
97 EXPECT_EQ(234, sbar.st_size);
98 EXPECT_EQ(S_IFREG | S_IREAD | S_IWRITE, sbar.st_mode);
99 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698