| 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/create_file.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/create_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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 kFileSystemId, | 42 kFileSystemId, |
| 43 "" /* file_system_name */, | 43 "" /* file_system_name */, |
| 44 true /* writable */, | 44 true /* writable */, |
| 45 base::FilePath() /* mount_path */); | 45 base::FilePath() /* mount_path */); |
| 46 } | 46 } |
| 47 | 47 |
| 48 ProvidedFileSystemInfo file_system_info_; | 48 ProvidedFileSystemInfo file_system_info_; |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 TEST_F(FileSystemProviderOperationsCreateFileTest, Execute) { | 51 TEST_F(FileSystemProviderOperationsCreateFileTest, Execute) { |
| 52 using extensions::api::file_system_provider::CreateFileRequestedOptions; |
| 53 |
| 52 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 54 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 53 util::StatusCallbackLog callback_log; | 55 util::StatusCallbackLog callback_log; |
| 54 | 56 |
| 55 CreateFile create_file(NULL, | 57 CreateFile create_file(NULL, |
| 56 file_system_info_, | 58 file_system_info_, |
| 57 base::FilePath::FromUTF8Unsafe(kFilePath), | 59 base::FilePath::FromUTF8Unsafe(kFilePath), |
| 58 base::Bind(&util::LogStatusCallback, &callback_log)); | 60 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 59 create_file.SetDispatchEventImplForTesting( | 61 create_file.SetDispatchEventImplForTesting( |
| 60 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 62 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 61 base::Unretained(&dispatcher))); | 63 base::Unretained(&dispatcher))); |
| 62 | 64 |
| 63 EXPECT_TRUE(create_file.Execute(kRequestId)); | 65 EXPECT_TRUE(create_file.Execute(kRequestId)); |
| 64 | 66 |
| 65 ASSERT_EQ(1u, dispatcher.events().size()); | 67 ASSERT_EQ(1u, dispatcher.events().size()); |
| 66 extensions::Event* event = dispatcher.events()[0]; | 68 extensions::Event* event = dispatcher.events()[0]; |
| 67 EXPECT_EQ( | 69 EXPECT_EQ( |
| 68 extensions::api::file_system_provider::OnCreateFileRequested::kEventName, | 70 extensions::api::file_system_provider::OnCreateFileRequested::kEventName, |
| 69 event->event_name); | 71 event->event_name); |
| 70 base::ListValue* event_args = event->event_args.get(); | 72 base::ListValue* event_args = event->event_args.get(); |
| 71 ASSERT_EQ(1u, event_args->GetSize()); | 73 ASSERT_EQ(1u, event_args->GetSize()); |
| 72 | 74 |
| 73 base::DictionaryValue* options = NULL; | 75 const base::DictionaryValue* options_as_value = NULL; |
| 74 ASSERT_TRUE(event_args->GetDictionary(0, &options)); | 76 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); |
| 75 | 77 |
| 76 std::string event_file_system_id; | 78 CreateFileRequestedOptions options; |
| 77 EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id)); | 79 ASSERT_TRUE( |
| 78 EXPECT_EQ(kFileSystemId, event_file_system_id); | 80 CreateFileRequestedOptions::Populate(*options_as_value, &options)); |
| 79 | 81 EXPECT_EQ(kFileSystemId, options.file_system_id); |
| 80 int event_request_id = -1; | 82 EXPECT_EQ(kRequestId, options.request_id); |
| 81 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); | 83 EXPECT_EQ(kFilePath, options.file_path); |
| 82 EXPECT_EQ(kRequestId, event_request_id); | |
| 83 | |
| 84 std::string event_file_path; | |
| 85 EXPECT_TRUE(options->GetString("filePath", &event_file_path)); | |
| 86 EXPECT_EQ(kFilePath, event_file_path); | |
| 87 } | 84 } |
| 88 | 85 |
| 89 TEST_F(FileSystemProviderOperationsCreateFileTest, Execute_NoListener) { | 86 TEST_F(FileSystemProviderOperationsCreateFileTest, Execute_NoListener) { |
| 90 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); | 87 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); |
| 91 util::StatusCallbackLog callback_log; | 88 util::StatusCallbackLog callback_log; |
| 92 | 89 |
| 93 CreateFile create_file(NULL, | 90 CreateFile create_file(NULL, |
| 94 file_system_info_, | 91 file_system_info_, |
| 95 base::FilePath::FromUTF8Unsafe(kFilePath), | 92 base::FilePath::FromUTF8Unsafe(kFilePath), |
| 96 base::Bind(&util::LogStatusCallback, &callback_log)); | 93 base::Bind(&util::LogStatusCallback, &callback_log)); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 create_file.OnError(kRequestId, | 158 create_file.OnError(kRequestId, |
| 162 scoped_ptr<RequestValue>(new RequestValue()), | 159 scoped_ptr<RequestValue>(new RequestValue()), |
| 163 base::File::FILE_ERROR_TOO_MANY_OPENED); | 160 base::File::FILE_ERROR_TOO_MANY_OPENED); |
| 164 ASSERT_EQ(1u, callback_log.size()); | 161 ASSERT_EQ(1u, callback_log.size()); |
| 165 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); | 162 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); |
| 166 } | 163 } |
| 167 | 164 |
| 168 } // namespace operations | 165 } // namespace operations |
| 169 } // namespace file_system_provider | 166 } // namespace file_system_provider |
| 170 } // namespace chromeos | 167 } // namespace chromeos |
| OLD | NEW |