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

Side by Side Diff: native_client_sdk/src/libraries/nacl_io_test/mount_html5fs_test.cc

Issue 13951014: [NaCl SDK] nacl_io: opening a node immediately after mounting would fail. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix windows Created 7 years, 8 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
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 5
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <string.h> 7 #include <string.h>
8 #include <gmock/gmock.h> 8 #include <gmock/gmock.h>
9 #include <ppapi/c/ppb_file_io.h> 9 #include <ppapi/c/ppb_file_io.h>
10 #include <ppapi/c/pp_errors.h> 10 #include <ppapi/c/pp_errors.h>
11 #include <ppapi/c/pp_instance.h> 11 #include <ppapi/c/pp_instance.h>
12 #if defined(WIN32)
13 #include <windows.h> // For Sleep()
14 #endif
12 15
13 #include "mock_util.h" 16 #include "mock_util.h"
14 #include "nacl_io/mount_html5fs.h" 17 #include "nacl_io/mount_html5fs.h"
15 #include "nacl_io/osdirent.h" 18 #include "nacl_io/osdirent.h"
16 #include "pepper_interface_mock.h" 19 #include "pepper_interface_mock.h"
17 20
18 using ::testing::_; 21 using ::testing::_;
19 using ::testing::DoAll; 22 using ::testing::DoAll;
20 using ::testing::Invoke; 23 using ::testing::Invoke;
21 using ::testing::Return; 24 using ::testing::Return;
25 using ::testing::SaveArg;
22 using ::testing::SetArgPointee; 26 using ::testing::SetArgPointee;
23 using ::testing::StrEq; 27 using ::testing::StrEq;
24 using ::testing::WithArgs; 28 using ::testing::WithArgs;
25 29
26 namespace { 30 namespace {
27 31
28 class MountHtml5FsMock : public MountHtml5Fs { 32 class MountHtml5FsMock : public MountHtml5Fs {
29 public: 33 public:
30 MountHtml5FsMock(StringMap_t map, PepperInterfaceMock* ppapi) { 34 MountHtml5FsMock(StringMap_t map, PepperInterfaceMock* ppapi) {
31 Init(1, map, ppapi); 35 Init(1, map, ppapi);
32 } 36 }
33 37
34 ~MountHtml5FsMock() { 38 ~MountHtml5FsMock() {
35 Destroy(); 39 Destroy();
36 } 40 }
37 }; 41 };
38 42
39 class MountHtml5FsTest : public ::testing::Test { 43 class MountHtml5FsTest : public ::testing::Test {
40 public: 44 public:
41 MountHtml5FsTest(); 45 MountHtml5FsTest();
42 ~MountHtml5FsTest(); 46 ~MountHtml5FsTest();
43 void SetUpFilesystem(PP_FileSystemType, int); 47 void SetUpFilesystemExpectations(PP_FileSystemType, int,
48 bool async_callback=false);
44 49
45 protected: 50 protected:
46 PepperInterfaceMock* ppapi_; 51 PepperInterfaceMock* ppapi_;
52 PP_CompletionCallback open_filesystem_callback_;
47 53
48 static const PP_Instance instance_ = 123; 54 static const PP_Instance instance_ = 123;
49 static const PP_Resource filesystem_resource_ = 234; 55 static const PP_Resource filesystem_resource_ = 234;
50 }; 56 };
51 57
52 MountHtml5FsTest::MountHtml5FsTest() 58 MountHtml5FsTest::MountHtml5FsTest()
53 : ppapi_(NULL) { 59 : ppapi_(new PepperInterfaceMock(instance_)) {
54 } 60 }
55 61
56 MountHtml5FsTest::~MountHtml5FsTest() { 62 MountHtml5FsTest::~MountHtml5FsTest() {
57 delete ppapi_; 63 delete ppapi_;
58 } 64 }
59 65
60 void MountHtml5FsTest::SetUpFilesystem(PP_FileSystemType fstype, 66 void MountHtml5FsTest::SetUpFilesystemExpectations(
61 int expected_size) { 67 PP_FileSystemType fstype,
62 ppapi_ = new PepperInterfaceMock(instance_); 68 int expected_size,
69 bool async_callback) {
63 FileSystemInterfaceMock* filesystem = ppapi_->GetFileSystemInterface(); 70 FileSystemInterfaceMock* filesystem = ppapi_->GetFileSystemInterface();
64 EXPECT_CALL(*filesystem, Create(instance_, fstype)) 71 EXPECT_CALL(*filesystem, Create(instance_, fstype))
65 .Times(1) 72 .Times(1)
66 .WillOnce(Return(filesystem_resource_)); 73 .WillOnce(Return(filesystem_resource_));
67 EXPECT_CALL(*filesystem, Open(filesystem_resource_, expected_size, _)) 74
68 .WillOnce(CallCallback<2>(int32_t(PP_OK))); 75 if (async_callback) {
76 EXPECT_CALL(*filesystem, Open(filesystem_resource_, expected_size, _))
77 .WillOnce(DoAll(SaveArg<2>(&open_filesystem_callback_),
78 Return(int32_t(PP_OK))));
79 EXPECT_CALL(*ppapi_, IsMainThread()).WillOnce(Return(PP_TRUE));
80 } else {
81 EXPECT_CALL(*filesystem, Open(filesystem_resource_, expected_size, _))
82 .WillOnce(CallCallback<2>(int32_t(PP_OK)));
83 EXPECT_CALL(*ppapi_, IsMainThread()).WillOnce(Return(PP_FALSE));
84 }
69 85
70 EXPECT_CALL(*ppapi_, ReleaseResource(filesystem_resource_)); 86 EXPECT_CALL(*ppapi_, ReleaseResource(filesystem_resource_));
71 } 87 }
72 88
73 class MountHtml5FsNodeTest : public MountHtml5FsTest { 89 class MountHtml5FsNodeTest : public MountHtml5FsTest {
74 public: 90 public:
75 MountHtml5FsNodeTest(); 91 MountHtml5FsNodeTest();
76 virtual void SetUp(); 92 virtual void SetUp();
77 virtual void TearDown(); 93 virtual void TearDown();
78 94
95 void SetUpNodeExpectations();
96 void InitFilesystem();
97 void InitNode();
98
79 protected: 99 protected:
80 MountHtml5FsMock* mnt_; 100 MountHtml5FsMock* mnt_;
81 MountNode* node_; 101 MountNode* node_;
82 102
83 FileRefInterfaceMock* fileref_; 103 FileRefInterfaceMock* fileref_;
84 FileIoInterfaceMock* fileio_; 104 FileIoInterfaceMock* fileio_;
85 105
86 static const char path_[]; 106 static const char path_[];
87 static const PP_Resource fileref_resource_ = 235; 107 static const PP_Resource fileref_resource_ = 235;
88 static const PP_Resource fileio_resource_ = 236; 108 static const PP_Resource fileio_resource_ = 236;
89 }; 109 };
90 110
91 // static 111 // static
92 const char MountHtml5FsNodeTest::path_[] = "/foo"; 112 const char MountHtml5FsNodeTest::path_[] = "/foo";
93 113
94 MountHtml5FsNodeTest::MountHtml5FsNodeTest() 114 MountHtml5FsNodeTest::MountHtml5FsNodeTest()
95 : mnt_(NULL), 115 : mnt_(NULL),
96 node_(NULL), 116 node_(NULL),
97 fileref_(NULL), 117 fileref_(NULL),
98 fileio_(NULL) { 118 fileio_(NULL) {
99 } 119 }
100 120
101 void MountHtml5FsNodeTest::SetUp() { 121 void MountHtml5FsNodeTest::SetUp() {
102 SetUpFilesystem(PP_FILESYSTEMTYPE_LOCALPERSISTENT, 0);
103 StringMap_t map;
104 mnt_ = new MountHtml5FsMock(map, ppapi_);
105
106 fileref_ = ppapi_->GetFileRefInterface(); 122 fileref_ = ppapi_->GetFileRefInterface();
107 fileio_ = ppapi_->GetFileIoInterface(); 123 fileio_ = ppapi_->GetFileIoInterface();
124 }
108 125
126 void MountHtml5FsNodeTest::TearDown() {
127 if (mnt_) {
128 mnt_->ReleaseNode(node_);
129 delete mnt_;
130 }
131 }
132
133 void MountHtml5FsNodeTest::SetUpNodeExpectations() {
109 // Open. 134 // Open.
110 EXPECT_CALL(*fileref_, Create(filesystem_resource_, StrEq(&path_[0]))) 135 EXPECT_CALL(*fileref_, Create(filesystem_resource_, StrEq(&path_[0])))
111 .WillOnce(Return(fileref_resource_)); 136 .WillOnce(Return(fileref_resource_));
112 EXPECT_CALL(*fileio_, Create(instance_)).WillOnce(Return(fileio_resource_)); 137 EXPECT_CALL(*fileio_, Create(instance_)).WillOnce(Return(fileio_resource_));
113 int32_t open_flags = PP_FILEOPENFLAG_READ | PP_FILEOPENFLAG_WRITE | 138 int32_t open_flags = PP_FILEOPENFLAG_READ | PP_FILEOPENFLAG_WRITE |
114 PP_FILEOPENFLAG_CREATE; 139 PP_FILEOPENFLAG_CREATE;
115 EXPECT_CALL(*fileio_, 140 EXPECT_CALL(*fileio_,
116 Open(fileio_resource_, fileref_resource_, open_flags, _)) 141 Open(fileio_resource_, fileref_resource_, open_flags, _))
117 .WillOnce(Return(int32_t(PP_OK))); 142 .WillOnce(Return(int32_t(PP_OK)));
118 143
119 // Close. 144 // Close.
120 EXPECT_CALL(*fileio_, Close(fileio_resource_)); 145 EXPECT_CALL(*fileio_, Close(fileio_resource_));
121 EXPECT_CALL(*ppapi_, ReleaseResource(fileref_resource_)); 146 EXPECT_CALL(*ppapi_, ReleaseResource(fileref_resource_));
122 EXPECT_CALL(*ppapi_, ReleaseResource(fileio_resource_)); 147 EXPECT_CALL(*ppapi_, ReleaseResource(fileio_resource_));
123 EXPECT_CALL(*fileio_, Flush(fileio_resource_, _)); 148 EXPECT_CALL(*fileio_, Flush(fileio_resource_, _));
149 }
124 150
151 void MountHtml5FsNodeTest::InitFilesystem() {
152 StringMap_t map;
153 mnt_ = new MountHtml5FsMock(map, ppapi_);
154 }
155
156 void MountHtml5FsNodeTest::InitNode() {
125 node_ = mnt_->Open(Path(path_), O_CREAT | O_RDWR); 157 node_ = mnt_->Open(Path(path_), O_CREAT | O_RDWR);
126 ASSERT_NE((MountNode*)NULL, node_); 158 ASSERT_NE((MountNode*)NULL, node_);
127 } 159 }
128 160
129 void MountHtml5FsNodeTest::TearDown() { 161 // Node test where the filesystem is opened synchronously; that is, the
130 mnt_->ReleaseNode(node_); 162 // creation of the mount blocks until the filesystem is ready.
131 delete mnt_; 163 class MountHtml5FsNodeSyncTest : public MountHtml5FsNodeTest {
164 public:
165 virtual void SetUp();
166 };
167
168 void MountHtml5FsNodeSyncTest::SetUp() {
169 MountHtml5FsNodeTest::SetUp();
170 SetUpFilesystemExpectations(PP_FILESYSTEMTYPE_LOCALPERSISTENT, 0);
171 InitFilesystem();
172 SetUpNodeExpectations();
173 InitNode();
132 } 174 }
133 175
134 void ReadEntriesAction(const PP_ArrayOutput& output) { 176 void ReadEntriesAction(const PP_ArrayOutput& output) {
135 const int fileref_resource_1 = 238; 177 const int fileref_resource_1 = 238;
136 const int fileref_resource_2 = 239; 178 const int fileref_resource_2 = 239;
137 179
138 std::vector<PP_DirectoryEntry_Dev> entries; 180 std::vector<PP_DirectoryEntry_Dev> entries;
139 PP_DirectoryEntry_Dev entry1 = { fileref_resource_1, PP_FILETYPE_REGULAR }; 181 PP_DirectoryEntry_Dev entry1 = { fileref_resource_1, PP_FILETYPE_REGULAR };
140 PP_DirectoryEntry_Dev entry2 = { fileref_resource_2, PP_FILETYPE_REGULAR }; 182 PP_DirectoryEntry_Dev entry2 = { fileref_resource_2, PP_FILETYPE_REGULAR };
141 entries.push_back(entry1); 183 entries.push_back(entry1);
142 entries.push_back(entry2); 184 entries.push_back(entry2);
143 185
144 void* dest = output.GetDataBuffer( 186 void* dest = output.GetDataBuffer(
145 output.user_data, 2, sizeof(PP_DirectoryEntry_Dev)); 187 output.user_data, 2, sizeof(PP_DirectoryEntry_Dev));
146 memcpy(dest, &entries[0], sizeof(PP_DirectoryEntry_Dev) * 2); 188 memcpy(dest, &entries[0], sizeof(PP_DirectoryEntry_Dev) * 2);
147 } 189 }
148 190
191 class MountHtml5FsNodeAsyncTest : public MountHtml5FsNodeTest {
192 public:
193 virtual void SetUp();
194 virtual void TearDown();
195
196 private:
197 static void* ThreadThunk(void* param);
198 void Thread();
199
200 enum {
201 STATE_INIT,
202 STATE_INIT_NODE,
203 STATE_INIT_NODE_FINISHED,
204 } state_;
205
206 pthread_t thread_;
207 pthread_cond_t cond_;
208 pthread_mutex_t mutex_;
209 };
210
211 void MountHtml5FsNodeAsyncTest::SetUp() {
212 MountHtml5FsNodeTest::SetUp();
213
214 state_ = STATE_INIT;
215
216 pthread_create(&thread_, NULL, &MountHtml5FsNodeAsyncTest::ThreadThunk, this);
217 pthread_mutex_init(&mutex_, NULL);
218 pthread_cond_init(&cond_, NULL);
219
220 // This test shows that even if the filesystem open callback happens after an
221 // attempt to open a node, it still works (opening the node blocks until the
222 // filesystem is ready).
223 // true => asynchronous filesystem open.
224 SetUpFilesystemExpectations(PP_FILESYSTEMTYPE_LOCALPERSISTENT, 0, true);
225 InitFilesystem();
226 SetUpNodeExpectations();
227
228 // Signal the other thread to try opening a Node.
229 pthread_mutex_lock(&mutex_);
230 state_ = STATE_INIT_NODE;
231 pthread_cond_signal(&cond_);
232 pthread_mutex_unlock(&mutex_);
233
234 // Wait for a bit...
235 // TODO(binji): this will be flaky. How to test this better?
236 #if defined(WIN32)
237 Sleep(500); // milliseconds
238 #else
239 usleep(500*1000); // microseconds
240 #endif
241
242 // Call the filesystem open callback.
243 (*open_filesystem_callback_.func)(open_filesystem_callback_.user_data, PP_OK);
244
245 // Wait for the other thread to unblock and signal us.
246 pthread_mutex_lock(&mutex_);
247 while (state_ != STATE_INIT_NODE_FINISHED)
248 pthread_cond_wait(&cond_, &mutex_);
249 pthread_mutex_unlock(&mutex_);
250 }
251
252 void MountHtml5FsNodeAsyncTest::TearDown() {
253 pthread_cond_destroy(&cond_);
254 pthread_mutex_destroy(&mutex_);
255
256 MountHtml5FsNodeTest::TearDown();
257 }
258
259 void* MountHtml5FsNodeAsyncTest::ThreadThunk(void* param) {
260 static_cast<MountHtml5FsNodeAsyncTest*>(param)->Thread();
261 return NULL;
262 }
263
264 void MountHtml5FsNodeAsyncTest::Thread() {
265 // Wait for the "main" thread to tell us to open the Node.
266 pthread_mutex_lock(&mutex_);
267 while (state_ != STATE_INIT_NODE)
268 pthread_cond_wait(&cond_, &mutex_);
269 pthread_mutex_unlock(&mutex_);
270
271 // Opening the node blocks until the filesystem is open...
272 InitNode();
273
274 // Signal the "main" thread to tell it we're unblocked.
275 pthread_mutex_lock(&mutex_);
276 state_ = STATE_INIT_NODE_FINISHED;
277 pthread_cond_signal(&cond_);
278 pthread_mutex_unlock(&mutex_);
279 }
280
149 } // namespace 281 } // namespace
150 282
151 283
152 TEST_F(MountHtml5FsTest, FilesystemType) { 284 TEST_F(MountHtml5FsTest, FilesystemType) {
153 SetUpFilesystem(PP_FILESYSTEMTYPE_LOCALPERSISTENT, 100); 285 SetUpFilesystemExpectations(PP_FILESYSTEMTYPE_LOCALPERSISTENT, 100);
154 286
155 StringMap_t map; 287 StringMap_t map;
156 map["type"] = "PERSISTENT"; 288 map["type"] = "PERSISTENT";
157 map["expected_size"] = "100"; 289 map["expected_size"] = "100";
158 MountHtml5FsMock mnt(map, ppapi_); 290 MountHtml5FsMock mnt(map, ppapi_);
159 } 291 }
160 292
161 TEST_F(MountHtml5FsTest, Mkdir) { 293 TEST_F(MountHtml5FsTest, Mkdir) {
162 const char path[] = "/foo"; 294 const char path[] = "/foo";
163 const PP_Resource fileref_resource = 235; 295 const PP_Resource fileref_resource = 235;
164 296
165 // These are the default values. 297 // These are the default values.
166 SetUpFilesystem(PP_FILESYSTEMTYPE_LOCALPERSISTENT, 0); 298 SetUpFilesystemExpectations(PP_FILESYSTEMTYPE_LOCALPERSISTENT, 0);
167 299
168 FileRefInterfaceMock* fileref = ppapi_->GetFileRefInterface(); 300 FileRefInterfaceMock* fileref = ppapi_->GetFileRefInterface();
169 301
170 EXPECT_CALL(*fileref, Create(filesystem_resource_, StrEq(&path[0]))) 302 EXPECT_CALL(*fileref, Create(filesystem_resource_, StrEq(&path[0])))
171 .WillOnce(Return(fileref_resource)); 303 .WillOnce(Return(fileref_resource));
172 EXPECT_CALL(*fileref, MakeDirectory(fileref_resource, _, _)) 304 EXPECT_CALL(*fileref, MakeDirectory(fileref_resource, _, _))
173 .WillOnce(Return(int32_t(PP_OK))); 305 .WillOnce(Return(int32_t(PP_OK)));
174 EXPECT_CALL(*ppapi_, ReleaseResource(fileref_resource)); 306 EXPECT_CALL(*ppapi_, ReleaseResource(fileref_resource));
175 307
176 StringMap_t map; 308 StringMap_t map;
177 MountHtml5FsMock mnt(map, ppapi_); 309 MountHtml5FsMock mnt(map, ppapi_);
178 310
179 const int permissions = 0; // unused. 311 const int permissions = 0; // unused.
180 int32_t result = mnt.Mkdir(Path(path), permissions); 312 int32_t result = mnt.Mkdir(Path(path), permissions);
181 ASSERT_EQ(0, result); 313 ASSERT_EQ(0, result);
182 } 314 }
183 315
184 TEST_F(MountHtml5FsTest, Remove) { 316 TEST_F(MountHtml5FsTest, Remove) {
185 const char path[] = "/foo"; 317 const char path[] = "/foo";
186 const PP_Resource fileref_resource = 235; 318 const PP_Resource fileref_resource = 235;
187 319
188 // These are the default values. 320 // These are the default values.
189 SetUpFilesystem(PP_FILESYSTEMTYPE_LOCALPERSISTENT, 0); 321 SetUpFilesystemExpectations(PP_FILESYSTEMTYPE_LOCALPERSISTENT, 0);
190 322
191 FileRefInterfaceMock* fileref = ppapi_->GetFileRefInterface(); 323 FileRefInterfaceMock* fileref = ppapi_->GetFileRefInterface();
192 324
193 EXPECT_CALL(*fileref, Create(filesystem_resource_, StrEq(&path[0]))) 325 EXPECT_CALL(*fileref, Create(filesystem_resource_, StrEq(&path[0])))
194 .WillOnce(Return(fileref_resource)); 326 .WillOnce(Return(fileref_resource));
195 EXPECT_CALL(*fileref, Delete(fileref_resource, _)) 327 EXPECT_CALL(*fileref, Delete(fileref_resource, _))
196 .WillOnce(Return(int32_t(PP_OK))); 328 .WillOnce(Return(int32_t(PP_OK)));
197 EXPECT_CALL(*ppapi_, ReleaseResource(fileref_resource)); 329 EXPECT_CALL(*ppapi_, ReleaseResource(fileref_resource));
198 330
199 StringMap_t map; 331 StringMap_t map;
200 MountHtml5FsMock mnt(map, ppapi_); 332 MountHtml5FsMock mnt(map, ppapi_);
201 333
202 int32_t result = mnt.Remove(Path(path)); 334 int32_t result = mnt.Remove(Path(path));
203 ASSERT_EQ(0, result); 335 ASSERT_EQ(0, result);
204 } 336 }
205 337
206 TEST_F(MountHtml5FsNodeTest, OpenAndClose) { 338 TEST_F(MountHtml5FsNodeAsyncTest, AsyncFilesystemOpen) {
207 } 339 }
208 340
209 TEST_F(MountHtml5FsNodeTest, Write) { 341 TEST_F(MountHtml5FsNodeSyncTest, OpenAndClose) {
342 }
343
344 TEST_F(MountHtml5FsNodeSyncTest, Write) {
210 const int offset = 10; 345 const int offset = 10;
211 const int count = 20; 346 const int count = 20;
212 const char buffer[30] = {0}; 347 const char buffer[30] = {0};
213 348
214 EXPECT_CALL(*fileio_, Write(fileio_resource_, offset, &buffer[0], count, _)) 349 EXPECT_CALL(*fileio_, Write(fileio_resource_, offset, &buffer[0], count, _))
215 .WillOnce(Return(count)); 350 .WillOnce(Return(count));
216 351
217 int result = node_->Write(offset, &buffer, count); 352 int result = node_->Write(offset, &buffer, count);
218 EXPECT_EQ(count, result); 353 EXPECT_EQ(count, result);
219 } 354 }
220 355
221 TEST_F(MountHtml5FsNodeTest, Read) { 356 TEST_F(MountHtml5FsNodeSyncTest, Read) {
222 const int offset = 10; 357 const int offset = 10;
223 const int count = 20; 358 const int count = 20;
224 char buffer[30] = {0}; 359 char buffer[30] = {0};
225 360
226 EXPECT_CALL(*fileio_, Read(fileio_resource_, offset, &buffer[0], count, _)) 361 EXPECT_CALL(*fileio_, Read(fileio_resource_, offset, &buffer[0], count, _))
227 .WillOnce(Return(count)); 362 .WillOnce(Return(count));
228 363
229 int result = node_->Read(offset, &buffer, count); 364 int result = node_->Read(offset, &buffer, count);
230 EXPECT_EQ(count, result); 365 EXPECT_EQ(count, result);
231 } 366 }
232 367
233 TEST_F(MountHtml5FsNodeTest, GetStat) { 368 TEST_F(MountHtml5FsNodeSyncTest, GetStat) {
234 const int size = 123; 369 const int size = 123;
235 const int creation_time = 1000; 370 const int creation_time = 1000;
236 const int access_time = 2000; 371 const int access_time = 2000;
237 const int modified_time = 3000; 372 const int modified_time = 3000;
238 373
239 PP_FileInfo info; 374 PP_FileInfo info;
240 info.size = size; 375 info.size = size;
241 info.type = PP_FILETYPE_REGULAR; 376 info.type = PP_FILETYPE_REGULAR;
242 info.system_type = PP_FILESYSTEMTYPE_LOCALPERSISTENT; 377 info.system_type = PP_FILESYSTEMTYPE_LOCALPERSISTENT;
243 info.creation_time = creation_time; 378 info.creation_time = creation_time;
244 info.last_access_time = access_time; 379 info.last_access_time = access_time;
245 info.last_modified_time = modified_time; 380 info.last_modified_time = modified_time;
246 381
247 EXPECT_CALL(*fileio_, Query(fileio_resource_, _, _)) 382 EXPECT_CALL(*fileio_, Query(fileio_resource_, _, _))
248 .WillOnce(DoAll(SetArgPointee<1>(info), 383 .WillOnce(DoAll(SetArgPointee<1>(info),
249 Return(int32_t(PP_OK)))); 384 Return(int32_t(PP_OK))));
250 385
251 struct stat statbuf; 386 struct stat statbuf;
252 int result = node_->GetStat(&statbuf); 387 int result = node_->GetStat(&statbuf);
253 388
254 EXPECT_EQ(0, result); 389 EXPECT_EQ(0, result);
255 EXPECT_EQ(S_IFREG | S_IWRITE | S_IREAD, statbuf.st_mode); 390 EXPECT_EQ(S_IFREG | S_IWRITE | S_IREAD, statbuf.st_mode);
256 EXPECT_EQ(size, statbuf.st_size); 391 EXPECT_EQ(size, statbuf.st_size);
257 EXPECT_EQ(access_time, statbuf.st_atime); 392 EXPECT_EQ(access_time, statbuf.st_atime);
258 EXPECT_EQ(modified_time, statbuf.st_mtime); 393 EXPECT_EQ(modified_time, statbuf.st_mtime);
259 EXPECT_EQ(creation_time, statbuf.st_ctime); 394 EXPECT_EQ(creation_time, statbuf.st_ctime);
260 } 395 }
261 396
262 TEST_F(MountHtml5FsNodeTest, Truncate) { 397 TEST_F(MountHtml5FsNodeSyncTest, Truncate) {
263 const int size = 123; 398 const int size = 123;
264 EXPECT_CALL(*fileio_, SetLength(fileio_resource_, size, _)) 399 EXPECT_CALL(*fileio_, SetLength(fileio_resource_, size, _))
265 .WillOnce(Return(int32_t(PP_OK))); 400 .WillOnce(Return(int32_t(PP_OK)));
266 401
267 int result = node_->Truncate(size); 402 int result = node_->Truncate(size);
268 EXPECT_EQ(0, result); 403 EXPECT_EQ(0, result);
269 } 404 }
270 405
271 TEST_F(MountHtml5FsNodeTest, GetDents) { 406 TEST_F(MountHtml5FsNodeSyncTest, GetDents) {
272 const int dir_reader_resource = 237; 407 const int dir_reader_resource = 237;
273 const int fileref_resource_1 = 238; 408 const int fileref_resource_1 = 238;
274 const int fileref_resource_2 = 239; 409 const int fileref_resource_2 = 239;
275 410
276 const int fileref_name_id_1 = 240; 411 const int fileref_name_id_1 = 240;
277 const char fileref_name_cstr_1[] = "bar"; 412 const char fileref_name_cstr_1[] = "bar";
278 PP_Var fileref_name_1; 413 PP_Var fileref_name_1;
279 fileref_name_1.type = PP_VARTYPE_STRING; 414 fileref_name_1.type = PP_VARTYPE_STRING;
280 fileref_name_1.value.as_id = fileref_name_id_1; 415 fileref_name_1.value.as_id = fileref_name_id_1;
281 416
(...skipping 28 matching lines...) Expand all
310 EXPECT_CALL(*ppapi_, ReleaseResource(fileref_resource_2)); 445 EXPECT_CALL(*ppapi_, ReleaseResource(fileref_resource_2));
311 446
312 struct dirent dirents[2]; 447 struct dirent dirents[2];
313 memset(&dirents[0], 0, sizeof(dirents)); 448 memset(&dirents[0], 0, sizeof(dirents));
314 int result = node_->GetDents(0, &dirents[0], sizeof(dirent) * 2); 449 int result = node_->GetDents(0, &dirents[0], sizeof(dirent) * 2);
315 450
316 EXPECT_EQ(0, result); 451 EXPECT_EQ(0, result);
317 EXPECT_STREQ(&fileref_name_cstr_1[0], &dirents[0].d_name[0]); 452 EXPECT_STREQ(&fileref_name_cstr_1[0], &dirents[0].d_name[0]);
318 EXPECT_STREQ(&fileref_name_cstr_2[0], &dirents[1].d_name[0]); 453 EXPECT_STREQ(&fileref_name_cstr_2[0], &dirents[1].d_name[0]);
319 } 454 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698