| 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/read_directory
.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/read_directory
.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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 kFileSystemId, | 85 kFileSystemId, |
| 86 "" /* display_name */, | 86 "" /* display_name */, |
| 87 false /* writable */, | 87 false /* writable */, |
| 88 base::FilePath() /* mount_path */); | 88 base::FilePath() /* mount_path */); |
| 89 } | 89 } |
| 90 | 90 |
| 91 ProvidedFileSystemInfo file_system_info_; | 91 ProvidedFileSystemInfo file_system_info_; |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 TEST_F(FileSystemProviderOperationsReadDirectoryTest, Execute) { | 94 TEST_F(FileSystemProviderOperationsReadDirectoryTest, Execute) { |
| 95 using extensions::api::file_system_provider::ReadDirectoryRequestedOptions; |
| 96 |
| 95 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 97 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 96 CallbackLogger callback_logger; | 98 CallbackLogger callback_logger; |
| 97 | 99 |
| 98 ReadDirectory read_directory(NULL, | 100 ReadDirectory read_directory(NULL, |
| 99 file_system_info_, | 101 file_system_info_, |
| 100 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 102 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
| 101 base::Bind(&CallbackLogger::OnReadDirectory, | 103 base::Bind(&CallbackLogger::OnReadDirectory, |
| 102 base::Unretained(&callback_logger))); | 104 base::Unretained(&callback_logger))); |
| 103 read_directory.SetDispatchEventImplForTesting( | 105 read_directory.SetDispatchEventImplForTesting( |
| 104 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 106 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 105 base::Unretained(&dispatcher))); | 107 base::Unretained(&dispatcher))); |
| 106 | 108 |
| 107 EXPECT_TRUE(read_directory.Execute(kRequestId)); | 109 EXPECT_TRUE(read_directory.Execute(kRequestId)); |
| 108 | 110 |
| 109 ASSERT_EQ(1u, dispatcher.events().size()); | 111 ASSERT_EQ(1u, dispatcher.events().size()); |
| 110 extensions::Event* event = dispatcher.events()[0]; | 112 extensions::Event* event = dispatcher.events()[0]; |
| 111 EXPECT_EQ(extensions::api::file_system_provider::OnReadDirectoryRequested:: | 113 EXPECT_EQ(extensions::api::file_system_provider::OnReadDirectoryRequested:: |
| 112 kEventName, | 114 kEventName, |
| 113 event->event_name); | 115 event->event_name); |
| 114 base::ListValue* event_args = event->event_args.get(); | 116 base::ListValue* event_args = event->event_args.get(); |
| 115 ASSERT_EQ(1u, event_args->GetSize()); | 117 ASSERT_EQ(1u, event_args->GetSize()); |
| 116 | 118 |
| 117 base::DictionaryValue* options = NULL; | 119 const base::DictionaryValue* options_as_value = NULL; |
| 118 ASSERT_TRUE(event_args->GetDictionary(0, &options)); | 120 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); |
| 119 | 121 |
| 120 std::string event_file_system_id; | 122 ReadDirectoryRequestedOptions options; |
| 121 EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id)); | 123 ASSERT_TRUE( |
| 122 EXPECT_EQ(kFileSystemId, event_file_system_id); | 124 ReadDirectoryRequestedOptions::Populate(*options_as_value, &options)); |
| 123 | 125 EXPECT_EQ(kFileSystemId, options.file_system_id); |
| 124 int event_request_id = -1; | 126 EXPECT_EQ(kRequestId, options.request_id); |
| 125 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); | 127 EXPECT_EQ(kDirectoryPath, options.directory_path); |
| 126 EXPECT_EQ(kRequestId, event_request_id); | |
| 127 | |
| 128 std::string event_directory_path; | |
| 129 EXPECT_TRUE(options->GetString("directoryPath", &event_directory_path)); | |
| 130 EXPECT_EQ(kDirectoryPath, event_directory_path); | |
| 131 } | 128 } |
| 132 | 129 |
| 133 TEST_F(FileSystemProviderOperationsReadDirectoryTest, Execute_NoListener) { | 130 TEST_F(FileSystemProviderOperationsReadDirectoryTest, Execute_NoListener) { |
| 134 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); | 131 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); |
| 135 CallbackLogger callback_logger; | 132 CallbackLogger callback_logger; |
| 136 | 133 |
| 137 ReadDirectory read_directory(NULL, | 134 ReadDirectory read_directory(NULL, |
| 138 file_system_info_, | 135 file_system_info_, |
| 139 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 136 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
| 140 base::Bind(&CallbackLogger::OnReadDirectory, | 137 base::Bind(&CallbackLogger::OnReadDirectory, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 235 |
| 239 ASSERT_EQ(1u, callback_logger.events().size()); | 236 ASSERT_EQ(1u, callback_logger.events().size()); |
| 240 CallbackLogger::Event* event = callback_logger.events()[0]; | 237 CallbackLogger::Event* event = callback_logger.events()[0]; |
| 241 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); | 238 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); |
| 242 ASSERT_EQ(0u, event->entry_list().size()); | 239 ASSERT_EQ(0u, event->entry_list().size()); |
| 243 } | 240 } |
| 244 | 241 |
| 245 } // namespace operations | 242 } // namespace operations |
| 246 } // namespace file_system_provider | 243 } // namespace file_system_provider |
| 247 } // namespace chromeos | 244 } // namespace chromeos |
| OLD | NEW |