OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 #include "ppapi/c/pp_errors.h" | 6 #include "ppapi/c/pp_errors.h" |
7 #include "ppapi/c/ppb_file_io.h" | 7 #include "ppapi/c/ppb_file_io.h" |
8 #include "ppapi/c/ppb_file_ref.h" | 8 #include "ppapi/c/ppb_file_ref.h" |
9 #include "ppapi/c/ppb_file_system.h" | 9 #include "ppapi/c/ppb_file_system.h" |
10 #include "ppapi/proxy/file_system_resource.h" | 10 #include "ppapi/proxy/file_system_resource.h" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 231 |
232 // Should have sent a "reserve quota" message, with the amount of the request | 232 // Should have sent a "reserve quota" message, with the amount of the request |
233 // and a map of all currently open files to their max written offsets. | 233 // and a map of all currently open files to their max written offsets. |
234 ResourceMessageCallParams params; | 234 ResourceMessageCallParams params; |
235 IPC::Message msg; | 235 IPC::Message msg; |
236 ASSERT_TRUE(sink().GetFirstResourceCallMatching( | 236 ASSERT_TRUE(sink().GetFirstResourceCallMatching( |
237 PpapiHostMsg_FileSystem_ReserveQuota::ID, ¶ms, &msg)); | 237 PpapiHostMsg_FileSystem_ReserveQuota::ID, ¶ms, &msg)); |
238 sink().ClearMessages(); | 238 sink().ClearMessages(); |
239 | 239 |
240 int64_t amount = 0; | 240 int64_t amount = 0; |
241 FileOffsetMap max_written_offsets; | 241 FileGrowthMap file_growths; |
242 ASSERT_TRUE(UnpackMessage<PpapiHostMsg_FileSystem_ReserveQuota>( | 242 ASSERT_TRUE(UnpackMessage<PpapiHostMsg_FileSystem_ReserveQuota>( |
243 msg, &amount, &max_written_offsets)); | 243 msg, &amount, &file_growths)); |
244 ASSERT_EQ(kQuotaRequestAmount1, amount); | 244 ASSERT_EQ(kQuotaRequestAmount1, amount); |
245 ASSERT_EQ(2U, max_written_offsets.size()); | 245 ASSERT_EQ(2U, file_growths.size()); |
246 ASSERT_EQ(0, max_written_offsets[file_io1.get()]); | 246 ASSERT_EQ(0, file_growths[file_io1.get()].max_written_offset); |
247 ASSERT_EQ(0, max_written_offsets[file_io2.get()]); | 247 ASSERT_EQ(0, file_growths[file_io2.get()].max_written_offset); |
248 | 248 |
249 // Make another request while the "reserve quota" message is pending. | 249 // Make another request while the "reserve quota" message is pending. |
250 MockRequestQuotaCallback cb2; | 250 MockRequestQuotaCallback cb2; |
251 result = file_system_api->RequestQuota( | 251 result = file_system_api->RequestQuota( |
252 kQuotaRequestAmount2, | 252 kQuotaRequestAmount2, |
253 base::Bind(&MockRequestQuotaCallback::Callback, base::Unretained(&cb2))); | 253 base::Bind(&MockRequestQuotaCallback::Callback, base::Unretained(&cb2))); |
254 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 254 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
255 // No new "reserve quota" message should be sent while one is pending. | 255 // No new "reserve quota" message should be sent while one is pending. |
256 ASSERT_FALSE(sink().GetFirstResourceCallMatching( | 256 ASSERT_FALSE(sink().GetFirstResourceCallMatching( |
257 PpapiHostMsg_FileSystem_ReserveQuota::ID, ¶ms, &msg)); | 257 PpapiHostMsg_FileSystem_ReserveQuota::ID, ¶ms, &msg)); |
258 { | 258 { |
259 ProxyAutoUnlock unlock_to_prevent_deadlock; | 259 ProxyAutoUnlock unlock_to_prevent_deadlock; |
260 // Reply with quota reservation amount sufficient to cover both requests. | 260 // Reply with quota reservation amount sufficient to cover both requests. |
261 // Both callbacks should be called with the requests granted. | 261 // Both callbacks should be called with the requests granted. |
262 SendReply(params, | 262 SendReply(params, |
263 PP_OK, | 263 PP_OK, |
264 PpapiPluginMsg_FileSystem_ReserveQuotaReply( | 264 PpapiPluginMsg_FileSystem_ReserveQuotaReply( |
265 kQuotaRequestAmount1 + kQuotaRequestAmount2, | 265 kQuotaRequestAmount1 + kQuotaRequestAmount2, |
266 max_written_offsets)); | 266 FileGrowthMapToFileSizeMap(file_growths))); |
267 } | 267 } |
268 ASSERT_TRUE(cb1.called()); | 268 ASSERT_TRUE(cb1.called()); |
269 ASSERT_EQ(kQuotaRequestAmount1, cb1.result()); | 269 ASSERT_EQ(kQuotaRequestAmount1, cb1.result()); |
270 ASSERT_TRUE(cb2.called()); | 270 ASSERT_TRUE(cb2.called()); |
271 ASSERT_EQ(kQuotaRequestAmount2, cb2.result()); | 271 ASSERT_EQ(kQuotaRequestAmount2, cb2.result()); |
272 cb1.Reset(); | 272 cb1.Reset(); |
273 cb2.Reset(); | 273 cb2.Reset(); |
274 | 274 |
275 // All requests should fail when insufficient quota is returned to satisfy | 275 // All requests should fail when insufficient quota is returned to satisfy |
276 // the first request. | 276 // the first request. |
(...skipping 10 matching lines...) Expand all Loading... |
287 PpapiHostMsg_FileSystem_ReserveQuota::ID, ¶ms, &msg)); | 287 PpapiHostMsg_FileSystem_ReserveQuota::ID, ¶ms, &msg)); |
288 sink().ClearMessages(); | 288 sink().ClearMessages(); |
289 { | 289 { |
290 ProxyAutoUnlock unlock_to_prevent_deadlock; | 290 ProxyAutoUnlock unlock_to_prevent_deadlock; |
291 // Reply with quota reservation amount insufficient to cover the first | 291 // Reply with quota reservation amount insufficient to cover the first |
292 // request. | 292 // request. |
293 SendReply(params, | 293 SendReply(params, |
294 PP_OK, | 294 PP_OK, |
295 PpapiPluginMsg_FileSystem_ReserveQuotaReply( | 295 PpapiPluginMsg_FileSystem_ReserveQuotaReply( |
296 kQuotaRequestAmount1 - 1, | 296 kQuotaRequestAmount1 - 1, |
297 max_written_offsets)); | 297 FileGrowthMapToFileSizeMap(file_growths))); |
298 } | 298 } |
299 ASSERT_TRUE(cb1.called()); | 299 ASSERT_TRUE(cb1.called()); |
300 ASSERT_EQ(0, cb1.result()); | 300 ASSERT_EQ(0, cb1.result()); |
301 ASSERT_TRUE(cb2.called()); | 301 ASSERT_TRUE(cb2.called()); |
302 ASSERT_EQ(0, cb2.result()); | 302 ASSERT_EQ(0, cb2.result()); |
303 cb1.Reset(); | 303 cb1.Reset(); |
304 cb2.Reset(); | 304 cb2.Reset(); |
305 | 305 |
306 // A new request should be made if the quota reservation is enough to satisfy | 306 // A new request should be made if the quota reservation is enough to satisfy |
307 // at least one request. | 307 // at least one request. |
(...skipping 10 matching lines...) Expand all Loading... |
318 PpapiHostMsg_FileSystem_ReserveQuota::ID, ¶ms, &msg)); | 318 PpapiHostMsg_FileSystem_ReserveQuota::ID, ¶ms, &msg)); |
319 sink().ClearMessages(); | 319 sink().ClearMessages(); |
320 { | 320 { |
321 ProxyAutoUnlock unlock_to_prevent_deadlock; | 321 ProxyAutoUnlock unlock_to_prevent_deadlock; |
322 // Reply with quota reservation amount sufficient only to cover the first | 322 // Reply with quota reservation amount sufficient only to cover the first |
323 // request. | 323 // request. |
324 SendReply(params, | 324 SendReply(params, |
325 PP_OK, | 325 PP_OK, |
326 PpapiPluginMsg_FileSystem_ReserveQuotaReply( | 326 PpapiPluginMsg_FileSystem_ReserveQuotaReply( |
327 kQuotaRequestAmount1, | 327 kQuotaRequestAmount1, |
328 max_written_offsets)); | 328 FileGrowthMapToFileSizeMap(file_growths))); |
329 } | 329 } |
330 ASSERT_TRUE(cb1.called()); | 330 ASSERT_TRUE(cb1.called()); |
331 ASSERT_EQ(kQuotaRequestAmount1, cb1.result()); | 331 ASSERT_EQ(kQuotaRequestAmount1, cb1.result()); |
332 ASSERT_FALSE(cb2.called()); | 332 ASSERT_FALSE(cb2.called()); |
333 | 333 |
334 // Another request message should have been sent. | 334 // Another request message should have been sent. |
335 ASSERT_TRUE(sink().GetFirstResourceCallMatching( | 335 ASSERT_TRUE(sink().GetFirstResourceCallMatching( |
336 PpapiHostMsg_FileSystem_ReserveQuota::ID, ¶ms, &msg)); | 336 PpapiHostMsg_FileSystem_ReserveQuota::ID, ¶ms, &msg)); |
337 sink().ClearMessages(); | 337 sink().ClearMessages(); |
338 { | 338 { |
339 ProxyAutoUnlock unlock_to_prevent_deadlock; | 339 ProxyAutoUnlock unlock_to_prevent_deadlock; |
340 // Reply with quota reservation amount sufficient to cover the second | 340 // Reply with quota reservation amount sufficient to cover the second |
341 // request and some extra. | 341 // request and some extra. |
342 SendReply(params, | 342 SendReply(params, |
343 PP_OK, | 343 PP_OK, |
344 PpapiPluginMsg_FileSystem_ReserveQuotaReply( | 344 PpapiPluginMsg_FileSystem_ReserveQuotaReply( |
345 kQuotaRequestAmount1 + kQuotaRequestAmount2, | 345 kQuotaRequestAmount1 + kQuotaRequestAmount2, |
346 max_written_offsets)); | 346 FileGrowthMapToFileSizeMap(file_growths))); |
347 } | 347 } |
348 | 348 |
349 ASSERT_TRUE(cb2.called()); | 349 ASSERT_TRUE(cb2.called()); |
350 ASSERT_EQ(kQuotaRequestAmount2, cb2.result()); | 350 ASSERT_EQ(kQuotaRequestAmount2, cb2.result()); |
351 cb1.Reset(); | 351 cb1.Reset(); |
352 cb2.Reset(); | 352 cb2.Reset(); |
353 | 353 |
354 // There is kQuotaRequestAmount1 of quota left, and a request for it should | 354 // There is kQuotaRequestAmount1 of quota left, and a request for it should |
355 // succeed immediately. | 355 // succeed immediately. |
356 result = file_system_api->RequestQuota( | 356 result = file_system_api->RequestQuota( |
357 kQuotaRequestAmount1, | 357 kQuotaRequestAmount1, |
358 base::Bind(&MockRequestQuotaCallback::Callback, base::Unretained(&cb1))); | 358 base::Bind(&MockRequestQuotaCallback::Callback, base::Unretained(&cb1))); |
359 ASSERT_EQ(kQuotaRequestAmount1, result); | 359 ASSERT_EQ(kQuotaRequestAmount1, result); |
360 } | 360 } |
361 | 361 |
362 } // namespace proxy | 362 } // namespace proxy |
363 } // namespace ppapi | 363 } // namespace ppapi |
OLD | NEW |