1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "ppapi/tests/test_file_system.h" 6 7 #include <string.h> 8 9 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/cpp/file_system.h" 11 #include "ppapi/tests/test_utils.h" 12 #include "ppapi/tests/testing_instance.h" 13 14 REGISTER_TEST_CASE(FileSystem); 15 16 bool TestFileSystem::Init() { 17 return CheckTestingInterface() && EnsureRunningOverHTTP(); 18 } 19 20 void TestFileSystem::RunTests(const std::string& filter) { 21 RUN_CALLBACK_TEST(TestFileSystem, Open, filter); 22 RUN_CALLBACK_TEST(TestFileSystem, MultipleOpens, filter); 23 } 24 25 std::string TestFileSystem::TestOpen() { 26 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); 27 28 // Open. 29 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); 30 callback.WaitForResult(file_system.Open(1024, callback.GetCallback())); 31 CHECK_CALLBACK_BEHAVIOR(callback); 32 ASSERT_EQ(PP_OK, callback.result()); 33 34 // Open aborted. 35 int32_t rv = 0; 36 { 37 pp::FileSystem fs(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); 38 rv = fs.Open(1024, callback.GetCallback()); 39 } 40 callback.WaitForAbortResult(rv); 41 CHECK_CALLBACK_BEHAVIOR(callback); 42 43 PASS(); 44 } 45 46 std::string TestFileSystem::TestMultipleOpens() { 47 // Should not allow multiple opens, regardless of whether or not the first 48 // open has completed. 49 TestCompletionCallback callback_1(instance_->pp_instance(), callback_type()); 50 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); 51 int32_t rv_1 = file_system.Open(1024, callback_1.GetCallback()); 52 53 TestCompletionCallback callback_2(instance_->pp_instance(), callback_type()); 54 callback_2.WaitForResult(file_system.Open(1024, callback_2.GetCallback())); 55 CHECK_CALLBACK_BEHAVIOR(callback_2); 56 // FileSystem should not allow multiple opens. 57 ASSERT_NE(PP_OK, callback_2.result()); 58 59 callback_1.WaitForResult(rv_1); 60 CHECK_CALLBACK_BEHAVIOR(callback_1); 61 ASSERT_EQ(PP_OK, callback_1.result()); 62 63 TestCompletionCallback callback_3(instance_->pp_instance(), callback_type()); 64 callback_3.WaitForResult(file_system.Open(1024, callback_3.GetCallback())); 65 CHECK_CALLBACK_BEHAVIOR(callback_3); 66 ASSERT_NE(PP_OK, callback_3.result()); 67 68 PASS(); 69 } 70