| 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/abort.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/abort.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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 ProvidedFileSystemInfo file_system_info_; | 46 ProvidedFileSystemInfo file_system_info_; |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 TEST_F(FileSystemProviderOperationsAbortTest, Execute) { | 49 TEST_F(FileSystemProviderOperationsAbortTest, Execute) { |
| 50 using extensions::api::file_system_provider::AbortRequestedOptions; | 50 using extensions::api::file_system_provider::AbortRequestedOptions; |
| 51 | 51 |
| 52 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 52 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 53 util::StatusCallbackLog callback_log; | 53 util::StatusCallbackLog callback_log; |
| 54 | 54 |
| 55 Abort abort(NULL, | 55 Abort<> abort(NULL, file_system_info_, kOperationRequestId, |
| 56 file_system_info_, | 56 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 57 kOperationRequestId, | |
| 58 base::Bind(&util::LogStatusCallback, &callback_log)); | |
| 59 abort.SetDispatchEventImplForTesting( | 57 abort.SetDispatchEventImplForTesting( |
| 60 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 58 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 61 base::Unretained(&dispatcher))); | 59 base::Unretained(&dispatcher))); |
| 62 | 60 |
| 63 EXPECT_TRUE(abort.Execute(kRequestId)); | 61 EXPECT_TRUE(abort.Execute(kRequestId)); |
| 64 | 62 |
| 65 ASSERT_EQ(1u, dispatcher.events().size()); | 63 ASSERT_EQ(1u, dispatcher.events().size()); |
| 66 extensions::Event* event = dispatcher.events()[0]; | 64 extensions::Event* event = dispatcher.events()[0]; |
| 67 EXPECT_EQ(extensions::api::file_system_provider::OnAbortRequested::kEventName, | 65 EXPECT_EQ(extensions::api::file_system_provider::OnAbortRequested::kEventName, |
| 68 event->event_name); | 66 event->event_name); |
| 69 base::ListValue* event_args = event->event_args.get(); | 67 base::ListValue* event_args = event->event_args.get(); |
| 70 ASSERT_EQ(1u, event_args->GetSize()); | 68 ASSERT_EQ(1u, event_args->GetSize()); |
| 71 | 69 |
| 72 const base::DictionaryValue* options_as_value = NULL; | 70 const base::DictionaryValue* options_as_value = NULL; |
| 73 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); | 71 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); |
| 74 | 72 |
| 75 AbortRequestedOptions options; | 73 AbortRequestedOptions options; |
| 76 ASSERT_TRUE(AbortRequestedOptions::Populate(*options_as_value, &options)); | 74 ASSERT_TRUE(AbortRequestedOptions::Populate(*options_as_value, &options)); |
| 77 EXPECT_EQ(kFileSystemId, options.file_system_id); | 75 EXPECT_EQ(kFileSystemId, options.file_system_id); |
| 78 EXPECT_EQ(kRequestId, options.request_id); | 76 EXPECT_EQ(kRequestId, options.request_id); |
| 79 EXPECT_EQ(kOperationRequestId, options.operation_request_id); | 77 EXPECT_EQ(kOperationRequestId, options.operation_request_id); |
| 80 } | 78 } |
| 81 | 79 |
| 82 TEST_F(FileSystemProviderOperationsAbortTest, Execute_NoListener) { | 80 TEST_F(FileSystemProviderOperationsAbortTest, Execute_NoListener) { |
| 83 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); | 81 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); |
| 84 util::StatusCallbackLog callback_log; | 82 util::StatusCallbackLog callback_log; |
| 85 | 83 |
| 86 Abort abort(NULL, | 84 Abort<> abort(NULL, file_system_info_, kOperationRequestId, |
| 87 file_system_info_, | 85 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 88 kOperationRequestId, | |
| 89 base::Bind(&util::LogStatusCallback, &callback_log)); | |
| 90 abort.SetDispatchEventImplForTesting( | 86 abort.SetDispatchEventImplForTesting( |
| 91 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 87 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 92 base::Unretained(&dispatcher))); | 88 base::Unretained(&dispatcher))); |
| 93 | 89 |
| 94 EXPECT_FALSE(abort.Execute(kRequestId)); | 90 EXPECT_FALSE(abort.Execute(kRequestId)); |
| 95 } | 91 } |
| 96 | 92 |
| 97 TEST_F(FileSystemProviderOperationsAbortTest, OnSuccess) { | 93 TEST_F(FileSystemProviderOperationsAbortTest, OnSuccess) { |
| 98 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 94 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 99 util::StatusCallbackLog callback_log; | 95 util::StatusCallbackLog callback_log; |
| 100 | 96 |
| 101 Abort abort(NULL, | 97 Abort<> abort(NULL, file_system_info_, kOperationRequestId, |
| 102 file_system_info_, | 98 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 103 kOperationRequestId, | |
| 104 base::Bind(&util::LogStatusCallback, &callback_log)); | |
| 105 abort.SetDispatchEventImplForTesting( | 99 abort.SetDispatchEventImplForTesting( |
| 106 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 100 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 107 base::Unretained(&dispatcher))); | 101 base::Unretained(&dispatcher))); |
| 108 | 102 |
| 109 EXPECT_TRUE(abort.Execute(kRequestId)); | 103 EXPECT_TRUE(abort.Execute(kRequestId)); |
| 110 | 104 |
| 111 abort.OnSuccess(kRequestId, | 105 abort.OnSuccess(kRequestId, |
| 112 scoped_ptr<RequestValue>(new RequestValue()), | 106 scoped_ptr<RequestValue>(new RequestValue()), |
| 113 false /* has_more */); | 107 false /* has_more */); |
| 114 ASSERT_EQ(1u, callback_log.size()); | 108 ASSERT_EQ(1u, callback_log.size()); |
| 115 EXPECT_EQ(base::File::FILE_OK, callback_log[0]); | 109 EXPECT_EQ(base::File::FILE_OK, callback_log[0]); |
| 116 } | 110 } |
| 117 | 111 |
| 118 TEST_F(FileSystemProviderOperationsAbortTest, OnError) { | 112 TEST_F(FileSystemProviderOperationsAbortTest, OnError) { |
| 119 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 113 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 120 util::StatusCallbackLog callback_log; | 114 util::StatusCallbackLog callback_log; |
| 121 | 115 |
| 122 Abort abort(NULL, | 116 Abort<> abort(NULL, file_system_info_, kOperationRequestId, |
| 123 file_system_info_, | 117 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 124 kOperationRequestId, | |
| 125 base::Bind(&util::LogStatusCallback, &callback_log)); | |
| 126 abort.SetDispatchEventImplForTesting( | 118 abort.SetDispatchEventImplForTesting( |
| 127 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 119 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 128 base::Unretained(&dispatcher))); | 120 base::Unretained(&dispatcher))); |
| 129 | 121 |
| 130 EXPECT_TRUE(abort.Execute(kRequestId)); | 122 EXPECT_TRUE(abort.Execute(kRequestId)); |
| 131 | 123 |
| 132 abort.OnError(kRequestId, | 124 abort.OnError(kRequestId, |
| 133 scoped_ptr<RequestValue>(new RequestValue()), | 125 scoped_ptr<RequestValue>(new RequestValue()), |
| 134 base::File::FILE_ERROR_TOO_MANY_OPENED); | 126 base::File::FILE_ERROR_TOO_MANY_OPENED); |
| 135 ASSERT_EQ(1u, callback_log.size()); | 127 ASSERT_EQ(1u, callback_log.size()); |
| 136 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); | 128 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); |
| 137 } | 129 } |
| 138 | 130 |
| 139 } // namespace operations | 131 } // namespace operations |
| 140 } // namespace file_system_provider | 132 } // namespace file_system_provider |
| 141 } // namespace chromeos | 133 } // namespace chromeos |
| OLD | NEW |