| 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_directo
ry.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/create_directo
ry.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(FileSystemProviderOperationsCreateDirectoryTest, Execute) { | 51 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute) { |
| 52 using extensions::api::file_system_provider::CreateDirectoryRequestedOptions; |
| 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 CreateDirectory create_directory( | 57 CreateDirectory create_directory( |
| 56 NULL, | 58 NULL, |
| 57 file_system_info_, | 59 file_system_info_, |
| 58 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 60 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
| 59 true /* recursive */, | 61 true /* recursive */, |
| 60 base::Bind(&util::LogStatusCallback, &callback_log)); | 62 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 61 create_directory.SetDispatchEventImplForTesting( | 63 create_directory.SetDispatchEventImplForTesting( |
| 62 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 64 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 63 base::Unretained(&dispatcher))); | 65 base::Unretained(&dispatcher))); |
| 64 | 66 |
| 65 EXPECT_TRUE(create_directory.Execute(kRequestId)); | 67 EXPECT_TRUE(create_directory.Execute(kRequestId)); |
| 66 | 68 |
| 67 ASSERT_EQ(1u, dispatcher.events().size()); | 69 ASSERT_EQ(1u, dispatcher.events().size()); |
| 68 extensions::Event* event = dispatcher.events()[0]; | 70 extensions::Event* event = dispatcher.events()[0]; |
| 69 EXPECT_EQ(extensions::api::file_system_provider::OnCreateDirectoryRequested:: | 71 EXPECT_EQ(extensions::api::file_system_provider::OnCreateDirectoryRequested:: |
| 70 kEventName, | 72 kEventName, |
| 71 event->event_name); | 73 event->event_name); |
| 72 base::ListValue* event_args = event->event_args.get(); | 74 base::ListValue* event_args = event->event_args.get(); |
| 73 ASSERT_EQ(1u, event_args->GetSize()); | 75 ASSERT_EQ(1u, event_args->GetSize()); |
| 74 | 76 |
| 75 base::DictionaryValue* options = NULL; | 77 const base::DictionaryValue* options_as_value = NULL; |
| 76 ASSERT_TRUE(event_args->GetDictionary(0, &options)); | 78 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); |
| 77 | 79 |
| 78 std::string event_file_system_id; | 80 CreateDirectoryRequestedOptions options; |
| 79 EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id)); | 81 ASSERT_TRUE( |
| 80 EXPECT_EQ(kFileSystemId, event_file_system_id); | 82 CreateDirectoryRequestedOptions::Populate(*options_as_value, &options)); |
| 81 | 83 EXPECT_EQ(kFileSystemId, options.file_system_id); |
| 82 int event_request_id = -1; | 84 EXPECT_EQ(kRequestId, options.request_id); |
| 83 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); | 85 EXPECT_EQ(kDirectoryPath, options.directory_path); |
| 84 EXPECT_EQ(kRequestId, event_request_id); | 86 EXPECT_TRUE(options.recursive); |
| 85 | |
| 86 std::string event_directory_path; | |
| 87 EXPECT_TRUE(options->GetString("directoryPath", &event_directory_path)); | |
| 88 EXPECT_EQ(kDirectoryPath, event_directory_path); | |
| 89 | |
| 90 bool event_recursive; | |
| 91 EXPECT_TRUE(options->GetBoolean("recursive", &event_recursive)); | |
| 92 EXPECT_TRUE(event_recursive); | |
| 93 } | 87 } |
| 94 | 88 |
| 95 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute_NoListener) { | 89 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute_NoListener) { |
| 96 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); | 90 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); |
| 97 util::StatusCallbackLog callback_log; | 91 util::StatusCallbackLog callback_log; |
| 98 | 92 |
| 99 CreateDirectory create_directory( | 93 CreateDirectory create_directory( |
| 100 NULL, | 94 NULL, |
| 101 file_system_info_, | 95 file_system_info_, |
| 102 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 96 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 create_directory.OnError(kRequestId, | 169 create_directory.OnError(kRequestId, |
| 176 scoped_ptr<RequestValue>(new RequestValue()), | 170 scoped_ptr<RequestValue>(new RequestValue()), |
| 177 base::File::FILE_ERROR_TOO_MANY_OPENED); | 171 base::File::FILE_ERROR_TOO_MANY_OPENED); |
| 178 ASSERT_EQ(1u, callback_log.size()); | 172 ASSERT_EQ(1u, callback_log.size()); |
| 179 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); | 173 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); |
| 180 } | 174 } |
| 181 | 175 |
| 182 } // namespace operations | 176 } // namespace operations |
| 183 } // namespace file_system_provider | 177 } // namespace file_system_provider |
| 184 } // namespace chromeos | 178 } // namespace chromeos |
| OLD | NEW |