OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/file_system_provider/operations/open_file.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/open_file.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, | 140 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, |
141 base::Bind(&CallbackLogger::OnOpenFile, | 141 base::Bind(&CallbackLogger::OnOpenFile, |
142 base::Unretained(&callback_logger))); | 142 base::Unretained(&callback_logger))); |
143 open_file.SetDispatchEventImplForTesting( | 143 open_file.SetDispatchEventImplForTesting( |
144 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 144 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
145 base::Unretained(&dispatcher))); | 145 base::Unretained(&dispatcher))); |
146 | 146 |
147 EXPECT_FALSE(open_file.Execute(kRequestId)); | 147 EXPECT_FALSE(open_file.Execute(kRequestId)); |
148 } | 148 } |
149 | 149 |
| 150 TEST_F(FileSystemProviderOperationsOpenFileTest, Execute_ReadOnly) { |
| 151 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 152 CallbackLogger callback_logger; |
| 153 |
| 154 const ProvidedFileSystemInfo read_only_file_system_info( |
| 155 kExtensionId, |
| 156 kFileSystemId, |
| 157 "" /* file_system_name */, |
| 158 false /* writable */, |
| 159 base::FilePath() /* mount_path */); |
| 160 |
| 161 // Opening for read on a read-only file system is allowed. |
| 162 { |
| 163 OpenFile open_file(NULL, |
| 164 read_only_file_system_info, |
| 165 base::FilePath::FromUTF8Unsafe(kFilePath), |
| 166 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, |
| 167 base::Bind(&CallbackLogger::OnOpenFile, |
| 168 base::Unretained(&callback_logger))); |
| 169 open_file.SetDispatchEventImplForTesting( |
| 170 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 171 base::Unretained(&dispatcher))); |
| 172 |
| 173 EXPECT_TRUE(open_file.Execute(kRequestId)); |
| 174 } |
| 175 |
| 176 // Opening for write on a read-only file system is forbidden and must fail. |
| 177 { |
| 178 OpenFile open_file(NULL, |
| 179 read_only_file_system_info, |
| 180 base::FilePath::FromUTF8Unsafe(kFilePath), |
| 181 ProvidedFileSystemInterface::OPEN_FILE_MODE_WRITE, |
| 182 base::Bind(&CallbackLogger::OnOpenFile, |
| 183 base::Unretained(&callback_logger))); |
| 184 open_file.SetDispatchEventImplForTesting( |
| 185 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 186 base::Unretained(&dispatcher))); |
| 187 |
| 188 EXPECT_FALSE(open_file.Execute(kRequestId)); |
| 189 } |
| 190 } |
| 191 |
150 TEST_F(FileSystemProviderOperationsOpenFileTest, OnSuccess) { | 192 TEST_F(FileSystemProviderOperationsOpenFileTest, OnSuccess) { |
151 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 193 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
152 CallbackLogger callback_logger; | 194 CallbackLogger callback_logger; |
153 | 195 |
154 OpenFile open_file(NULL, | 196 OpenFile open_file(NULL, |
155 file_system_info_, | 197 file_system_info_, |
156 base::FilePath::FromUTF8Unsafe(kFilePath), | 198 base::FilePath::FromUTF8Unsafe(kFilePath), |
157 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, | 199 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, |
158 base::Bind(&CallbackLogger::OnOpenFile, | 200 base::Bind(&CallbackLogger::OnOpenFile, |
159 base::Unretained(&callback_logger))); | 201 base::Unretained(&callback_logger))); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 base::File::FILE_ERROR_TOO_MANY_OPENED); | 235 base::File::FILE_ERROR_TOO_MANY_OPENED); |
194 ASSERT_EQ(1u, callback_logger.events().size()); | 236 ASSERT_EQ(1u, callback_logger.events().size()); |
195 CallbackLogger::Event* event = callback_logger.events()[0]; | 237 CallbackLogger::Event* event = callback_logger.events()[0]; |
196 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); | 238 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); |
197 ASSERT_EQ(0, event->file_handle()); | 239 ASSERT_EQ(0, event->file_handle()); |
198 } | 240 } |
199 | 241 |
200 } // namespace operations | 242 } // namespace operations |
201 } // namespace file_system_provider | 243 } // namespace file_system_provider |
202 } // namespace chromeos | 244 } // namespace chromeos |
OLD | NEW |