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

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

Issue 130053003: [Pepper] Wire up append mode writing support of FileIO (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: s/max_written_offsets/file_sizes/g Created 6 years, 11 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 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"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 EXPECT_TRUE(fio); 117 EXPECT_TRUE(fio);
118 EXPECT_EQ(0, fio->max_written_offset()); 118 EXPECT_EQ(0, fio->max_written_offset());
119 119
120 const int64_t kNewFileSize = 10; 120 const int64_t kNewFileSize = 10;
121 fio->SetMaxWrittenOffset(kNewFileSize); 121 fio->SetMaxWrittenOffset(kNewFileSize);
122 122
123 // We should not be able to under-report max_written_offset when closing. 123 // We should not be able to under-report max_written_offset when closing.
124 test.ScanUntrustedMessage( 124 test.ScanUntrustedMessage(
125 PpapiHostMsg_ResourceCall( 125 PpapiHostMsg_ResourceCall(
126 fio_call_params, 126 fio_call_params,
127 PpapiHostMsg_FileIO_Close(0)), 127 PpapiHostMsg_FileIO_Close(FileGrowth(0, 0))),
128 &new_msg_ptr); 128 &new_msg_ptr);
129 EXPECT_TRUE(new_msg_ptr); 129 EXPECT_TRUE(new_msg_ptr);
130 ResourceMessageCallParams call_params; 130 ResourceMessageCallParams call_params;
131 IPC::Message nested_msg; 131 IPC::Message nested_msg;
132 int64_t max_written_offset = 0; 132 FileGrowth file_growth;
133 EXPECT_TRUE(UnpackMessage<PpapiHostMsg_ResourceCall>( 133 EXPECT_TRUE(UnpackMessage<PpapiHostMsg_ResourceCall>(
134 *new_msg_ptr, &call_params, &nested_msg) && 134 *new_msg_ptr, &call_params, &nested_msg) &&
135 UnpackMessage<PpapiHostMsg_FileIO_Close>( 135 UnpackMessage<PpapiHostMsg_FileIO_Close>(
136 nested_msg, &max_written_offset)); 136 nested_msg, &file_growth));
137 new_msg_ptr.reset(); 137 new_msg_ptr.reset();
138 EXPECT_EQ(kNewFileSize, max_written_offset); 138 EXPECT_EQ(kNewFileSize, file_growth.max_written_offset);
139 EXPECT_FALSE(FindFileIO(test, kFileIO)); 139 EXPECT_FALSE(FindFileIO(test, kFileIO));
140 140
141 // Reopen the file. 141 // Reopen the file.
142 OpenQuotaFile(&test, kFileIO, kFileSystem); 142 OpenQuotaFile(&test, kFileIO, kFileSystem);
143 fio = FindFileIO(test, kFileIO); 143 fio = FindFileIO(test, kFileIO);
144 fio->SetMaxWrittenOffset(kNewFileSize); 144 fio->SetMaxWrittenOffset(kNewFileSize);
145 145
146 // Close with correct max_written_offset. 146 // Close with correct max_written_offset.
147 test.ScanUntrustedMessage( 147 test.ScanUntrustedMessage(
148 PpapiHostMsg_ResourceCall( 148 PpapiHostMsg_ResourceCall(
149 fio_call_params, 149 fio_call_params,
150 PpapiHostMsg_FileIO_Close(kNewFileSize)), 150 PpapiHostMsg_FileIO_Close(FileGrowth(kNewFileSize, 0))),
151 &new_msg_ptr); 151 &new_msg_ptr);
152 EXPECT_FALSE(new_msg_ptr); 152 EXPECT_FALSE(new_msg_ptr);
153 EXPECT_FALSE(FindFileIO(test, kFileIO)); 153 EXPECT_FALSE(FindFileIO(test, kFileIO));
154 154
155 // Destroy file system. 155 // Destroy file system.
156 test.ScanUntrustedMessage( 156 test.ScanUntrustedMessage(
157 PpapiHostMsg_ResourceCall( 157 PpapiHostMsg_ResourceCall(
158 fs_call_params, 158 fs_call_params,
159 PpapiHostMsg_ResourceDestroyed(kFileSystem)), 159 PpapiHostMsg_ResourceDestroyed(kFileSystem)),
160 &new_msg_ptr); 160 &new_msg_ptr);
(...skipping 17 matching lines...) Expand all
178 EXPECT_TRUE(fio); 178 EXPECT_TRUE(fio);
179 EXPECT_EQ(0, fio->max_written_offset()); 179 EXPECT_EQ(0, fio->max_written_offset());
180 180
181 // Without reserving quota, we should not be able to grow the file. 181 // Without reserving quota, we should not be able to grow the file.
182 EXPECT_FALSE(fio->Grow(1)); 182 EXPECT_FALSE(fio->Grow(1));
183 EXPECT_EQ(0, fs->reserved_quota()); 183 EXPECT_EQ(0, fs->reserved_quota());
184 EXPECT_EQ(0, fio->max_written_offset()); 184 EXPECT_EQ(0, fio->max_written_offset());
185 185
186 // Receive reserved quota, and updated file sizes. 186 // Receive reserved quota, and updated file sizes.
187 const int64_t kNewFileSize = 10; 187 const int64_t kNewFileSize = 10;
188 FileOffsetMap offset_map; 188 FileSizeMap file_sizes;
189 offset_map.insert(std::make_pair(kFileIO, kNewFileSize)); 189 file_sizes[kFileIO] = kNewFileSize;
190 test.ScanMessage( 190 test.ScanMessage(
191 PpapiPluginMsg_ResourceReply( 191 PpapiPluginMsg_ResourceReply(
192 fs_reply_params, 192 fs_reply_params,
193 PpapiPluginMsg_FileSystem_ReserveQuotaReply( 193 PpapiPluginMsg_FileSystem_ReserveQuotaReply(
194 kQuotaReservationAmount, 194 kQuotaReservationAmount,
195 offset_map)), 195 file_sizes)),
196 &unused_handles, 196 &unused_handles,
197 &new_msg_ptr); 197 &new_msg_ptr);
198 EXPECT_FALSE(new_msg_ptr); 198 EXPECT_FALSE(new_msg_ptr);
199 EXPECT_EQ(kQuotaReservationAmount, fs->reserved_quota()); 199 EXPECT_EQ(kQuotaReservationAmount, fs->reserved_quota());
200 EXPECT_EQ(kNewFileSize, fio->max_written_offset()); 200 EXPECT_EQ(kNewFileSize, fio->max_written_offset());
201 201
202 // We should be able to grow the file within quota. 202 // We should be able to grow the file within quota.
203 EXPECT_TRUE(fio->Grow(1)); 203 EXPECT_TRUE(fio->Grow(1));
204 EXPECT_EQ(kQuotaReservationAmount - 1, fs->reserved_quota()); 204 EXPECT_EQ(kQuotaReservationAmount - 1, fs->reserved_quota());
205 EXPECT_EQ(kNewFileSize + 1, fio->max_written_offset()); 205 EXPECT_EQ(kNewFileSize + 1, fio->max_written_offset());
206 206
207 // We should not be able to grow the file over quota. 207 // We should not be able to grow the file over quota.
208 EXPECT_FALSE(fio->Grow(kQuotaReservationAmount)); 208 EXPECT_FALSE(fio->Grow(kQuotaReservationAmount));
209 EXPECT_EQ(kQuotaReservationAmount - 1, fs->reserved_quota()); 209 EXPECT_EQ(kQuotaReservationAmount - 1, fs->reserved_quota());
210 EXPECT_EQ(kNewFileSize + 1, fio->max_written_offset()); 210 EXPECT_EQ(kNewFileSize + 1, fio->max_written_offset());
211 211
212 // Plugin should not under-report max written offsets when reserving quota. 212 // Plugin should not under-report max written offsets when reserving quota.
213 offset_map[kFileIO] = 0; // should be kNewFileSize + 1. 213 file_sizes[kFileIO] = 0; // should be kNewFileSize + 1.
214 test.ScanUntrustedMessage( 214 test.ScanUntrustedMessage(
215 PpapiHostMsg_ResourceCall( 215 PpapiHostMsg_ResourceCall(
216 fio_call_params, 216 fio_call_params,
217 PpapiHostMsg_FileSystem_ReserveQuota( 217 PpapiHostMsg_FileSystem_ReserveQuota(
218 kQuotaReservationAmount, 218 kQuotaReservationAmount,
219 offset_map)), 219 FileSizeMapToFileGrowthMap(file_sizes))),
220 &new_msg_ptr); 220 &new_msg_ptr);
221 EXPECT_TRUE(new_msg_ptr); 221 EXPECT_TRUE(new_msg_ptr);
222 ResourceMessageCallParams call_params; 222 ResourceMessageCallParams call_params;
223 IPC::Message nested_msg; 223 IPC::Message nested_msg;
224 int64_t amount = 0; 224 int64_t amount = 0;
225 FileOffsetMap new_offset_map; 225 FileGrowthMap new_file_growths;
226 EXPECT_TRUE(UnpackMessage<PpapiHostMsg_ResourceCall>( 226 EXPECT_TRUE(UnpackMessage<PpapiHostMsg_ResourceCall>(
227 *new_msg_ptr, &call_params, &nested_msg) && 227 *new_msg_ptr, &call_params, &nested_msg) &&
228 UnpackMessage<PpapiHostMsg_FileSystem_ReserveQuota>( 228 UnpackMessage<PpapiHostMsg_FileSystem_ReserveQuota>(
229 nested_msg, &amount, &new_offset_map)); 229 nested_msg, &amount, &new_file_growths));
230 new_msg_ptr.reset(); 230 new_msg_ptr.reset();
231 EXPECT_EQ(kQuotaReservationAmount, amount); 231 EXPECT_EQ(kQuotaReservationAmount, amount);
232 EXPECT_EQ(kNewFileSize + 1, new_offset_map[kFileIO]); 232 EXPECT_EQ(kNewFileSize + 1, new_file_growths[kFileIO].max_written_offset);
233 } 233 }
234 234
235 TEST_F(NaClMessageScannerTest, SetLength) { 235 TEST_F(NaClMessageScannerTest, SetLength) {
236 NaClMessageScanner test; 236 NaClMessageScanner test;
237 std::vector<SerializedHandle> unused_handles; 237 std::vector<SerializedHandle> unused_handles;
238 ResourceMessageCallParams fio_call_params(kFileIO, 0); 238 ResourceMessageCallParams fio_call_params(kFileIO, 0);
239 ResourceMessageCallParams fs_call_params(kFileSystem, 0); 239 ResourceMessageCallParams fs_call_params(kFileSystem, 0);
240 ResourceMessageReplyParams fio_reply_params(kFileIO, 0); 240 ResourceMessageReplyParams fio_reply_params(kFileIO, 0);
241 ResourceMessageReplyParams fs_reply_params(kFileSystem, 0); 241 ResourceMessageReplyParams fs_reply_params(kFileSystem, 0);
242 scoped_ptr<IPC::Message> new_msg_ptr; 242 scoped_ptr<IPC::Message> new_msg_ptr;
243 243
244 OpenQuotaFile(&test, kFileIO, kFileSystem); 244 OpenQuotaFile(&test, kFileIO, kFileSystem);
245 NaClMessageScanner::FileSystem* fs = FindFileSystem(test, kFileSystem); 245 NaClMessageScanner::FileSystem* fs = FindFileSystem(test, kFileSystem);
246 NaClMessageScanner::FileIO* fio = FindFileIO(test, kFileIO); 246 NaClMessageScanner::FileIO* fio = FindFileIO(test, kFileIO);
247 247
248 // Receive reserved quota, and updated file sizes. 248 // Receive reserved quota, and updated file sizes.
249 const int64_t kNewFileSize = 10; 249 const int64_t kNewFileSize = 10;
250 FileOffsetMap offset_map; 250 FileSizeMap file_sizes;
251 offset_map.insert(std::make_pair(kFileIO, 0)); 251 file_sizes[kFileIO] = 0;
252 test.ScanMessage( 252 test.ScanMessage(
253 PpapiPluginMsg_ResourceReply( 253 PpapiPluginMsg_ResourceReply(
254 fs_reply_params, 254 fs_reply_params,
255 PpapiPluginMsg_FileSystem_ReserveQuotaReply( 255 PpapiPluginMsg_FileSystem_ReserveQuotaReply(
256 kQuotaReservationAmount, 256 kQuotaReservationAmount,
257 offset_map)), 257 file_sizes)),
258 &unused_handles, 258 &unused_handles,
259 &new_msg_ptr); 259 &new_msg_ptr);
260 260
261 // We should be able to SetLength within quota. 261 // We should be able to SetLength within quota.
262 test.ScanUntrustedMessage( 262 test.ScanUntrustedMessage(
263 PpapiHostMsg_ResourceCall( 263 PpapiHostMsg_ResourceCall(
264 fio_call_params, 264 fio_call_params,
265 PpapiHostMsg_FileIO_SetLength(kNewFileSize)), 265 PpapiHostMsg_FileIO_SetLength(kNewFileSize)),
266 &new_msg_ptr); 266 &new_msg_ptr);
267 EXPECT_FALSE(new_msg_ptr); 267 EXPECT_FALSE(new_msg_ptr);
(...skipping 16 matching lines...) Expand all
284 UnpackMessage<PpapiHostMsg_FileIO_SetLength>( 284 UnpackMessage<PpapiHostMsg_FileIO_SetLength>(
285 nested_msg, &length)); 285 nested_msg, &length));
286 new_msg_ptr.reset(); 286 new_msg_ptr.reset();
287 EXPECT_EQ(-1, length); 287 EXPECT_EQ(-1, length);
288 EXPECT_EQ(kQuotaReservationAmount - kNewFileSize, fs->reserved_quota()); 288 EXPECT_EQ(kQuotaReservationAmount - kNewFileSize, fs->reserved_quota());
289 EXPECT_EQ(kNewFileSize, fio->max_written_offset()); 289 EXPECT_EQ(kNewFileSize, fio->max_written_offset());
290 } 290 }
291 291
292 } // namespace proxy 292 } // namespace proxy
293 } // namespace ppapi 293 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698