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

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: Fixed externs. Created 5 years, 3 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 #include <vector>
8 9
9 #include "base/files/file.h" 10 #include "base/files/file.h"
10 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
11 #include "base/json/json_reader.h" 12 #include "base/json/json_reader.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h" 14 #include "base/memory/scoped_vector.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h " 16 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h "
16 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" 17 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h"
17 #include "chrome/common/extensions/api/file_system_provider.h" 18 #include "chrome/common/extensions/api/file_system_provider.h"
18 #include "chrome/common/extensions/api/file_system_provider_capabilities/file_sy stem_provider_capabilities_handler.h" 19 #include "chrome/common/extensions/api/file_system_provider_capabilities/file_sy stem_provider_capabilities_handler.h"
19 #include "chrome/common/extensions/api/file_system_provider_internal.h" 20 #include "chrome/common/extensions/api/file_system_provider_internal.h"
20 #include "extensions/browser/event_router.h" 21 #include "extensions/browser/event_router.h"
21 #include "storage/browser/fileapi/async_file_util.h" 22 #include "storage/browser/fileapi/async_file_util.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 24
24 namespace chromeos { 25 namespace chromeos {
25 namespace file_system_provider { 26 namespace file_system_provider {
26 namespace operations { 27 namespace operations {
27 namespace { 28 namespace {
28 29
29 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; 30 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
30 const char kFileSystemId[] = "testing-file-system"; 31 const char kFileSystemId[] = "testing-file-system";
31 const int kRequestId = 2; 32 const int kRequestId = 2;
32 const base::FilePath::CharType kEntryPath[] = FILE_PATH_LITERAL("/directory"); 33 const base::FilePath::CharType kDirectoryPath[] =
34 FILE_PATH_LITERAL("/directory");
35 const base::FilePath::CharType kFilePath[] = FILE_PATH_LITERAL("/file");
33 36
34 // Callback invocation logger. Acts as a fileapi end-point. 37 // Callback invocation logger. Acts as a fileapi end-point.
35 class CallbackLogger { 38 class CallbackLogger {
36 public: 39 public:
37 class Event { 40 class Event {
38 public: 41 public:
39 Event(const Actions& actions, base::File::Error result) 42 Event(const Actions& actions, base::File::Error result)
40 : actions_(actions), result_(result) {} 43 : actions_(actions), result_(result) {}
41 virtual ~Event() {} 44 virtual ~Event() {}
42 45
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 class FileSystemProviderOperationsGetActionsTest : public testing::Test { 93 class FileSystemProviderOperationsGetActionsTest : public testing::Test {
91 protected: 94 protected:
92 FileSystemProviderOperationsGetActionsTest() {} 95 FileSystemProviderOperationsGetActionsTest() {}
93 ~FileSystemProviderOperationsGetActionsTest() override {} 96 ~FileSystemProviderOperationsGetActionsTest() override {}
94 97
95 void SetUp() override { 98 void SetUp() override {
96 file_system_info_ = ProvidedFileSystemInfo( 99 file_system_info_ = ProvidedFileSystemInfo(
97 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */), 100 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */),
98 base::FilePath(), false /* configurable */, true /* watchable */, 101 base::FilePath(), false /* configurable */, true /* watchable */,
99 extensions::SOURCE_FILE); 102 extensions::SOURCE_FILE);
103 entry_paths_.clear();
104 entry_paths_.push_back(base::FilePath(kDirectoryPath));
105 entry_paths_.push_back(base::FilePath(kFilePath));
100 } 106 }
101 107
102 ProvidedFileSystemInfo file_system_info_; 108 ProvidedFileSystemInfo file_system_info_;
109 std::vector<base::FilePath> entry_paths_;
103 }; 110 };
104 111
105 TEST_F(FileSystemProviderOperationsGetActionsTest, Execute) { 112 TEST_F(FileSystemProviderOperationsGetActionsTest, Execute) {
106 using extensions::api::file_system_provider::GetActionsRequestedOptions; 113 using extensions::api::file_system_provider::GetActionsRequestedOptions;
107 114
108 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 115 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
109 CallbackLogger callback_logger; 116 CallbackLogger callback_logger;
110 117
111 GetActions get_actions(NULL, file_system_info_, base::FilePath(kEntryPath), 118 GetActions get_actions(NULL, file_system_info_, entry_paths_,
112 base::Bind(&CallbackLogger::OnGetActions, 119 base::Bind(&CallbackLogger::OnGetActions,
113 base::Unretained(&callback_logger))); 120 base::Unretained(&callback_logger)));
114 get_actions.SetDispatchEventImplForTesting( 121 get_actions.SetDispatchEventImplForTesting(
115 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 122 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
116 base::Unretained(&dispatcher))); 123 base::Unretained(&dispatcher)));
117 124
118 EXPECT_TRUE(get_actions.Execute(kRequestId)); 125 EXPECT_TRUE(get_actions.Execute(kRequestId));
119 126
120 ASSERT_EQ(1u, dispatcher.events().size()); 127 ASSERT_EQ(1u, dispatcher.events().size());
121 extensions::Event* event = dispatcher.events()[0]; 128 extensions::Event* event = dispatcher.events()[0];
122 EXPECT_EQ( 129 EXPECT_EQ(
123 extensions::api::file_system_provider::OnGetActionsRequested::kEventName, 130 extensions::api::file_system_provider::OnGetActionsRequested::kEventName,
124 event->event_name); 131 event->event_name);
125 base::ListValue* event_args = event->event_args.get(); 132 base::ListValue* event_args = event->event_args.get();
126 ASSERT_EQ(1u, event_args->GetSize()); 133 ASSERT_EQ(1u, event_args->GetSize());
127 134
128 const base::DictionaryValue* options_as_value = NULL; 135 const base::DictionaryValue* options_as_value = NULL;
129 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); 136 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
130 137
131 GetActionsRequestedOptions options; 138 GetActionsRequestedOptions options;
132 ASSERT_TRUE( 139 ASSERT_TRUE(
133 GetActionsRequestedOptions::Populate(*options_as_value, &options)); 140 GetActionsRequestedOptions::Populate(*options_as_value, &options));
134 EXPECT_EQ(kFileSystemId, options.file_system_id); 141 EXPECT_EQ(kFileSystemId, options.file_system_id);
135 EXPECT_EQ(kRequestId, options.request_id); 142 EXPECT_EQ(kRequestId, options.request_id);
136 EXPECT_EQ(kEntryPath, options.entry_path); 143 ASSERT_EQ(entry_paths_.size(), options.entry_paths.size());
144 EXPECT_EQ(entry_paths_[0].value(), options.entry_paths[0]);
145 EXPECT_EQ(entry_paths_[1].value(), options.entry_paths[1]);
137 } 146 }
138 147
139 TEST_F(FileSystemProviderOperationsGetActionsTest, Execute_NoListener) { 148 TEST_F(FileSystemProviderOperationsGetActionsTest, Execute_NoListener) {
140 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); 149 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
141 CallbackLogger callback_logger; 150 CallbackLogger callback_logger;
142 151
143 GetActions get_actions(NULL, file_system_info_, base::FilePath(kEntryPath), 152 GetActions get_actions(NULL, file_system_info_, entry_paths_,
144 base::Bind(&CallbackLogger::OnGetActions, 153 base::Bind(&CallbackLogger::OnGetActions,
145 base::Unretained(&callback_logger))); 154 base::Unretained(&callback_logger)));
146 get_actions.SetDispatchEventImplForTesting( 155 get_actions.SetDispatchEventImplForTesting(
147 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 156 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
148 base::Unretained(&dispatcher))); 157 base::Unretained(&dispatcher)));
149 158
150 EXPECT_FALSE(get_actions.Execute(kRequestId)); 159 EXPECT_FALSE(get_actions.Execute(kRequestId));
151 } 160 }
152 161
153 TEST_F(FileSystemProviderOperationsGetActionsTest, OnSuccess) { 162 TEST_F(FileSystemProviderOperationsGetActionsTest, OnSuccess) {
154 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 163 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
155 CallbackLogger callback_logger; 164 CallbackLogger callback_logger;
156 165
157 GetActions get_actions(NULL, file_system_info_, base::FilePath(kEntryPath), 166 GetActions get_actions(NULL, file_system_info_, entry_paths_,
158 base::Bind(&CallbackLogger::OnGetActions, 167 base::Bind(&CallbackLogger::OnGetActions,
159 base::Unretained(&callback_logger))); 168 base::Unretained(&callback_logger)));
160 get_actions.SetDispatchEventImplForTesting( 169 get_actions.SetDispatchEventImplForTesting(
161 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 170 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
162 base::Unretained(&dispatcher))); 171 base::Unretained(&dispatcher)));
163 172
164 EXPECT_TRUE(get_actions.Execute(kRequestId)); 173 EXPECT_TRUE(get_actions.Execute(kRequestId));
165 174
166 // Sample input as JSON. Keep in sync with file_system_provider_api.idl. 175 // 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 176 // 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 215
207 const Action action_custom = event->actions()[2]; 216 const Action action_custom = event->actions()[2];
208 EXPECT_EQ("SomeCustomActionId", action_custom.id); 217 EXPECT_EQ("SomeCustomActionId", action_custom.id);
209 EXPECT_EQ("Custom action.", action_custom.title); 218 EXPECT_EQ("Custom action.", action_custom.title);
210 } 219 }
211 220
212 TEST_F(FileSystemProviderOperationsGetActionsTest, OnError) { 221 TEST_F(FileSystemProviderOperationsGetActionsTest, OnError) {
213 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 222 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
214 CallbackLogger callback_logger; 223 CallbackLogger callback_logger;
215 224
216 GetActions get_actions(NULL, file_system_info_, base::FilePath(kEntryPath), 225 GetActions get_actions(NULL, file_system_info_, entry_paths_,
217 base::Bind(&CallbackLogger::OnGetActions, 226 base::Bind(&CallbackLogger::OnGetActions,
218 base::Unretained(&callback_logger))); 227 base::Unretained(&callback_logger)));
219 get_actions.SetDispatchEventImplForTesting( 228 get_actions.SetDispatchEventImplForTesting(
220 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 229 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
221 base::Unretained(&dispatcher))); 230 base::Unretained(&dispatcher)));
222 231
223 EXPECT_TRUE(get_actions.Execute(kRequestId)); 232 EXPECT_TRUE(get_actions.Execute(kRequestId));
224 233
225 get_actions.OnError(kRequestId, scoped_ptr<RequestValue>(new RequestValue()), 234 get_actions.OnError(kRequestId, scoped_ptr<RequestValue>(new RequestValue()),
226 base::File::FILE_ERROR_TOO_MANY_OPENED); 235 base::File::FILE_ERROR_TOO_MANY_OPENED);
227 236
228 ASSERT_EQ(1u, callback_logger.events().size()); 237 ASSERT_EQ(1u, callback_logger.events().size());
229 CallbackLogger::Event* event = callback_logger.events()[0]; 238 CallbackLogger::Event* event = callback_logger.events()[0];
230 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); 239 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result());
231 ASSERT_EQ(0u, event->actions().size()); 240 ASSERT_EQ(0u, event->actions().size());
232 } 241 }
233 242
234 } // namespace operations 243 } // namespace operations
235 } // namespace file_system_provider 244 } // namespace file_system_provider
236 } // namespace chromeos 245 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698