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

Side by Side Diff: ppapi/tests/test_file_ref.cc

Issue 113363004: PPAPI: Add new PPB_FileRef.MakeDirectory to support exclusive operation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ppapi/tests/test_file_ref.h" 5 #include "ppapi/tests/test_file_ref.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <sstream> 9 #include <sstream>
10 #include <vector> 10 #include <vector>
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 return callback.result(); 105 return callback.result();
106 } 106 }
107 107
108 void TestFileRef::RunTests(const std::string& filter) { 108 void TestFileRef::RunTests(const std::string& filter) {
109 RUN_CALLBACK_TEST(TestFileRef, Create, filter); 109 RUN_CALLBACK_TEST(TestFileRef, Create, filter);
110 RUN_CALLBACK_TEST(TestFileRef, GetFileSystemType, filter); 110 RUN_CALLBACK_TEST(TestFileRef, GetFileSystemType, filter);
111 RUN_CALLBACK_TEST(TestFileRef, GetName, filter); 111 RUN_CALLBACK_TEST(TestFileRef, GetName, filter);
112 RUN_CALLBACK_TEST(TestFileRef, GetPath, filter); 112 RUN_CALLBACK_TEST(TestFileRef, GetPath, filter);
113 RUN_CALLBACK_TEST(TestFileRef, GetParent, filter); 113 RUN_CALLBACK_TEST(TestFileRef, GetParent, filter);
114 RUN_CALLBACK_TEST(TestFileRef, MakeDirectory, filter); 114 RUN_CALLBACK_TEST(TestFileRef, MakeDirectory, filter);
115 RUN_CALLBACK_TEST(TestFileRef, MakeDirectoryExclusive, filter);
115 RUN_CALLBACK_TEST(TestFileRef, QueryAndTouchFile, filter); 116 RUN_CALLBACK_TEST(TestFileRef, QueryAndTouchFile, filter);
116 RUN_CALLBACK_TEST(TestFileRef, DeleteFileAndDirectory, filter); 117 RUN_CALLBACK_TEST(TestFileRef, DeleteFileAndDirectory, filter);
117 RUN_CALLBACK_TEST(TestFileRef, RenameFileAndDirectory, filter); 118 RUN_CALLBACK_TEST(TestFileRef, RenameFileAndDirectory, filter);
118 RUN_CALLBACK_TEST(TestFileRef, Query, filter); 119 RUN_CALLBACK_TEST(TestFileRef, Query, filter);
119 RUN_CALLBACK_TEST(TestFileRef, FileNameEscaping, filter); 120 RUN_CALLBACK_TEST(TestFileRef, FileNameEscaping, filter);
120 RUN_CALLBACK_TEST(TestFileRef, ReadDirectoryEntries, filter); 121 RUN_CALLBACK_TEST(TestFileRef, ReadDirectoryEntries, filter);
121 } 122 }
122 123
123 std::string TestFileRef::TestCreate() { 124 std::string TestFileRef::TestCreate() {
124 std::vector<std::string> invalid_paths; 125 std::vector<std::string> invalid_paths;
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 331
331 // MakeDirectory with nested path should fail. 332 // MakeDirectory with nested path should fail.
332 dir_ref = pp::FileRef(file_system, "/dir_make_dir_3/dir_make_dir_4"); 333 dir_ref = pp::FileRef(file_system, "/dir_make_dir_3/dir_make_dir_4");
333 callback.WaitForResult(dir_ref.MakeDirectory(callback.GetCallback())); 334 callback.WaitForResult(dir_ref.MakeDirectory(callback.GetCallback()));
334 CHECK_CALLBACK_BEHAVIOR(callback); 335 CHECK_CALLBACK_BEHAVIOR(callback);
335 ASSERT_NE(PP_OK, callback.result()); 336 ASSERT_NE(PP_OK, callback.result());
336 337
337 PASS(); 338 PASS();
338 } 339 }
339 340
341 std::string TestFileRef::TestMakeDirectoryExclusive() {
342 TestCompletionCallback callback(instance_->pp_instance(), callback_type());
343
344 // Open.
345 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
346 callback.WaitForResult(file_system.Open(1024, callback.GetCallback()));
347 CHECK_CALLBACK_BEHAVIOR(callback);
348 ASSERT_EQ(PP_OK, callback.result());
349
350 // Clean up.
351 pp::FileRef dir_ref(file_system, "/dir_exclusive");
352 int32_t rv = DeleteDirectoryRecursively(&dir_ref);
353 ASSERT_TRUE(rv == PP_OK || rv == PP_ERROR_FILENOTFOUND);
354
355 // MakeDirectoryExclusive.
356 callback.WaitForResult(dir_ref.MakeDirectoryExclusive(
357 PP_FALSE, callback.GetCallback()));
358 CHECK_CALLBACK_BEHAVIOR(callback);
359 ASSERT_EQ(PP_OK, callback.result());
360
361 // MakeDirectoryExclusive on the existing directory should fail.
362 callback.WaitForResult(dir_ref.MakeDirectoryExclusive(
363 PP_FALSE, callback.GetCallback()));
364 CHECK_CALLBACK_BEHAVIOR(callback);
365 ASSERT_EQ(PP_ERROR_FILEEXISTS, callback.result());
366
367 // MakeDirectoryExclusive with nested path.
368 dir_ref = pp::FileRef(file_system, "/dir_exclusive/dir1/dir2");
369 callback.WaitForResult(dir_ref.MakeDirectoryExclusive(
370 PP_FALSE, callback.GetCallback()));
371 CHECK_CALLBACK_BEHAVIOR(callback);
372 ASSERT_EQ(PP_ERROR_FILENOTFOUND, callback.result());
373
374 callback.WaitForResult(dir_ref.MakeDirectoryExclusive(
375 PP_TRUE, callback.GetCallback()));
376 CHECK_CALLBACK_BEHAVIOR(callback);
377 ASSERT_EQ(PP_OK, callback.result());
378
379 PASS();
380 }
381
340 std::string TestFileRef::TestQueryAndTouchFile() { 382 std::string TestFileRef::TestQueryAndTouchFile() {
341 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); 383 TestCompletionCallback callback(instance_->pp_instance(), callback_type());
342 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); 384 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
343 callback.WaitForResult(file_system.Open(1024, callback.GetCallback())); 385 callback.WaitForResult(file_system.Open(1024, callback.GetCallback()));
344 CHECK_CALLBACK_BEHAVIOR(callback); 386 CHECK_CALLBACK_BEHAVIOR(callback);
345 ASSERT_EQ(PP_OK, callback.result()); 387 ASSERT_EQ(PP_OK, callback.result());
346 388
347 pp::FileRef file_ref(file_system, "/file_touch"); 389 pp::FileRef file_ref(file_system, "/file_touch");
348 pp::FileIO file_io(instance_); 390 pp::FileIO file_io(instance_);
349 callback.WaitForResult( 391 callback.WaitForResult(
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 { 783 {
742 rv = pp::FileRef(file_system, test_dir_name) 784 rv = pp::FileRef(file_system, test_dir_name)
743 .ReadDirectoryEntries(output_callback.GetCallback()); 785 .ReadDirectoryEntries(output_callback.GetCallback());
744 } 786 }
745 output_callback.WaitForAbortResult(rv); 787 output_callback.WaitForAbortResult(rv);
746 CHECK_CALLBACK_BEHAVIOR(output_callback); 788 CHECK_CALLBACK_BEHAVIOR(output_callback);
747 789
748 790
749 PASS(); 791 PASS();
750 } 792 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698