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.
5 #include "ppapi/tests/test_file_system.h"
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"
14 REGISTER_TEST_CASE(FileSystem
);
16 bool TestFileSystem::Init() {
17 return CheckTestingInterface() && EnsureRunningOverHTTP();
20 void TestFileSystem::RunTests(const std::string
& filter
) {
21 RUN_CALLBACK_TEST(TestFileSystem
, Open
, filter
);
22 RUN_CALLBACK_TEST(TestFileSystem
, MultipleOpens
, filter
);
25 std::string
TestFileSystem::TestOpen() {
26 TestCompletionCallback
callback(instance_
->pp_instance(), callback_type());
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());
34 // Open aborted (see the DirectoryReader test for comments).
37 pp::FileSystem
fs(instance_
, PP_FILESYSTEMTYPE_LOCALTEMPORARY
);
38 rv
= fs
.Open(1024, callback
.GetCallback());
40 callback
.WaitForAbortResult(rv
);
41 CHECK_CALLBACK_BEHAVIOR(callback
);
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());
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());
59 callback_1
.WaitForResult(rv_1
);
60 CHECK_CALLBACK_BEHAVIOR(callback_1
);
61 ASSERT_EQ(PP_OK
, callback_1
.result());
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());