| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/execute_action
.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/execute_action
.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 10 matching lines...) Expand all Loading... |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 22 |
| 23 namespace chromeos { | 23 namespace chromeos { |
| 24 namespace file_system_provider { | 24 namespace file_system_provider { |
| 25 namespace operations { | 25 namespace operations { |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; | 28 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; |
| 29 const char kFileSystemId[] = "testing-file-system"; | 29 const char kFileSystemId[] = "testing-file-system"; |
| 30 const int kRequestId = 2; | 30 const int kRequestId = 2; |
| 31 const base::FilePath::CharType kEntryPath[] = | 31 const base::FilePath::CharType kDirectoryPath[] = |
| 32 FILE_PATH_LITERAL("/kitty/and/puppy/happy"); | 32 FILE_PATH_LITERAL("/kitty/and/puppy/happy"); |
| 33 const base::FilePath::CharType kFilePath[] = |
| 34 FILE_PATH_LITERAL("/rabbit/and/bear/happy"); |
| 33 const char kActionId[] = "SHARE"; | 35 const char kActionId[] = "SHARE"; |
| 34 | 36 |
| 35 } // namespace | 37 } // namespace |
| 36 | 38 |
| 37 class FileSystemProviderOperationsExecuteActionTest : public testing::Test { | 39 class FileSystemProviderOperationsExecuteActionTest : public testing::Test { |
| 38 protected: | 40 protected: |
| 39 FileSystemProviderOperationsExecuteActionTest() {} | 41 FileSystemProviderOperationsExecuteActionTest() {} |
| 40 ~FileSystemProviderOperationsExecuteActionTest() override {} | 42 ~FileSystemProviderOperationsExecuteActionTest() override {} |
| 41 | 43 |
| 42 void SetUp() override { | 44 void SetUp() override { |
| 43 file_system_info_ = ProvidedFileSystemInfo( | 45 file_system_info_ = ProvidedFileSystemInfo( |
| 44 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */), | 46 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */), |
| 45 base::FilePath(), false /* configurable */, true /* watchable */, | 47 base::FilePath(), false /* configurable */, true /* watchable */, |
| 46 extensions::SOURCE_FILE); | 48 extensions::SOURCE_FILE); |
| 49 entry_paths_.clear(); |
| 50 entry_paths_.insert(base::FilePath(kDirectoryPath)); |
| 51 entry_paths_.insert(base::FilePath(kFilePath)); |
| 47 } | 52 } |
| 48 | 53 |
| 49 ProvidedFileSystemInfo file_system_info_; | 54 ProvidedFileSystemInfo file_system_info_; |
| 55 std::set<base::FilePath> entry_paths_; |
| 50 }; | 56 }; |
| 51 | 57 |
| 52 TEST_F(FileSystemProviderOperationsExecuteActionTest, Execute) { | 58 TEST_F(FileSystemProviderOperationsExecuteActionTest, Execute) { |
| 53 using extensions::api::file_system_provider::ExecuteActionRequestedOptions; | 59 using extensions::api::file_system_provider::ExecuteActionRequestedOptions; |
| 54 | 60 |
| 55 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 61 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 56 util::StatusCallbackLog callback_log; | 62 util::StatusCallbackLog callback_log; |
| 57 | 63 |
| 58 ExecuteAction execute_action( | 64 ExecuteAction execute_action( |
| 59 NULL, file_system_info_, base::FilePath(kEntryPath), kActionId, | 65 NULL, file_system_info_, entry_paths_, kActionId, |
| 60 base::Bind(&util::LogStatusCallback, &callback_log)); | 66 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 61 execute_action.SetDispatchEventImplForTesting( | 67 execute_action.SetDispatchEventImplForTesting( |
| 62 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 68 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 63 base::Unretained(&dispatcher))); | 69 base::Unretained(&dispatcher))); |
| 64 | 70 |
| 65 EXPECT_TRUE(execute_action.Execute(kRequestId)); | 71 EXPECT_TRUE(execute_action.Execute(kRequestId)); |
| 66 | 72 |
| 67 ASSERT_EQ(1u, dispatcher.events().size()); | 73 ASSERT_EQ(1u, dispatcher.events().size()); |
| 68 extensions::Event* event = dispatcher.events()[0]; | 74 extensions::Event* event = dispatcher.events()[0]; |
| 69 EXPECT_EQ(extensions::api::file_system_provider::OnExecuteActionRequested:: | 75 EXPECT_EQ(extensions::api::file_system_provider::OnExecuteActionRequested:: |
| 70 kEventName, | 76 kEventName, |
| 71 event->event_name); | 77 event->event_name); |
| 72 base::ListValue* event_args = event->event_args.get(); | 78 base::ListValue* event_args = event->event_args.get(); |
| 73 ASSERT_EQ(1u, event_args->GetSize()); | 79 ASSERT_EQ(1u, event_args->GetSize()); |
| 74 | 80 |
| 75 const base::DictionaryValue* options_as_value = NULL; | 81 const base::DictionaryValue* options_as_value = NULL; |
| 76 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); | 82 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); |
| 77 | 83 |
| 78 ExecuteActionRequestedOptions options; | 84 ExecuteActionRequestedOptions options; |
| 79 ASSERT_TRUE( | 85 ASSERT_TRUE( |
| 80 ExecuteActionRequestedOptions::Populate(*options_as_value, &options)); | 86 ExecuteActionRequestedOptions::Populate(*options_as_value, &options)); |
| 81 EXPECT_EQ(kFileSystemId, options.file_system_id); | 87 EXPECT_EQ(kFileSystemId, options.file_system_id); |
| 82 EXPECT_EQ(kRequestId, options.request_id); | 88 EXPECT_EQ(kRequestId, options.request_id); |
| 83 EXPECT_EQ(kEntryPath, options.entry_path); | 89 ASSERT_EQ(entry_paths_.size(), options.entry_paths.size()); |
| 90 EXPECT_EQ(1u, entry_paths_.count(base::FilePath(options.entry_paths[0]))); |
| 91 EXPECT_EQ(1u, entry_paths_.count(base::FilePath(options.entry_paths[1]))); |
| 84 EXPECT_EQ(kActionId, options.action_id); | 92 EXPECT_EQ(kActionId, options.action_id); |
| 85 } | 93 } |
| 86 | 94 |
| 87 TEST_F(FileSystemProviderOperationsExecuteActionTest, Execute_NoListener) { | 95 TEST_F(FileSystemProviderOperationsExecuteActionTest, Execute_NoListener) { |
| 88 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); | 96 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); |
| 89 util::StatusCallbackLog callback_log; | 97 util::StatusCallbackLog callback_log; |
| 90 | 98 |
| 91 ExecuteAction execute_action( | 99 ExecuteAction execute_action( |
| 92 NULL, file_system_info_, base::FilePath(kEntryPath), kActionId, | 100 NULL, file_system_info_, entry_paths_, kActionId, |
| 93 base::Bind(&util::LogStatusCallback, &callback_log)); | 101 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 94 execute_action.SetDispatchEventImplForTesting( | 102 execute_action.SetDispatchEventImplForTesting( |
| 95 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 103 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 96 base::Unretained(&dispatcher))); | 104 base::Unretained(&dispatcher))); |
| 97 | 105 |
| 98 EXPECT_FALSE(execute_action.Execute(kRequestId)); | 106 EXPECT_FALSE(execute_action.Execute(kRequestId)); |
| 99 } | 107 } |
| 100 | 108 |
| 101 TEST_F(FileSystemProviderOperationsExecuteActionTest, OnSuccess) { | 109 TEST_F(FileSystemProviderOperationsExecuteActionTest, OnSuccess) { |
| 102 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 110 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 103 util::StatusCallbackLog callback_log; | 111 util::StatusCallbackLog callback_log; |
| 104 | 112 |
| 105 ExecuteAction execute_action( | 113 ExecuteAction execute_action( |
| 106 NULL, file_system_info_, base::FilePath(kEntryPath), kActionId, | 114 NULL, file_system_info_, entry_paths_, kActionId, |
| 107 base::Bind(&util::LogStatusCallback, &callback_log)); | 115 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 108 execute_action.SetDispatchEventImplForTesting( | 116 execute_action.SetDispatchEventImplForTesting( |
| 109 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 117 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 110 base::Unretained(&dispatcher))); | 118 base::Unretained(&dispatcher))); |
| 111 | 119 |
| 112 EXPECT_TRUE(execute_action.Execute(kRequestId)); | 120 EXPECT_TRUE(execute_action.Execute(kRequestId)); |
| 113 | 121 |
| 114 execute_action.OnSuccess(kRequestId, | 122 execute_action.OnSuccess(kRequestId, |
| 115 scoped_ptr<RequestValue>(new RequestValue()), | 123 scoped_ptr<RequestValue>(new RequestValue()), |
| 116 false /* has_more */); | 124 false /* has_more */); |
| 117 ASSERT_EQ(1u, callback_log.size()); | 125 ASSERT_EQ(1u, callback_log.size()); |
| 118 EXPECT_EQ(base::File::FILE_OK, callback_log[0]); | 126 EXPECT_EQ(base::File::FILE_OK, callback_log[0]); |
| 119 } | 127 } |
| 120 | 128 |
| 121 TEST_F(FileSystemProviderOperationsExecuteActionTest, OnError) { | 129 TEST_F(FileSystemProviderOperationsExecuteActionTest, OnError) { |
| 122 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 130 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 123 util::StatusCallbackLog callback_log; | 131 util::StatusCallbackLog callback_log; |
| 124 | 132 |
| 125 ExecuteAction execute_action( | 133 ExecuteAction execute_action( |
| 126 NULL, file_system_info_, base::FilePath(kEntryPath), kActionId, | 134 NULL, file_system_info_, entry_paths_, kActionId, |
| 127 base::Bind(&util::LogStatusCallback, &callback_log)); | 135 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 128 execute_action.SetDispatchEventImplForTesting( | 136 execute_action.SetDispatchEventImplForTesting( |
| 129 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 137 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 130 base::Unretained(&dispatcher))); | 138 base::Unretained(&dispatcher))); |
| 131 | 139 |
| 132 EXPECT_TRUE(execute_action.Execute(kRequestId)); | 140 EXPECT_TRUE(execute_action.Execute(kRequestId)); |
| 133 | 141 |
| 134 execute_action.OnError(kRequestId, | 142 execute_action.OnError(kRequestId, |
| 135 scoped_ptr<RequestValue>(new RequestValue()), | 143 scoped_ptr<RequestValue>(new RequestValue()), |
| 136 base::File::FILE_ERROR_TOO_MANY_OPENED); | 144 base::File::FILE_ERROR_TOO_MANY_OPENED); |
| 137 ASSERT_EQ(1u, callback_log.size()); | 145 ASSERT_EQ(1u, callback_log.size()); |
| 138 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); | 146 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); |
| 139 } | 147 } |
| 140 | 148 |
| 141 } // namespace operations | 149 } // namespace operations |
| 142 } // namespace file_system_provider | 150 } // namespace file_system_provider |
| 143 } // namespace chromeos | 151 } // namespace chromeos |
| OLD | NEW |