OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Native Client 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 <string.h> |
| 6 |
| 7 #include "native_client/src/third_party/ppapi/c/pp_errors.h" |
| 8 #include "native_client/src/third_party/ppapi/c/ppb_core.h" |
| 9 #include "native_client/src/third_party/ppapi/c/ppb_file_io.h" |
| 10 #include "native_client/src/third_party/ppapi/c/ppb_file_ref.h" |
| 11 #include "native_client/src/third_party/ppapi/c/ppb_file_system.h" |
| 12 #include "native_client/tests/ppapi_test_lib/get_browser_interface.h" |
| 13 #include "native_client/tests/ppapi_test_lib/test_interface.h" |
| 14 #include "native_client/tests/ppapi_browser/ppb_file_io/common.h" |
| 15 |
| 16 namespace { |
| 17 |
| 18 using common::BoundPPAPIFunc; |
| 19 using common::FileIOTester; |
| 20 using common::InitFileInfo; |
| 21 using common::kTestData; |
| 22 using common::OpenFileForTest; |
| 23 using common::TestCallbackData; |
| 24 using common::TestSequenceElement; |
| 25 |
| 26 class TestQuery : public TestSequenceElement { |
| 27 public: |
| 28 TestQuery() : TestSequenceElement("TestQuery") {} |
| 29 |
| 30 private: |
| 31 virtual BoundPPAPIFunc GetCompletionCallbackInitiatingPPAPIFunction( |
| 32 TestCallbackData* callback_data) { |
| 33 PP_FileInfo* file_info = new PP_FileInfo; |
| 34 callback_data->data = file_info; |
| 35 return std::tr1::bind(PPBFileIO()->Query, callback_data->existing_file_io, |
| 36 file_info, std::tr1::placeholders::_1); |
| 37 } |
| 38 }; |
| 39 |
| 40 // Verify the results of calling PPB_FileIO:::Query in from a TestQuery object. |
| 41 class TestQueryFileVerify : public TestSequenceElement { |
| 42 public: |
| 43 TestQueryFileVerify() : TestSequenceElement("TestQueryFileVerify") {} |
| 44 |
| 45 private: |
| 46 virtual void Execute(TestCallbackData* callback_data) { |
| 47 PP_FileInfo* file_info = |
| 48 reinterpret_cast<PP_FileInfo*>(callback_data->data); |
| 49 EXPECT(file_info->type == callback_data->file_info.type); |
| 50 EXPECT(file_info->system_type == callback_data->file_info.system_type); |
| 51 // TODO(sanga): Fix this with the correct test. |
| 52 // EXPECT(file_info->last_access_time == |
| 53 // callback_data->file_info.last_access_time); |
| 54 EXPECT(file_info->last_modified_time == |
| 55 callback_data->file_info.last_modified_time); |
| 56 EXPECT(file_info->size == strlen(kTestData)); |
| 57 delete file_info; |
| 58 } |
| 59 }; |
| 60 |
| 61 void TestQueryFile(PP_FileSystemType system_type) { |
| 62 PP_FileInfo file_info = { 0 }; |
| 63 InitFileInfo(system_type, &file_info); |
| 64 FileIOTester tester(file_info); |
| 65 tester.AddSequenceElement(new OpenFileForTest); |
| 66 tester.AddSequenceElement(new TestQuery); |
| 67 tester.AddSequenceElement(new TestQueryFileVerify); |
| 68 tester.Run(); |
| 69 } |
| 70 |
| 71 } // namespace |
| 72 |
| 73 void TestQueryFileLocalPersistent() { |
| 74 TestQueryFile(PP_FILESYSTEMTYPE_LOCALPERSISTENT); |
| 75 TEST_PASSED; |
| 76 } |
| 77 |
| 78 void TestQueryFileLocalTemporary() { |
| 79 TestQueryFile(PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 80 TEST_PASSED; |
| 81 } |
OLD | NEW |