| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 TEST_F(FileSystemProviderOperationsOpenFileTest, Execute) { | 85 TEST_F(FileSystemProviderOperationsOpenFileTest, Execute) { |
| 86 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 86 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 87 CallbackLogger callback_logger; | 87 CallbackLogger callback_logger; |
| 88 | 88 |
| 89 OpenFile open_file(NULL, | 89 OpenFile open_file(NULL, |
| 90 file_system_info_, | 90 file_system_info_, |
| 91 base::FilePath::FromUTF8Unsafe(kFilePath), | 91 base::FilePath::FromUTF8Unsafe(kFilePath), |
| 92 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, | 92 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, |
| 93 false /* create */, | |
| 94 base::Bind(&CallbackLogger::OnOpenFile, | 93 base::Bind(&CallbackLogger::OnOpenFile, |
| 95 base::Unretained(&callback_logger))); | 94 base::Unretained(&callback_logger))); |
| 96 open_file.SetDispatchEventImplForTesting( | 95 open_file.SetDispatchEventImplForTesting( |
| 97 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 96 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 98 base::Unretained(&dispatcher))); | 97 base::Unretained(&dispatcher))); |
| 99 | 98 |
| 100 EXPECT_TRUE(open_file.Execute(kRequestId)); | 99 EXPECT_TRUE(open_file.Execute(kRequestId)); |
| 101 | 100 |
| 102 ASSERT_EQ(1u, dispatcher.events().size()); | 101 ASSERT_EQ(1u, dispatcher.events().size()); |
| 103 extensions::Event* event = dispatcher.events()[0]; | 102 extensions::Event* event = dispatcher.events()[0]; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 121 std::string event_file_path; | 120 std::string event_file_path; |
| 122 EXPECT_TRUE(options->GetString("filePath", &event_file_path)); | 121 EXPECT_TRUE(options->GetString("filePath", &event_file_path)); |
| 123 EXPECT_EQ(kFilePath, event_file_path); | 122 EXPECT_EQ(kFilePath, event_file_path); |
| 124 | 123 |
| 125 std::string event_file_open_mode; | 124 std::string event_file_open_mode; |
| 126 EXPECT_TRUE(options->GetString("mode", &event_file_open_mode)); | 125 EXPECT_TRUE(options->GetString("mode", &event_file_open_mode)); |
| 127 const std::string expected_file_open_mode = | 126 const std::string expected_file_open_mode = |
| 128 extensions::api::file_system_provider::ToString( | 127 extensions::api::file_system_provider::ToString( |
| 129 extensions::api::file_system_provider::OPEN_FILE_MODE_READ); | 128 extensions::api::file_system_provider::OPEN_FILE_MODE_READ); |
| 130 EXPECT_EQ(expected_file_open_mode, event_file_open_mode); | 129 EXPECT_EQ(expected_file_open_mode, event_file_open_mode); |
| 131 | |
| 132 bool event_create; | |
| 133 EXPECT_TRUE(options->GetBoolean("create", &event_create)); | |
| 134 EXPECT_FALSE(event_create); | |
| 135 } | 130 } |
| 136 | 131 |
| 137 TEST_F(FileSystemProviderOperationsOpenFileTest, Execute_NoListener) { | 132 TEST_F(FileSystemProviderOperationsOpenFileTest, Execute_NoListener) { |
| 138 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); | 133 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); |
| 139 CallbackLogger callback_logger; | 134 CallbackLogger callback_logger; |
| 140 | 135 |
| 141 OpenFile open_file(NULL, | 136 OpenFile open_file(NULL, |
| 142 file_system_info_, | 137 file_system_info_, |
| 143 base::FilePath::FromUTF8Unsafe(kFilePath), | 138 base::FilePath::FromUTF8Unsafe(kFilePath), |
| 144 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, | 139 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, |
| 145 false /* create */, | |
| 146 base::Bind(&CallbackLogger::OnOpenFile, | 140 base::Bind(&CallbackLogger::OnOpenFile, |
| 147 base::Unretained(&callback_logger))); | 141 base::Unretained(&callback_logger))); |
| 148 open_file.SetDispatchEventImplForTesting( | 142 open_file.SetDispatchEventImplForTesting( |
| 149 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 143 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 150 base::Unretained(&dispatcher))); | 144 base::Unretained(&dispatcher))); |
| 151 | 145 |
| 152 EXPECT_FALSE(open_file.Execute(kRequestId)); | 146 EXPECT_FALSE(open_file.Execute(kRequestId)); |
| 153 } | 147 } |
| 154 | 148 |
| 155 TEST_F(FileSystemProviderOperationsOpenFileTest, OnSuccess) { | 149 TEST_F(FileSystemProviderOperationsOpenFileTest, OnSuccess) { |
| 156 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 150 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 157 CallbackLogger callback_logger; | 151 CallbackLogger callback_logger; |
| 158 | 152 |
| 159 OpenFile open_file(NULL, | 153 OpenFile open_file(NULL, |
| 160 file_system_info_, | 154 file_system_info_, |
| 161 base::FilePath::FromUTF8Unsafe(kFilePath), | 155 base::FilePath::FromUTF8Unsafe(kFilePath), |
| 162 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, | 156 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, |
| 163 false /* create */, | |
| 164 base::Bind(&CallbackLogger::OnOpenFile, | 157 base::Bind(&CallbackLogger::OnOpenFile, |
| 165 base::Unretained(&callback_logger))); | 158 base::Unretained(&callback_logger))); |
| 166 open_file.SetDispatchEventImplForTesting( | 159 open_file.SetDispatchEventImplForTesting( |
| 167 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 160 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 168 base::Unretained(&dispatcher))); | 161 base::Unretained(&dispatcher))); |
| 169 | 162 |
| 170 EXPECT_TRUE(open_file.Execute(kRequestId)); | 163 EXPECT_TRUE(open_file.Execute(kRequestId)); |
| 171 | 164 |
| 172 open_file.OnSuccess(kRequestId, | 165 open_file.OnSuccess(kRequestId, |
| 173 scoped_ptr<RequestValue>(new RequestValue()), | 166 scoped_ptr<RequestValue>(new RequestValue()), |
| 174 false /* has_more */); | 167 false /* has_more */); |
| 175 ASSERT_EQ(1u, callback_logger.events().size()); | 168 ASSERT_EQ(1u, callback_logger.events().size()); |
| 176 CallbackLogger::Event* event = callback_logger.events()[0]; | 169 CallbackLogger::Event* event = callback_logger.events()[0]; |
| 177 EXPECT_EQ(base::File::FILE_OK, event->result()); | 170 EXPECT_EQ(base::File::FILE_OK, event->result()); |
| 178 EXPECT_LT(0, event->file_handle()); | 171 EXPECT_LT(0, event->file_handle()); |
| 179 } | 172 } |
| 180 | 173 |
| 181 TEST_F(FileSystemProviderOperationsOpenFileTest, OnError) { | 174 TEST_F(FileSystemProviderOperationsOpenFileTest, OnError) { |
| 182 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 175 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 183 CallbackLogger callback_logger; | 176 CallbackLogger callback_logger; |
| 184 | 177 |
| 185 OpenFile open_file(NULL, | 178 OpenFile open_file(NULL, |
| 186 file_system_info_, | 179 file_system_info_, |
| 187 base::FilePath::FromUTF8Unsafe(kFilePath), | 180 base::FilePath::FromUTF8Unsafe(kFilePath), |
| 188 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, | 181 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, |
| 189 false /* create */, | |
| 190 base::Bind(&CallbackLogger::OnOpenFile, | 182 base::Bind(&CallbackLogger::OnOpenFile, |
| 191 base::Unretained(&callback_logger))); | 183 base::Unretained(&callback_logger))); |
| 192 open_file.SetDispatchEventImplForTesting( | 184 open_file.SetDispatchEventImplForTesting( |
| 193 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 185 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 194 base::Unretained(&dispatcher))); | 186 base::Unretained(&dispatcher))); |
| 195 | 187 |
| 196 EXPECT_TRUE(open_file.Execute(kRequestId)); | 188 EXPECT_TRUE(open_file.Execute(kRequestId)); |
| 197 | 189 |
| 198 open_file.OnError(kRequestId, | 190 open_file.OnError(kRequestId, |
| 199 scoped_ptr<RequestValue>(new RequestValue()), | 191 scoped_ptr<RequestValue>(new RequestValue()), |
| 200 base::File::FILE_ERROR_TOO_MANY_OPENED); | 192 base::File::FILE_ERROR_TOO_MANY_OPENED); |
| 201 ASSERT_EQ(1u, callback_logger.events().size()); | 193 ASSERT_EQ(1u, callback_logger.events().size()); |
| 202 CallbackLogger::Event* event = callback_logger.events()[0]; | 194 CallbackLogger::Event* event = callback_logger.events()[0]; |
| 203 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); | 195 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); |
| 204 ASSERT_EQ(0, event->file_handle()); | 196 ASSERT_EQ(0, event->file_handle()); |
| 205 } | 197 } |
| 206 | 198 |
| 207 } // namespace operations | 199 } // namespace operations |
| 208 } // namespace file_system_provider | 200 } // namespace file_system_provider |
| 209 } // namespace chromeos | 201 } // namespace chromeos |
| OLD | NEW |