OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/chromeos/drive/fileapi_worker.h" | 5 #include "chrome/browser/chromeos/drive/fileapi_worker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 const OpenMode expected_open_mode_; | 63 const OpenMode expected_open_mode_; |
64 bool closed_; | 64 bool closed_; |
65 }; | 65 }; |
66 | 66 |
67 // Helper function of testing OpenFile() for write access. It checks that the | 67 // Helper function of testing OpenFile() for write access. It checks that the |
68 // file handle correctly writes to the expected file. | 68 // file handle correctly writes to the expected file. |
69 void VerifyWrite( | 69 void VerifyWrite( |
70 int64 expected_size, | 70 int64 expected_size, |
71 const base::FilePath& expected_written_path, | 71 const base::FilePath& expected_written_path, |
72 const std::string& write_data, | 72 const std::string& write_data, |
73 base::PlatformFileError result, | 73 base::File::Error result, |
74 base::PlatformFile platform_file, | 74 base::PlatformFile platform_file, |
75 const base::Closure& close_callback) { | 75 const base::Closure& close_callback) { |
76 // Check that the file is properly opened. | 76 // Check that the file is properly opened. |
77 EXPECT_EQ(base::PLATFORM_FILE_OK, result); | 77 EXPECT_EQ(base::File::FILE_OK, result); |
78 EXPECT_NE(base::kInvalidPlatformFileValue, platform_file); | 78 EXPECT_NE(base::kInvalidPlatformFileValue, platform_file); |
79 EXPECT_FALSE(close_callback.is_null()); | 79 EXPECT_FALSE(close_callback.is_null()); |
80 | 80 |
81 // Check that the file has the expected length (i.e., truncated or not) | 81 // Check that the file has the expected length (i.e., truncated or not) |
82 base::PlatformFileInfo info; | 82 base::PlatformFileInfo info; |
83 EXPECT_TRUE(base::GetPlatformFileInfo(platform_file, &info)); | 83 EXPECT_TRUE(base::GetPlatformFileInfo(platform_file, &info)); |
84 EXPECT_EQ(expected_size, info.size); | 84 EXPECT_EQ(expected_size, info.size); |
85 | 85 |
86 // Write some data. | 86 // Write some data. |
87 const int data_size = static_cast<int>(write_data.size()); | 87 const int data_size = static_cast<int>(write_data.size()); |
88 EXPECT_EQ(data_size, | 88 EXPECT_EQ(data_size, |
89 base::WritePlatformFile(platform_file, 0, write_data.c_str(), | 89 base::WritePlatformFile(platform_file, 0, write_data.c_str(), |
90 data_size)); | 90 data_size)); |
91 EXPECT_TRUE(base::TruncatePlatformFile(platform_file, data_size)); | 91 EXPECT_TRUE(base::TruncatePlatformFile(platform_file, data_size)); |
92 | 92 |
93 // Close. | 93 // Close. |
94 base::ClosePlatformFile(platform_file); | 94 base::ClosePlatformFile(platform_file); |
95 close_callback.Run(); | 95 close_callback.Run(); |
96 | 96 |
97 // Checks that the written content goes to |expected_written_path|. I.e., | 97 // Checks that the written content goes to |expected_written_path|. I.e., |
98 // the |platform_file| handle is pointing to the file. | 98 // the |platform_file| handle is pointing to the file. |
99 std::string written; | 99 std::string written; |
100 EXPECT_TRUE(base::ReadFileToString(expected_written_path, &written)); | 100 EXPECT_TRUE(base::ReadFileToString(expected_written_path, &written)); |
101 EXPECT_EQ(write_data, written); | 101 EXPECT_EQ(write_data, written); |
102 } | 102 } |
103 | 103 |
104 // Helper function of testing OpenFile() for read access. It checks that the | 104 // Helper function of testing OpenFile() for read access. It checks that the |
105 // file is readable and contains |expected_data|. | 105 // file is readable and contains |expected_data|. |
106 void VerifyRead(const std::string& expected_data, | 106 void VerifyRead(const std::string& expected_data, |
107 base::PlatformFileError result, | 107 base::File::Error result, |
108 base::PlatformFile platform_file, | 108 base::PlatformFile platform_file, |
109 const base::Closure& close_callback) { | 109 const base::Closure& close_callback) { |
110 // Check that the file is properly opened. | 110 // Check that the file is properly opened. |
111 EXPECT_EQ(base::PLATFORM_FILE_OK, result); | 111 EXPECT_EQ(base::File::FILE_OK, result); |
112 EXPECT_NE(base::kInvalidPlatformFileValue, platform_file); | 112 EXPECT_NE(base::kInvalidPlatformFileValue, platform_file); |
113 EXPECT_FALSE(close_callback.is_null()); | 113 EXPECT_FALSE(close_callback.is_null()); |
114 | 114 |
115 // Check that the file has the expected content. | 115 // Check that the file has the expected content. |
116 const int data_size = static_cast<int>(expected_data.size()); | 116 const int data_size = static_cast<int>(expected_data.size()); |
117 base::PlatformFileInfo info; | 117 base::PlatformFileInfo info; |
118 EXPECT_TRUE(base::GetPlatformFileInfo(platform_file, &info)); | 118 EXPECT_TRUE(base::GetPlatformFileInfo(platform_file, &info)); |
119 EXPECT_EQ(data_size, info.size); | 119 EXPECT_EQ(data_size, info.size); |
120 | 120 |
121 std::vector<char> buffer(data_size); | 121 std::vector<char> buffer(data_size); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 OpenFile(kDummyPath, | 264 OpenFile(kDummyPath, |
265 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, | 265 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, |
266 base::Bind(&VerifyRead, kInitialData), | 266 base::Bind(&VerifyRead, kInitialData), |
267 &file_system); | 267 &file_system); |
268 test_util::RunBlockingPoolTask(); | 268 test_util::RunBlockingPoolTask(); |
269 EXPECT_TRUE(file_system.closed()); | 269 EXPECT_TRUE(file_system.closed()); |
270 } | 270 } |
271 | 271 |
272 } // namespace fileapi_internal | 272 } // namespace fileapi_internal |
273 } // namespace drive | 273 } // namespace drive |
OLD | NEW |