| 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 <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" | 17 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" |
| 18 #include "chrome/common/extensions/api/file_system_provider.h" | 18 #include "chrome/common/extensions/api/file_system_provider.h" |
| 19 #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" | 20 #include "chrome/common/extensions/api/file_system_provider_internal.h" |
| 20 #include "extensions/browser/event_router.h" | 21 #include "extensions/browser/event_router.h" |
| 21 #include "net/base/io_buffer.h" | 22 #include "net/base/io_buffer.h" |
| 22 #include "storage/browser/fileapi/async_file_util.h" | 23 #include "storage/browser/fileapi/async_file_util.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 25 |
| 25 namespace chromeos { | 26 namespace chromeos { |
| 26 namespace file_system_provider { | 27 namespace file_system_provider { |
| 27 namespace operations { | 28 namespace operations { |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; | 31 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; |
| 31 const char kFileSystemId[] = "testing-file-system"; | 32 const char kFileSystemId[] = "testing-file-system"; |
| 32 const int kRequestId = 2; | 33 const int kRequestId = 2; |
| 33 const int kFileHandle = 3; | 34 const int kFileHandle = 3; |
| 34 const char kWriteData[] = "Welcome to my world!"; | 35 const char kWriteData[] = "Welcome to my world!"; |
| 35 const int kOffset = 10; | 36 const int kOffset = 10; |
| 36 | 37 |
| 37 } // namespace | 38 } // namespace |
| 38 | 39 |
| 39 class FileSystemProviderOperationsWriteFileTest : public testing::Test { | 40 class FileSystemProviderOperationsWriteFileTest : public testing::Test { |
| 40 protected: | 41 protected: |
| 41 FileSystemProviderOperationsWriteFileTest() {} | 42 FileSystemProviderOperationsWriteFileTest() {} |
| 42 ~FileSystemProviderOperationsWriteFileTest() override {} | 43 ~FileSystemProviderOperationsWriteFileTest() override {} |
| 43 | 44 |
| 44 void SetUp() override { | 45 void SetUp() override { |
| 45 MountOptions mount_options(kFileSystemId, "" /* display_name */); | 46 MountOptions mount_options(kFileSystemId, "" /* display_name */); |
| 46 mount_options.writable = true; | 47 mount_options.writable = true; |
| 47 file_system_info_ = | 48 file_system_info_ = ProvidedFileSystemInfo( |
| 48 ProvidedFileSystemInfo(kExtensionId, mount_options, base::FilePath()); | 49 kExtensionId, mount_options, base::FilePath(), false /* configurable */, |
| 50 extensions::SOURCE_FILE); |
| 49 io_buffer_ = make_scoped_refptr(new net::StringIOBuffer(kWriteData)); | 51 io_buffer_ = make_scoped_refptr(new net::StringIOBuffer(kWriteData)); |
| 50 } | 52 } |
| 51 | 53 |
| 52 ProvidedFileSystemInfo file_system_info_; | 54 ProvidedFileSystemInfo file_system_info_; |
| 53 scoped_refptr<net::StringIOBuffer> io_buffer_; | 55 scoped_refptr<net::StringIOBuffer> io_buffer_; |
| 54 }; | 56 }; |
| 55 | 57 |
| 56 TEST_F(FileSystemProviderOperationsWriteFileTest, Execute) { | 58 TEST_F(FileSystemProviderOperationsWriteFileTest, Execute) { |
| 57 using extensions::api::file_system_provider::WriteFileRequestedOptions; | 59 using extensions::api::file_system_provider::WriteFileRequestedOptions; |
| 58 | 60 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 base::Unretained(&dispatcher))); | 112 base::Unretained(&dispatcher))); |
| 111 | 113 |
| 112 EXPECT_FALSE(write_file.Execute(kRequestId)); | 114 EXPECT_FALSE(write_file.Execute(kRequestId)); |
| 113 } | 115 } |
| 114 | 116 |
| 115 TEST_F(FileSystemProviderOperationsWriteFileTest, Execute_ReadOnly) { | 117 TEST_F(FileSystemProviderOperationsWriteFileTest, Execute_ReadOnly) { |
| 116 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 118 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 117 util::StatusCallbackLog callback_log; | 119 util::StatusCallbackLog callback_log; |
| 118 | 120 |
| 119 const ProvidedFileSystemInfo read_only_file_system_info( | 121 const ProvidedFileSystemInfo read_only_file_system_info( |
| 120 kExtensionId, | 122 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */), |
| 121 MountOptions(kFileSystemId, "" /* display_name */), | 123 base::FilePath() /* mount_path */, false /* configurable */, |
| 122 base::FilePath() /* mount_path */); | 124 extensions::SOURCE_FILE); |
| 123 | 125 |
| 124 WriteFile write_file(NULL, | 126 WriteFile write_file(NULL, |
| 125 read_only_file_system_info, | 127 read_only_file_system_info, |
| 126 kFileHandle, | 128 kFileHandle, |
| 127 io_buffer_.get(), | 129 io_buffer_.get(), |
| 128 kOffset, | 130 kOffset, |
| 129 io_buffer_->size(), | 131 io_buffer_->size(), |
| 130 base::Bind(&util::LogStatusCallback, &callback_log)); | 132 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 131 write_file.SetDispatchEventImplForTesting( | 133 write_file.SetDispatchEventImplForTesting( |
| 132 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 134 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 scoped_ptr<RequestValue>(new RequestValue()), | 182 scoped_ptr<RequestValue>(new RequestValue()), |
| 181 base::File::FILE_ERROR_TOO_MANY_OPENED); | 183 base::File::FILE_ERROR_TOO_MANY_OPENED); |
| 182 | 184 |
| 183 ASSERT_EQ(1u, callback_log.size()); | 185 ASSERT_EQ(1u, callback_log.size()); |
| 184 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); | 186 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); |
| 185 } | 187 } |
| 186 | 188 |
| 187 } // namespace operations | 189 } // namespace operations |
| 188 } // namespace file_system_provider | 190 } // namespace file_system_provider |
| 189 } // namespace chromeos | 191 } // namespace chromeos |
| OLD | NEW |