| 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 "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, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 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 &unused_handles, |
| 63 &new_msg_ptr); | 53 &new_msg_ptr); |
| 64 EXPECT_FALSE(new_msg_ptr); | 54 EXPECT_FALSE(new_msg_ptr); |
| 65 } | 55 } |
| 66 }; | 56 }; |
| 67 | 57 |
| 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) { | 58 TEST_F(NaClMessageScannerTest, FileOpenClose) { |
| 90 NaClMessageScanner test; | 59 NaClMessageScanner test; |
| 91 std::vector<SerializedHandle> unused_handles; | 60 std::vector<SerializedHandle> unused_handles; |
| 92 ResourceMessageCallParams fio_call_params(kFileIO, 0); | 61 ResourceMessageCallParams fio_call_params(kFileIO, 0); |
| 93 ResourceMessageCallParams fs_call_params(kFileSystem, 0); | 62 ResourceMessageCallParams fs_call_params(kFileSystem, 0); |
| 94 ResourceMessageReplyParams fio_reply_params(kFileIO, 0); | 63 ResourceMessageReplyParams fio_reply_params(kFileIO, 0); |
| 95 ResourceMessageReplyParams fs_reply_params(kFileSystem, 0); | 64 ResourceMessageReplyParams fs_reply_params(kFileSystem, 0); |
| 96 scoped_ptr<IPC::Message> new_msg_ptr; | 65 scoped_ptr<IPC::Message> new_msg_ptr; |
| 97 | 66 |
| 98 EXPECT_EQ(NULL, FindFileSystem(test, kFileSystem)); | 67 EXPECT_EQ(NULL, FindFileSystem(test, kFileSystem)); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 UnpackMessage<PpapiHostMsg_FileIO_SetLength>( | 255 UnpackMessage<PpapiHostMsg_FileIO_SetLength>( |
| 287 nested_msg, &length)); | 256 nested_msg, &length)); |
| 288 new_msg_ptr.reset(); | 257 new_msg_ptr.reset(); |
| 289 EXPECT_EQ(-1, length); | 258 EXPECT_EQ(-1, length); |
| 290 EXPECT_EQ(kQuotaReservationAmount - kNewFileSize, fs->reserved_quota()); | 259 EXPECT_EQ(kQuotaReservationAmount - kNewFileSize, fs->reserved_quota()); |
| 291 EXPECT_EQ(kNewFileSize, fio->max_written_offset()); | 260 EXPECT_EQ(kNewFileSize, fio->max_written_offset()); |
| 292 } | 261 } |
| 293 | 262 |
| 294 } // namespace proxy | 263 } // namespace proxy |
| 295 } // namespace ppapi | 264 } // namespace ppapi |
| OLD | NEW |