| 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/write_file.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/write_file.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <string> | 8 #include <string> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/files/file.h" | 11 #include "base/files/file.h" |
| 11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" | 16 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" |
| 17 #include "chrome/common/extensions/api/file_system_provider.h" | 17 #include "chrome/common/extensions/api/file_system_provider.h" |
| 18 #include "chrome/common/extensions/api/file_system_provider_capabilities/file_sy
stem_provider_capabilities_handler.h" | 18 #include "chrome/common/extensions/api/file_system_provider_capabilities/file_sy
stem_provider_capabilities_handler.h" |
| 19 #include "chrome/common/extensions/api/file_system_provider_internal.h" | 19 #include "chrome/common/extensions/api/file_system_provider_internal.h" |
| 20 #include "extensions/browser/event_router.h" | 20 #include "extensions/browser/event_router.h" |
| 21 #include "net/base/io_buffer.h" | 21 #include "net/base/io_buffer.h" |
| 22 #include "storage/browser/fileapi/async_file_util.h" | 22 #include "storage/browser/fileapi/async_file_util.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 kOffset, | 147 kOffset, |
| 148 io_buffer_->size(), | 148 io_buffer_->size(), |
| 149 base::Bind(&util::LogStatusCallback, &callback_log)); | 149 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 150 write_file.SetDispatchEventImplForTesting( | 150 write_file.SetDispatchEventImplForTesting( |
| 151 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 151 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 152 base::Unretained(&dispatcher))); | 152 base::Unretained(&dispatcher))); |
| 153 | 153 |
| 154 EXPECT_TRUE(write_file.Execute(kRequestId)); | 154 EXPECT_TRUE(write_file.Execute(kRequestId)); |
| 155 | 155 |
| 156 write_file.OnSuccess(kRequestId, | 156 write_file.OnSuccess(kRequestId, |
| 157 scoped_ptr<RequestValue>(new RequestValue()), | 157 std::unique_ptr<RequestValue>(new RequestValue()), |
| 158 false /* has_more */); | 158 false /* has_more */); |
| 159 ASSERT_EQ(1u, callback_log.size()); | 159 ASSERT_EQ(1u, callback_log.size()); |
| 160 EXPECT_EQ(base::File::FILE_OK, callback_log[0]); | 160 EXPECT_EQ(base::File::FILE_OK, callback_log[0]); |
| 161 } | 161 } |
| 162 | 162 |
| 163 TEST_F(FileSystemProviderOperationsWriteFileTest, OnError) { | 163 TEST_F(FileSystemProviderOperationsWriteFileTest, OnError) { |
| 164 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 164 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 165 util::StatusCallbackLog callback_log; | 165 util::StatusCallbackLog callback_log; |
| 166 | 166 |
| 167 WriteFile write_file(NULL, | 167 WriteFile write_file(NULL, |
| 168 file_system_info_, | 168 file_system_info_, |
| 169 kFileHandle, | 169 kFileHandle, |
| 170 io_buffer_.get(), | 170 io_buffer_.get(), |
| 171 kOffset, | 171 kOffset, |
| 172 io_buffer_->size(), | 172 io_buffer_->size(), |
| 173 base::Bind(&util::LogStatusCallback, &callback_log)); | 173 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 174 write_file.SetDispatchEventImplForTesting( | 174 write_file.SetDispatchEventImplForTesting( |
| 175 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 175 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 176 base::Unretained(&dispatcher))); | 176 base::Unretained(&dispatcher))); |
| 177 | 177 |
| 178 EXPECT_TRUE(write_file.Execute(kRequestId)); | 178 EXPECT_TRUE(write_file.Execute(kRequestId)); |
| 179 | 179 |
| 180 write_file.OnError(kRequestId, | 180 write_file.OnError(kRequestId, |
| 181 scoped_ptr<RequestValue>(new RequestValue()), | 181 std::unique_ptr<RequestValue>(new RequestValue()), |
| 182 base::File::FILE_ERROR_TOO_MANY_OPENED); | 182 base::File::FILE_ERROR_TOO_MANY_OPENED); |
| 183 | 183 |
| 184 ASSERT_EQ(1u, callback_log.size()); | 184 ASSERT_EQ(1u, callback_log.size()); |
| 185 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); | 185 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); |
| 186 } | 186 } |
| 187 | 187 |
| 188 } // namespace operations | 188 } // namespace operations |
| 189 } // namespace file_system_provider | 189 } // namespace file_system_provider |
| 190 } // namespace chromeos | 190 } // namespace chromeos |
| OLD | NEW |