| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_flash_file.h" | 5 #include "ppapi/tests/test_flash_file.h" |
| 6 | 6 |
| 7 #include "ppapi/cpp/module.h" | 7 #include "ppapi/cpp/module.h" |
| 8 #include "ppapi/cpp/private/flash_file.h" |
| 8 #include "ppapi/tests/testing_instance.h" | 9 #include "ppapi/tests/testing_instance.h" |
| 9 #include "ppapi/tests/test_utils.h" | 10 #include "ppapi/tests/test_utils.h" |
| 10 | 11 |
| 11 #if defined(PPAPI_OS_WIN) | 12 #if defined(PPAPI_OS_WIN) |
| 12 #include <windows.h> | 13 #include <windows.h> |
| 13 #else | 14 #else |
| 14 #include <errno.h> | 15 #include <errno.h> |
| 15 #include <unistd.h> | 16 #include <unistd.h> |
| 16 #endif | 17 #endif |
| 17 | 18 |
| 19 using pp::flash::FileModuleLocal; |
| 20 |
| 18 namespace { | 21 namespace { |
| 19 | 22 |
| 20 void CloseFileHandle(PP_FileHandle file_handle) { | 23 void CloseFileHandle(PP_FileHandle file_handle) { |
| 21 #if defined(PPAPI_OS_WIN) | 24 #if defined(PPAPI_OS_WIN) |
| 22 CloseHandle(file_handle); | 25 CloseHandle(file_handle); |
| 23 #else | 26 #else |
| 24 close(file_handle); | 27 close(file_handle); |
| 25 #endif | 28 #endif |
| 26 } | 29 } |
| 27 | 30 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 72 |
| 70 delete[] buffer; | 73 delete[] buffer; |
| 71 return result; | 74 return result; |
| 72 } | 75 } |
| 73 | 76 |
| 74 } // namespace | 77 } // namespace |
| 75 | 78 |
| 76 REGISTER_TEST_CASE(FlashFile); | 79 REGISTER_TEST_CASE(FlashFile); |
| 77 | 80 |
| 78 TestFlashFile::TestFlashFile(TestingInstance* instance) | 81 TestFlashFile::TestFlashFile(TestingInstance* instance) |
| 79 : TestCase(instance), module_local_interface_(NULL) { | 82 : TestCase(instance) { |
| 80 } | 83 } |
| 81 | 84 |
| 82 TestFlashFile::~TestFlashFile() { | 85 TestFlashFile::~TestFlashFile() { |
| 83 } | 86 } |
| 84 | 87 |
| 85 bool TestFlashFile::Init() { | 88 bool TestFlashFile::Init() { |
| 86 module_local_interface_ = static_cast<const PPB_Flash_File_ModuleLocal*>( | 89 return FileModuleLocal::IsAvailable(); |
| 87 pp::Module::Get()->GetBrowserInterface( | |
| 88 PPB_FLASH_FILE_MODULELOCAL_INTERFACE)); | |
| 89 return !!module_local_interface_; | |
| 90 } | 90 } |
| 91 | 91 |
| 92 void TestFlashFile::RunTests(const std::string& filter) { | 92 void TestFlashFile::RunTests(const std::string& filter) { |
| 93 RUN_TEST(CreateTemporaryFile, filter); | 93 RUN_TEST(CreateTemporaryFile, filter); |
| 94 } | 94 } |
| 95 | 95 |
| 96 std::string TestFlashFile::TestCreateTemporaryFile() { | 96 std::string TestFlashFile::TestCreateTemporaryFile() { |
| 97 ASSERT_TRUE(FileModuleLocal::IsCreateTemporaryFileAvailable()); |
| 98 |
| 97 // Make sure that the root directory exists. | 99 // Make sure that the root directory exists. |
| 98 module_local_interface_->CreateDir(instance_->pp_instance(), ""); | 100 FileModuleLocal::CreateDir(instance_, std::string()); |
| 99 | 101 |
| 100 int32_t before_create = 0; | 102 size_t before_create = 0; |
| 101 ASSERT_SUBTEST_SUCCESS(GetItemCountUnderModuleLocalRoot(&before_create)); | 103 ASSERT_SUBTEST_SUCCESS(GetItemCountUnderModuleLocalRoot(&before_create)); |
| 102 | 104 |
| 103 PP_FileHandle file_handle = PP_kInvalidFileHandle; | 105 PP_FileHandle file_handle = FileModuleLocal::CreateTemporaryFile(instance_); |
| 104 int32_t result = module_local_interface_->CreateTemporaryFile( | 106 ASSERT_NE(PP_kInvalidFileHandle, file_handle); |
| 105 instance_->pp_instance(), &file_handle); | |
| 106 ASSERT_EQ(result, PP_OK); | |
| 107 | 107 |
| 108 std::string contents = "This is a temp file."; | 108 std::string contents = "This is a temp file."; |
| 109 ASSERT_TRUE(WriteFile(file_handle, contents)); | 109 ASSERT_TRUE(WriteFile(file_handle, contents)); |
| 110 std::string read_contents; | 110 std::string read_contents; |
| 111 ASSERT_TRUE(ReadFile(file_handle, &read_contents)); | 111 ASSERT_TRUE(ReadFile(file_handle, &read_contents)); |
| 112 ASSERT_EQ(contents, read_contents); | 112 ASSERT_EQ(contents, read_contents); |
| 113 | 113 |
| 114 CloseFileHandle(file_handle); | 114 CloseFileHandle(file_handle); |
| 115 | 115 |
| 116 int32_t after_close = 0; | 116 size_t after_close = 0; |
| 117 ASSERT_SUBTEST_SUCCESS(GetItemCountUnderModuleLocalRoot(&after_close)); | 117 ASSERT_SUBTEST_SUCCESS(GetItemCountUnderModuleLocalRoot(&after_close)); |
| 118 ASSERT_EQ(before_create, after_close); | 118 ASSERT_EQ(before_create, after_close); |
| 119 | 119 |
| 120 PASS(); | 120 PASS(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 std::string TestFlashFile::GetItemCountUnderModuleLocalRoot( | 123 std::string TestFlashFile::GetItemCountUnderModuleLocalRoot( |
| 124 int32_t* item_count) { | 124 size_t* item_count) { |
| 125 PP_DirContents_Dev* contents = NULL; | 125 std::vector<PP_DirEntry_Dev> contents; |
| 126 int32_t result = module_local_interface_->GetDirContents( | 126 ASSERT_TRUE(FileModuleLocal::GetDirContents(instance_, "", &contents)); |
| 127 instance_->pp_instance(), "", &contents); | 127 *item_count = contents.size(); |
| 128 ASSERT_EQ(result, PP_OK); | |
| 129 | |
| 130 *item_count = contents->count; | |
| 131 module_local_interface_->FreeDirContents(instance_->pp_instance(), contents); | |
| 132 PASS(); | 128 PASS(); |
| 133 } | 129 } |
| OLD | NEW |