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