| 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 | 8 |
| 9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 true /* writable */, | 47 true /* writable */, |
| 48 base::FilePath() /* mount_path */); | 48 base::FilePath() /* mount_path */); |
| 49 io_buffer_ = make_scoped_refptr(new net::StringIOBuffer(kWriteData)); | 49 io_buffer_ = make_scoped_refptr(new net::StringIOBuffer(kWriteData)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 ProvidedFileSystemInfo file_system_info_; | 52 ProvidedFileSystemInfo file_system_info_; |
| 53 scoped_refptr<net::StringIOBuffer> io_buffer_; | 53 scoped_refptr<net::StringIOBuffer> io_buffer_; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 TEST_F(FileSystemProviderOperationsWriteFileTest, Execute) { | 56 TEST_F(FileSystemProviderOperationsWriteFileTest, Execute) { |
| 57 using extensions::api::file_system_provider::WriteFileRequestedOptions; |
| 58 |
| 57 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 59 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 58 util::StatusCallbackLog callback_log; | 60 util::StatusCallbackLog callback_log; |
| 59 | 61 |
| 60 WriteFile write_file(NULL, | 62 WriteFile write_file(NULL, |
| 61 file_system_info_, | 63 file_system_info_, |
| 62 kFileHandle, | 64 kFileHandle, |
| 63 io_buffer_.get(), | 65 io_buffer_.get(), |
| 64 kOffset, | 66 kOffset, |
| 65 io_buffer_->size(), | 67 io_buffer_->size(), |
| 66 base::Bind(&util::LogStatusCallback, &callback_log)); | 68 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 67 write_file.SetDispatchEventImplForTesting( | 69 write_file.SetDispatchEventImplForTesting( |
| 68 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 70 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 69 base::Unretained(&dispatcher))); | 71 base::Unretained(&dispatcher))); |
| 70 | 72 |
| 71 EXPECT_TRUE(write_file.Execute(kRequestId)); | 73 EXPECT_TRUE(write_file.Execute(kRequestId)); |
| 72 | 74 |
| 73 ASSERT_EQ(1u, dispatcher.events().size()); | 75 ASSERT_EQ(1u, dispatcher.events().size()); |
| 74 extensions::Event* event = dispatcher.events()[0]; | 76 extensions::Event* event = dispatcher.events()[0]; |
| 75 EXPECT_EQ( | 77 EXPECT_EQ( |
| 76 extensions::api::file_system_provider::OnWriteFileRequested::kEventName, | 78 extensions::api::file_system_provider::OnWriteFileRequested::kEventName, |
| 77 event->event_name); | 79 event->event_name); |
| 78 base::ListValue* event_args = event->event_args.get(); | 80 base::ListValue* event_args = event->event_args.get(); |
| 79 ASSERT_EQ(1u, event_args->GetSize()); | 81 ASSERT_EQ(1u, event_args->GetSize()); |
| 80 | 82 |
| 81 base::DictionaryValue* options = NULL; | 83 const base::DictionaryValue* options_as_value = NULL; |
| 82 ASSERT_TRUE(event_args->GetDictionary(0, &options)); | 84 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); |
| 83 | 85 |
| 84 std::string event_file_system_id; | 86 WriteFileRequestedOptions options; |
| 85 EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id)); | 87 ASSERT_TRUE(WriteFileRequestedOptions::Populate(*options_as_value, &options)); |
| 86 EXPECT_EQ(kFileSystemId, event_file_system_id); | 88 EXPECT_EQ(kFileSystemId, options.file_system_id); |
| 87 | 89 EXPECT_EQ(kRequestId, options.request_id); |
| 88 int event_request_id = -1; | 90 EXPECT_EQ(kFileHandle, options.open_request_id); |
| 89 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); | 91 EXPECT_EQ(kOffset, static_cast<double>(options.offset)); |
| 90 EXPECT_EQ(kRequestId, event_request_id); | 92 EXPECT_EQ(std::string(kWriteData), options.data); |
| 91 | |
| 92 int event_file_handle = -1; | |
| 93 EXPECT_TRUE(options->GetInteger("openRequestId", &event_file_handle)); | |
| 94 EXPECT_EQ(kFileHandle, event_file_handle); | |
| 95 | |
| 96 double event_offset = -1; | |
| 97 EXPECT_TRUE(options->GetDouble("offset", &event_offset)); | |
| 98 EXPECT_EQ(kOffset, static_cast<double>(event_offset)); | |
| 99 | |
| 100 base::BinaryValue* event_data = NULL; | |
| 101 ASSERT_TRUE(options->GetBinary("data", &event_data)); | |
| 102 EXPECT_EQ(static_cast<size_t>(io_buffer_->size()), event_data->GetSize()); | |
| 103 char* const event_data_buffer = event_data->GetBuffer(); | |
| 104 ASSERT_TRUE(event_data_buffer); | |
| 105 EXPECT_EQ(std::string(kWriteData), | |
| 106 std::string(event_data_buffer, event_data->GetSize())); | |
| 107 } | 93 } |
| 108 | 94 |
| 109 TEST_F(FileSystemProviderOperationsWriteFileTest, Execute_NoListener) { | 95 TEST_F(FileSystemProviderOperationsWriteFileTest, Execute_NoListener) { |
| 110 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); | 96 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); |
| 111 util::StatusCallbackLog callback_log; | 97 util::StatusCallbackLog callback_log; |
| 112 | 98 |
| 113 WriteFile write_file(NULL, | 99 WriteFile write_file(NULL, |
| 114 file_system_info_, | 100 file_system_info_, |
| 115 kFileHandle, | 101 kFileHandle, |
| 116 io_buffer_.get(), | 102 io_buffer_.get(), |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 scoped_ptr<RequestValue>(new RequestValue()), | 180 scoped_ptr<RequestValue>(new RequestValue()), |
| 195 base::File::FILE_ERROR_TOO_MANY_OPENED); | 181 base::File::FILE_ERROR_TOO_MANY_OPENED); |
| 196 | 182 |
| 197 ASSERT_EQ(1u, callback_log.size()); | 183 ASSERT_EQ(1u, callback_log.size()); |
| 198 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); | 184 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); |
| 199 } | 185 } |
| 200 | 186 |
| 201 } // namespace operations | 187 } // namespace operations |
| 202 } // namespace file_system_provider | 188 } // namespace file_system_provider |
| 203 } // namespace chromeos | 189 } // namespace chromeos |
| OLD | NEW |