| 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/close_file.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/close_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 30 matching lines...) Expand all Loading... |
| 41 kFileSystemId, | 41 kFileSystemId, |
| 42 "" /* display_name */, | 42 "" /* display_name */, |
| 43 false /* writable */, | 43 false /* writable */, |
| 44 base::FilePath() /* mount_path */); | 44 base::FilePath() /* mount_path */); |
| 45 } | 45 } |
| 46 | 46 |
| 47 ProvidedFileSystemInfo file_system_info_; | 47 ProvidedFileSystemInfo file_system_info_; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 TEST_F(FileSystemProviderOperationsCloseFileTest, Execute) { | 50 TEST_F(FileSystemProviderOperationsCloseFileTest, Execute) { |
| 51 using extensions::api::file_system_provider::CloseFileRequestedOptions; |
| 52 |
| 51 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 53 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 52 util::StatusCallbackLog callback_log; | 54 util::StatusCallbackLog callback_log; |
| 53 | 55 |
| 54 CloseFile close_file(NULL, | 56 CloseFile close_file(NULL, |
| 55 file_system_info_, | 57 file_system_info_, |
| 56 kOpenRequestId, | 58 kOpenRequestId, |
| 57 base::Bind(&util::LogStatusCallback, &callback_log)); | 59 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 58 close_file.SetDispatchEventImplForTesting( | 60 close_file.SetDispatchEventImplForTesting( |
| 59 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 61 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 60 base::Unretained(&dispatcher))); | 62 base::Unretained(&dispatcher))); |
| 61 | 63 |
| 62 EXPECT_TRUE(close_file.Execute(kRequestId)); | 64 EXPECT_TRUE(close_file.Execute(kRequestId)); |
| 63 | 65 |
| 64 ASSERT_EQ(1u, dispatcher.events().size()); | 66 ASSERT_EQ(1u, dispatcher.events().size()); |
| 65 extensions::Event* event = dispatcher.events()[0]; | 67 extensions::Event* event = dispatcher.events()[0]; |
| 66 EXPECT_EQ( | 68 EXPECT_EQ( |
| 67 extensions::api::file_system_provider::OnCloseFileRequested::kEventName, | 69 extensions::api::file_system_provider::OnCloseFileRequested::kEventName, |
| 68 event->event_name); | 70 event->event_name); |
| 69 base::ListValue* event_args = event->event_args.get(); | 71 base::ListValue* event_args = event->event_args.get(); |
| 70 ASSERT_EQ(1u, event_args->GetSize()); | 72 ASSERT_EQ(1u, event_args->GetSize()); |
| 71 | 73 |
| 72 base::DictionaryValue* options = NULL; | 74 const base::DictionaryValue* options_as_value = NULL; |
| 73 ASSERT_TRUE(event_args->GetDictionary(0, &options)); | 75 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); |
| 74 | 76 |
| 75 std::string event_file_system_id; | 77 CloseFileRequestedOptions options; |
| 76 EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id)); | 78 ASSERT_TRUE(CloseFileRequestedOptions::Populate(*options_as_value, &options)); |
| 77 EXPECT_EQ(kFileSystemId, event_file_system_id); | 79 EXPECT_EQ(kFileSystemId, options.file_system_id); |
| 78 | 80 EXPECT_EQ(kRequestId, options.request_id); |
| 79 int event_request_id = -1; | 81 EXPECT_EQ(kOpenRequestId, options.open_request_id); |
| 80 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); | |
| 81 EXPECT_EQ(kRequestId, event_request_id); | |
| 82 | |
| 83 int event_open_request_id = -1; | |
| 84 EXPECT_TRUE(options->GetInteger("openRequestId", &event_open_request_id)); | |
| 85 EXPECT_EQ(kOpenRequestId, event_open_request_id); | |
| 86 } | 82 } |
| 87 | 83 |
| 88 TEST_F(FileSystemProviderOperationsCloseFileTest, Execute_NoListener) { | 84 TEST_F(FileSystemProviderOperationsCloseFileTest, Execute_NoListener) { |
| 89 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); | 85 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); |
| 90 util::StatusCallbackLog callback_log; | 86 util::StatusCallbackLog callback_log; |
| 91 | 87 |
| 92 CloseFile close_file(NULL, | 88 CloseFile close_file(NULL, |
| 93 file_system_info_, | 89 file_system_info_, |
| 94 kOpenRequestId, | 90 kOpenRequestId, |
| 95 base::Bind(&util::LogStatusCallback, &callback_log)); | 91 base::Bind(&util::LogStatusCallback, &callback_log)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 close_file.OnError(kRequestId, | 134 close_file.OnError(kRequestId, |
| 139 scoped_ptr<RequestValue>(new RequestValue()), | 135 scoped_ptr<RequestValue>(new RequestValue()), |
| 140 base::File::FILE_ERROR_TOO_MANY_OPENED); | 136 base::File::FILE_ERROR_TOO_MANY_OPENED); |
| 141 ASSERT_EQ(1u, callback_log.size()); | 137 ASSERT_EQ(1u, callback_log.size()); |
| 142 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); | 138 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); |
| 143 } | 139 } |
| 144 | 140 |
| 145 } // namespace operations | 141 } // namespace operations |
| 146 } // namespace file_system_provider | 142 } // namespace file_system_provider |
| 147 } // namespace chromeos | 143 } // namespace chromeos |
| OLD | NEW |