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

Side by Side Diff: ppapi/proxy/nacl_message_scanner_unittest.cc

Issue 472073003: Pepper: Make pending_sync_msgs_ local to IO thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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
« no previous file with comments | « ppapi/proxy/nacl_message_scanner.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 "ipc/ipc_message.h" 5 #include "ipc/ipc_message.h"
6 #include "ppapi/proxy/nacl_message_scanner.h" 6 #include "ppapi/proxy/nacl_message_scanner.h"
7 #include "ppapi/proxy/ppapi_messages.h" 7 #include "ppapi/proxy/ppapi_messages.h"
8 #include "ppapi/proxy/ppapi_proxy_test.h" 8 #include "ppapi/proxy/ppapi_proxy_test.h"
9 #include "ppapi/proxy/serialized_handle.h" 9 #include "ppapi/proxy/serialized_handle.h"
10 #include "ppapi/shared_impl/host_resource.h" 10 #include "ppapi/shared_impl/host_resource.h"
11 11
12 namespace ppapi { 12 namespace ppapi {
13 namespace proxy { 13 namespace proxy {
14 14
15 namespace { 15 namespace {
16 const PP_Resource kInvalidResource = 0; 16 const PP_Resource kInvalidResource = 0;
17 const PP_Resource kFileSystem = 1; 17 const PP_Resource kFileSystem = 1;
18 const PP_Resource kFileIO = 2; 18 const PP_Resource kFileIO = 2;
19 const int64_t kQuotaReservationAmount = 100; 19 const int64_t kQuotaReservationAmount = 100;
20 } 20 }
21 21
22 class NaClMessageScannerTest : public PluginProxyTest { 22 class NaClMessageScannerTest : public PluginProxyTest {
23 public: 23 public:
24 NaClMessageScannerTest() {} 24 NaClMessageScannerTest() {}
25 25
26 uint32 FindPendingSyncMessage(
27 const NaClMessageScanner& scanner,
28 const IPC::Message& msg) {
29 int msg_id = IPC::SyncMessage::GetMessageId(msg);
30 std::map<int, uint32>::const_iterator it =
31 scanner.pending_sync_msgs_.find(msg_id);
32 // O can signal that no message was found.
33 return (it != scanner.pending_sync_msgs_.end()) ? it->second : 0;
34 }
35
36 NaClMessageScanner::FileSystem* FindFileSystem( 26 NaClMessageScanner::FileSystem* FindFileSystem(
37 const NaClMessageScanner& scanner, 27 const NaClMessageScanner& scanner,
38 PP_Resource file_system) { 28 PP_Resource file_system) {
39 NaClMessageScanner::FileSystemMap::const_iterator it = 29 NaClMessageScanner::FileSystemMap::const_iterator it =
40 scanner.file_systems_.find(file_system); 30 scanner.file_systems_.find(file_system);
41 return (it != scanner.file_systems_.end()) ? it->second : NULL; 31 return (it != scanner.file_systems_.end()) ? it->second : NULL;
42 } 32 }
43 33
44 NaClMessageScanner::FileIO* FindFileIO( 34 NaClMessageScanner::FileIO* FindFileIO(
45 const NaClMessageScanner& scanner, 35 const NaClMessageScanner& scanner,
46 PP_Resource file_io) { 36 PP_Resource file_io) {
47 NaClMessageScanner::FileIOMap::const_iterator it = 37 NaClMessageScanner::FileIOMap::const_iterator it =
48 scanner.files_.find(file_io); 38 scanner.files_.find(file_io);
49 return (it != scanner.files_.end()) ? it->second : NULL; 39 return (it != scanner.files_.end()) ? it->second : NULL;
50 } 40 }
51 41
52 void OpenQuotaFile(NaClMessageScanner* scanner, 42 void OpenQuotaFile(NaClMessageScanner* scanner,
53 PP_Resource file_io, 43 PP_Resource file_io,
54 PP_Resource file_system) { 44 PP_Resource file_system) {
55 std::vector<SerializedHandle> unused_handles; 45 std::vector<SerializedHandle> unused_handles;
56 ResourceMessageReplyParams fio_reply_params(file_io, 0); 46 ResourceMessageReplyParams fio_reply_params(file_io, 0);
57 scoped_ptr<IPC::Message> new_msg_ptr; 47 scoped_ptr<IPC::Message> new_msg_ptr;
58 scanner->ScanMessage( 48 scanner->ScanMessage(
59 PpapiPluginMsg_ResourceReply( 49 PpapiPluginMsg_ResourceReply(
60 fio_reply_params, 50 fio_reply_params,
61 PpapiPluginMsg_FileIO_OpenReply(file_system, 0)), 51 PpapiPluginMsg_FileIO_OpenReply(file_system, 0)),
62 &unused_handles, 52 PpapiPluginMsg_ResourceReply::ID,
63 &new_msg_ptr); 53 &unused_handles,
54 &new_msg_ptr);
64 EXPECT_FALSE(new_msg_ptr); 55 EXPECT_FALSE(new_msg_ptr);
65 } 56 }
66 }; 57 };
67 58
68 TEST_F(NaClMessageScannerTest, SyncMessageAndReply) {
69 NaClMessageScanner test;
70 ppapi::proxy::SerializedHandle handle(
71 ppapi::proxy::SerializedHandle::SHARED_MEMORY);
72 int id = -1;
73 IPC::Message msg =
74 PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer(
75 ppapi::API_ID_PPB_GRAPHICS_3D,
76 HostResource(),
77 4096, // size
78 &id,
79 &handle);
80 scoped_ptr<IPC::Message> new_msg_ptr;
81 EXPECT_NE(msg.type(), FindPendingSyncMessage(test, msg));
82 test.ScanUntrustedMessage(msg, &new_msg_ptr);
83 EXPECT_FALSE(new_msg_ptr);
84 EXPECT_EQ(msg.type(), FindPendingSyncMessage(test, msg));
85
86 // TODO(bbudge) Figure out how to put together a sync reply message.
87 }
88
89 TEST_F(NaClMessageScannerTest, FileOpenClose) { 59 TEST_F(NaClMessageScannerTest, FileOpenClose) {
90 NaClMessageScanner test; 60 NaClMessageScanner test;
91 std::vector<SerializedHandle> unused_handles; 61 std::vector<SerializedHandle> unused_handles;
92 ResourceMessageCallParams fio_call_params(kFileIO, 0); 62 ResourceMessageCallParams fio_call_params(kFileIO, 0);
93 ResourceMessageCallParams fs_call_params(kFileSystem, 0); 63 ResourceMessageCallParams fs_call_params(kFileSystem, 0);
94 ResourceMessageReplyParams fio_reply_params(kFileIO, 0); 64 ResourceMessageReplyParams fio_reply_params(kFileIO, 0);
95 ResourceMessageReplyParams fs_reply_params(kFileSystem, 0); 65 ResourceMessageReplyParams fs_reply_params(kFileSystem, 0);
96 scoped_ptr<IPC::Message> new_msg_ptr; 66 scoped_ptr<IPC::Message> new_msg_ptr;
97 67
98 EXPECT_EQ(NULL, FindFileSystem(test, kFileSystem)); 68 EXPECT_EQ(NULL, FindFileSystem(test, kFileSystem));
99 EXPECT_EQ(NULL, FindFileIO(test, kFileIO)); 69 EXPECT_EQ(NULL, FindFileIO(test, kFileIO));
100 70
101 // Open a file, not in a quota file system. 71 // Open a file, not in a quota file system.
102 test.ScanMessage( 72 test.ScanMessage(
103 PpapiPluginMsg_ResourceReply( 73 PpapiPluginMsg_ResourceReply(
104 fio_reply_params, 74 fio_reply_params,
105 PpapiPluginMsg_FileIO_OpenReply(kInvalidResource, 0)), 75 PpapiPluginMsg_FileIO_OpenReply(kInvalidResource, 0)),
76 PpapiPluginMsg_ResourceReply::ID,
106 &unused_handles, 77 &unused_handles,
107 &new_msg_ptr); 78 &new_msg_ptr);
108 EXPECT_FALSE(new_msg_ptr); 79 EXPECT_FALSE(new_msg_ptr);
109 EXPECT_FALSE(FindFileSystem(test, kFileSystem)); 80 EXPECT_FALSE(FindFileSystem(test, kFileSystem));
110 EXPECT_FALSE(FindFileIO(test, kFileIO)); 81 EXPECT_FALSE(FindFileIO(test, kFileIO));
111 82
112 // Open a file in a quota file system; info objects for it and its file system 83 // Open a file in a quota file system; info objects for it and its file system
113 // should be created. 84 // should be created.
114 OpenQuotaFile(&test, kFileIO, kFileSystem); 85 OpenQuotaFile(&test, kFileIO, kFileSystem);
115 NaClMessageScanner::FileSystem* fs = FindFileSystem(test, kFileSystem); 86 NaClMessageScanner::FileSystem* fs = FindFileSystem(test, kFileSystem);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // Receive reserved quota, and updated file sizes. 159 // Receive reserved quota, and updated file sizes.
189 const int64_t kNewFileSize = 10; 160 const int64_t kNewFileSize = 10;
190 FileSizeMap file_sizes; 161 FileSizeMap file_sizes;
191 file_sizes[kFileIO] = kNewFileSize; 162 file_sizes[kFileIO] = kNewFileSize;
192 test.ScanMessage( 163 test.ScanMessage(
193 PpapiPluginMsg_ResourceReply( 164 PpapiPluginMsg_ResourceReply(
194 fs_reply_params, 165 fs_reply_params,
195 PpapiPluginMsg_FileSystem_ReserveQuotaReply( 166 PpapiPluginMsg_FileSystem_ReserveQuotaReply(
196 kQuotaReservationAmount, 167 kQuotaReservationAmount,
197 file_sizes)), 168 file_sizes)),
169 PpapiPluginMsg_ResourceReply::ID,
198 &unused_handles, 170 &unused_handles,
199 &new_msg_ptr); 171 &new_msg_ptr);
200 EXPECT_FALSE(new_msg_ptr); 172 EXPECT_FALSE(new_msg_ptr);
201 EXPECT_EQ(kQuotaReservationAmount, fs->reserved_quota()); 173 EXPECT_EQ(kQuotaReservationAmount, fs->reserved_quota());
202 EXPECT_EQ(kNewFileSize, fio->max_written_offset()); 174 EXPECT_EQ(kNewFileSize, fio->max_written_offset());
203 175
204 // We should be able to grow the file within quota. 176 // We should be able to grow the file within quota.
205 EXPECT_TRUE(fio->Grow(1)); 177 EXPECT_TRUE(fio->Grow(1));
206 EXPECT_EQ(kQuotaReservationAmount - 1, fs->reserved_quota()); 178 EXPECT_EQ(kQuotaReservationAmount - 1, fs->reserved_quota());
207 EXPECT_EQ(kNewFileSize + 1, fio->max_written_offset()); 179 EXPECT_EQ(kNewFileSize + 1, fio->max_written_offset());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 // Receive reserved quota, and updated file sizes. 222 // Receive reserved quota, and updated file sizes.
251 const int64_t kNewFileSize = 10; 223 const int64_t kNewFileSize = 10;
252 FileSizeMap file_sizes; 224 FileSizeMap file_sizes;
253 file_sizes[kFileIO] = 0; 225 file_sizes[kFileIO] = 0;
254 test.ScanMessage( 226 test.ScanMessage(
255 PpapiPluginMsg_ResourceReply( 227 PpapiPluginMsg_ResourceReply(
256 fs_reply_params, 228 fs_reply_params,
257 PpapiPluginMsg_FileSystem_ReserveQuotaReply( 229 PpapiPluginMsg_FileSystem_ReserveQuotaReply(
258 kQuotaReservationAmount, 230 kQuotaReservationAmount,
259 file_sizes)), 231 file_sizes)),
232 PpapiPluginMsg_ResourceReply::ID,
260 &unused_handles, 233 &unused_handles,
261 &new_msg_ptr); 234 &new_msg_ptr);
262 235
263 // We should be able to SetLength within quota. 236 // We should be able to SetLength within quota.
264 test.ScanUntrustedMessage( 237 test.ScanUntrustedMessage(
265 PpapiHostMsg_ResourceCall( 238 PpapiHostMsg_ResourceCall(
266 fio_call_params, 239 fio_call_params,
267 PpapiHostMsg_FileIO_SetLength(kNewFileSize)), 240 PpapiHostMsg_FileIO_SetLength(kNewFileSize)),
268 &new_msg_ptr); 241 &new_msg_ptr);
269 EXPECT_FALSE(new_msg_ptr); 242 EXPECT_FALSE(new_msg_ptr);
(...skipping 16 matching lines...) Expand all
286 UnpackMessage<PpapiHostMsg_FileIO_SetLength>( 259 UnpackMessage<PpapiHostMsg_FileIO_SetLength>(
287 nested_msg, &length)); 260 nested_msg, &length));
288 new_msg_ptr.reset(); 261 new_msg_ptr.reset();
289 EXPECT_EQ(-1, length); 262 EXPECT_EQ(-1, length);
290 EXPECT_EQ(kQuotaReservationAmount - kNewFileSize, fs->reserved_quota()); 263 EXPECT_EQ(kQuotaReservationAmount - kNewFileSize, fs->reserved_quota());
291 EXPECT_EQ(kNewFileSize, fio->max_written_offset()); 264 EXPECT_EQ(kNewFileSize, fio->max_written_offset());
292 } 265 }
293 266
294 } // namespace proxy 267 } // namespace proxy
295 } // namespace ppapi 268 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/nacl_message_scanner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698