Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: chrome/browser/chromeos/file_system_provider/operations/get_actions_unittest.cc

Issue 1239043002: Add support for actions for multiple file selection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Better documentation. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/get_actions.h" 5 #include "chrome/browser/chromeos/file_system_provider/operations/get_actions.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 11 matching lines...) Expand all
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 23
24 namespace chromeos { 24 namespace chromeos {
25 namespace file_system_provider { 25 namespace file_system_provider {
26 namespace operations { 26 namespace operations {
27 namespace { 27 namespace {
28 28
29 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; 29 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
30 const char kFileSystemId[] = "testing-file-system"; 30 const char kFileSystemId[] = "testing-file-system";
31 const int kRequestId = 2; 31 const int kRequestId = 2;
32 const base::FilePath::CharType kEntryPath[] = FILE_PATH_LITERAL("/directory"); 32 const base::FilePath::CharType kDirectoryPath[] =
33 FILE_PATH_LITERAL("/directory");
34 const base::FilePath::CharType kFilePath[] = FILE_PATH_LITERAL("/file");
33 35
34 // Callback invocation logger. Acts as a fileapi end-point. 36 // Callback invocation logger. Acts as a fileapi end-point.
35 class CallbackLogger { 37 class CallbackLogger {
36 public: 38 public:
37 class Event { 39 class Event {
38 public: 40 public:
39 Event(const Actions& actions, base::File::Error result) 41 Event(const Actions& actions, base::File::Error result)
40 : actions_(actions), result_(result) {} 42 : actions_(actions), result_(result) {}
41 virtual ~Event() {} 43 virtual ~Event() {}
42 44
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 class FileSystemProviderOperationsGetActionsTest : public testing::Test { 92 class FileSystemProviderOperationsGetActionsTest : public testing::Test {
91 protected: 93 protected:
92 FileSystemProviderOperationsGetActionsTest() {} 94 FileSystemProviderOperationsGetActionsTest() {}
93 ~FileSystemProviderOperationsGetActionsTest() override {} 95 ~FileSystemProviderOperationsGetActionsTest() override {}
94 96
95 void SetUp() override { 97 void SetUp() override {
96 file_system_info_ = ProvidedFileSystemInfo( 98 file_system_info_ = ProvidedFileSystemInfo(
97 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */), 99 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */),
98 base::FilePath(), false /* configurable */, true /* watchable */, 100 base::FilePath(), false /* configurable */, true /* watchable */,
99 extensions::SOURCE_FILE); 101 extensions::SOURCE_FILE);
102 entry_paths_.clear();
103 entry_paths_.insert(base::FilePath(kDirectoryPath));
104 entry_paths_.insert(base::FilePath(kFilePath));
100 } 105 }
101 106
102 ProvidedFileSystemInfo file_system_info_; 107 ProvidedFileSystemInfo file_system_info_;
108 std::set<base::FilePath> entry_paths_;
103 }; 109 };
104 110
105 TEST_F(FileSystemProviderOperationsGetActionsTest, Execute) { 111 TEST_F(FileSystemProviderOperationsGetActionsTest, Execute) {
106 using extensions::api::file_system_provider::GetActionsRequestedOptions; 112 using extensions::api::file_system_provider::GetActionsRequestedOptions;
107 113
108 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 114 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
109 CallbackLogger callback_logger; 115 CallbackLogger callback_logger;
110 116
111 GetActions get_actions(NULL, file_system_info_, base::FilePath(kEntryPath), 117 GetActions get_actions(NULL, file_system_info_, entry_paths_,
112 base::Bind(&CallbackLogger::OnGetActions, 118 base::Bind(&CallbackLogger::OnGetActions,
113 base::Unretained(&callback_logger))); 119 base::Unretained(&callback_logger)));
114 get_actions.SetDispatchEventImplForTesting( 120 get_actions.SetDispatchEventImplForTesting(
115 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 121 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
116 base::Unretained(&dispatcher))); 122 base::Unretained(&dispatcher)));
117 123
118 EXPECT_TRUE(get_actions.Execute(kRequestId)); 124 EXPECT_TRUE(get_actions.Execute(kRequestId));
119 125
120 ASSERT_EQ(1u, dispatcher.events().size()); 126 ASSERT_EQ(1u, dispatcher.events().size());
121 extensions::Event* event = dispatcher.events()[0]; 127 extensions::Event* event = dispatcher.events()[0];
122 EXPECT_EQ( 128 EXPECT_EQ(
123 extensions::api::file_system_provider::OnGetActionsRequested::kEventName, 129 extensions::api::file_system_provider::OnGetActionsRequested::kEventName,
124 event->event_name); 130 event->event_name);
125 base::ListValue* event_args = event->event_args.get(); 131 base::ListValue* event_args = event->event_args.get();
126 ASSERT_EQ(1u, event_args->GetSize()); 132 ASSERT_EQ(1u, event_args->GetSize());
127 133
128 const base::DictionaryValue* options_as_value = NULL; 134 const base::DictionaryValue* options_as_value = NULL;
129 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); 135 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
130 136
131 GetActionsRequestedOptions options; 137 GetActionsRequestedOptions options;
132 ASSERT_TRUE( 138 ASSERT_TRUE(
133 GetActionsRequestedOptions::Populate(*options_as_value, &options)); 139 GetActionsRequestedOptions::Populate(*options_as_value, &options));
134 EXPECT_EQ(kFileSystemId, options.file_system_id); 140 EXPECT_EQ(kFileSystemId, options.file_system_id);
135 EXPECT_EQ(kRequestId, options.request_id); 141 EXPECT_EQ(kRequestId, options.request_id);
136 EXPECT_EQ(kEntryPath, options.entry_path); 142 ASSERT_EQ(entry_paths_.size(), options.entry_paths.size());
143 EXPECT_EQ(1u, entry_paths_.count(base::FilePath(options.entry_paths[0])));
144 EXPECT_EQ(1u, entry_paths_.count(base::FilePath(options.entry_paths[1])));
137 } 145 }
138 146
139 TEST_F(FileSystemProviderOperationsGetActionsTest, Execute_NoListener) { 147 TEST_F(FileSystemProviderOperationsGetActionsTest, Execute_NoListener) {
140 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); 148 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
141 CallbackLogger callback_logger; 149 CallbackLogger callback_logger;
142 150
143 GetActions get_actions(NULL, file_system_info_, base::FilePath(kEntryPath), 151 GetActions get_actions(NULL, file_system_info_, entry_paths_,
144 base::Bind(&CallbackLogger::OnGetActions, 152 base::Bind(&CallbackLogger::OnGetActions,
145 base::Unretained(&callback_logger))); 153 base::Unretained(&callback_logger)));
146 get_actions.SetDispatchEventImplForTesting( 154 get_actions.SetDispatchEventImplForTesting(
147 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 155 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
148 base::Unretained(&dispatcher))); 156 base::Unretained(&dispatcher)));
149 157
150 EXPECT_FALSE(get_actions.Execute(kRequestId)); 158 EXPECT_FALSE(get_actions.Execute(kRequestId));
151 } 159 }
152 160
153 TEST_F(FileSystemProviderOperationsGetActionsTest, OnSuccess) { 161 TEST_F(FileSystemProviderOperationsGetActionsTest, OnSuccess) {
154 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 162 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
155 CallbackLogger callback_logger; 163 CallbackLogger callback_logger;
156 164
157 GetActions get_actions(NULL, file_system_info_, base::FilePath(kEntryPath), 165 GetActions get_actions(NULL, file_system_info_, entry_paths_,
158 base::Bind(&CallbackLogger::OnGetActions, 166 base::Bind(&CallbackLogger::OnGetActions,
159 base::Unretained(&callback_logger))); 167 base::Unretained(&callback_logger)));
160 get_actions.SetDispatchEventImplForTesting( 168 get_actions.SetDispatchEventImplForTesting(
161 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 169 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
162 base::Unretained(&dispatcher))); 170 base::Unretained(&dispatcher)));
163 171
164 EXPECT_TRUE(get_actions.Execute(kRequestId)); 172 EXPECT_TRUE(get_actions.Execute(kRequestId));
165 173
166 // Sample input as JSON. Keep in sync with file_system_provider_api.idl. 174 // Sample input as JSON. Keep in sync with file_system_provider_api.idl.
167 // As for now, it is impossible to create *::Params class directly, not from 175 // As for now, it is impossible to create *::Params class directly, not from
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 214
207 const Action action_custom = event->actions()[2]; 215 const Action action_custom = event->actions()[2];
208 EXPECT_EQ("SomeCustomActionId", action_custom.id); 216 EXPECT_EQ("SomeCustomActionId", action_custom.id);
209 EXPECT_EQ("Custom action.", action_custom.title); 217 EXPECT_EQ("Custom action.", action_custom.title);
210 } 218 }
211 219
212 TEST_F(FileSystemProviderOperationsGetActionsTest, OnError) { 220 TEST_F(FileSystemProviderOperationsGetActionsTest, OnError) {
213 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 221 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
214 CallbackLogger callback_logger; 222 CallbackLogger callback_logger;
215 223
216 GetActions get_actions(NULL, file_system_info_, base::FilePath(kEntryPath), 224 GetActions get_actions(NULL, file_system_info_, entry_paths_,
217 base::Bind(&CallbackLogger::OnGetActions, 225 base::Bind(&CallbackLogger::OnGetActions,
218 base::Unretained(&callback_logger))); 226 base::Unretained(&callback_logger)));
219 get_actions.SetDispatchEventImplForTesting( 227 get_actions.SetDispatchEventImplForTesting(
220 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 228 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
221 base::Unretained(&dispatcher))); 229 base::Unretained(&dispatcher)));
222 230
223 EXPECT_TRUE(get_actions.Execute(kRequestId)); 231 EXPECT_TRUE(get_actions.Execute(kRequestId));
224 232
225 get_actions.OnError(kRequestId, scoped_ptr<RequestValue>(new RequestValue()), 233 get_actions.OnError(kRequestId, scoped_ptr<RequestValue>(new RequestValue()),
226 base::File::FILE_ERROR_TOO_MANY_OPENED); 234 base::File::FILE_ERROR_TOO_MANY_OPENED);
227 235
228 ASSERT_EQ(1u, callback_logger.events().size()); 236 ASSERT_EQ(1u, callback_logger.events().size());
229 CallbackLogger::Event* event = callback_logger.events()[0]; 237 CallbackLogger::Event* event = callback_logger.events()[0];
230 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); 238 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result());
231 ASSERT_EQ(0u, event->actions().size()); 239 ASSERT_EQ(0u, event->actions().size());
232 } 240 }
233 241
234 } // namespace operations 242 } // namespace operations
235 } // namespace file_system_provider 243 } // namespace file_system_provider
236 } // namespace chromeos 244 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698