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

Side by Side Diff: chrome/browser/extensions/api/file_system/file_system_api_unittest.cc

Issue 1829783002: [Extensions] Convert APIs to use movable types [5] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/api/file_system/file_system_api.h" 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 const std::vector<base::FilePath::StringType>& actual) { 49 const std::vector<base::FilePath::StringType>& actual) {
50 EXPECT_EQ(expected.size(), actual.size()); 50 EXPECT_EQ(expected.size(), actual.size());
51 if (expected.size() != actual.size()) 51 if (expected.size() != actual.size())
52 return; 52 return;
53 53
54 for (size_t i = 0; i < expected.size(); ++i) { 54 for (size_t i = 0; i < expected.size(); ++i) {
55 EXPECT_EQ(expected[i], actual[i]); 55 EXPECT_EQ(expected[i], actual[i]);
56 } 56 }
57 } 57 }
58 58
59 AcceptOption* BuildAcceptOption(const std::string& description, 59 AcceptOption BuildAcceptOption(const std::string& description,
60 const std::string& mime_types, 60 const std::string& mime_types,
61 const std::string& extensions) { 61 const std::string& extensions) {
62 AcceptOption* option = new AcceptOption(); 62 AcceptOption option;
63 63
64 if (!description.empty()) 64 if (!description.empty())
65 option->description.reset(new std::string(description)); 65 option.description.reset(new std::string(description));
66 66
67 if (!mime_types.empty()) { 67 if (!mime_types.empty()) {
68 option->mime_types.reset(new std::vector<std::string>( 68 option.mime_types.reset(new std::vector<std::string>(base::SplitString(
69 base::SplitString(mime_types, ",", 69 mime_types, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)));
70 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)));
71 } 70 }
72 71
73 if (!extensions.empty()) { 72 if (!extensions.empty()) {
74 option->extensions.reset(new std::vector<std::string>( 73 option.extensions.reset(new std::vector<std::string>(base::SplitString(
75 base::SplitString(extensions, ",", 74 extensions, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)));
76 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)));
77 } 75 }
78 76
79 return option; 77 return option;
80 } 78 }
81 79
82 #if defined(OS_WIN) 80 #if defined(OS_WIN)
83 #define ToStringType base::UTF8ToWide 81 #define ToStringType base::UTF8ToWide
84 #else 82 #else
85 #define ToStringType 83 #define ToStringType
86 #endif 84 #endif
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // AcceptsAllTypes is ignored when no other extensions are available. 189 // AcceptsAllTypes is ignored when no other extensions are available.
192 ui::SelectFileDialog::FileTypeInfo file_type_info; 190 ui::SelectFileDialog::FileTypeInfo file_type_info;
193 bool acceptsAllTypes = false; 191 bool acceptsAllTypes = false;
194 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, 192 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info,
195 base::FilePath::StringType(), NULL, &acceptsAllTypes); 193 base::FilePath::StringType(), NULL, &acceptsAllTypes);
196 EXPECT_TRUE(file_type_info.include_all_files); 194 EXPECT_TRUE(file_type_info.include_all_files);
197 EXPECT_TRUE(file_type_info.extensions.empty()); 195 EXPECT_TRUE(file_type_info.extensions.empty());
198 196
199 // Test grouping of multiple types. 197 // Test grouping of multiple types.
200 file_type_info = ui::SelectFileDialog::FileTypeInfo(); 198 file_type_info = ui::SelectFileDialog::FileTypeInfo();
201 std::vector<linked_ptr<AcceptOption> > options; 199 std::vector<AcceptOption> options;
202 options.push_back(linked_ptr<AcceptOption>(BuildAcceptOption( 200 options.push_back(BuildAcceptOption(std::string(),
203 std::string(), "application/x-chrome-extension", "jso"))); 201 "application/x-chrome-extension", "jso"));
204 acceptsAllTypes = false; 202 acceptsAllTypes = false;
205 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, 203 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info,
206 base::FilePath::StringType(), &options, &acceptsAllTypes); 204 base::FilePath::StringType(), &options, &acceptsAllTypes);
207 EXPECT_FALSE(file_type_info.include_all_files); 205 EXPECT_FALSE(file_type_info.include_all_files);
208 ASSERT_EQ(file_type_info.extensions.size(), (size_t) 1); 206 ASSERT_EQ(file_type_info.extensions.size(), (size_t) 1);
209 EXPECT_TRUE(file_type_info.extension_description_overrides[0].empty()) << 207 EXPECT_TRUE(file_type_info.extension_description_overrides[0].empty()) <<
210 "No override must be specified for boring accept types"; 208 "No override must be specified for boring accept types";
211 // Note here (and below) that the expectedTypes are sorted, because we use a 209 // Note here (and below) that the expectedTypes are sorted, because we use a
212 // set internally to generate the output: thus, the output is sorted. 210 // set internally to generate the output: thus, the output is sorted.
213 std::vector<base::FilePath::StringType> expectedTypes; 211 std::vector<base::FilePath::StringType> expectedTypes;
214 expectedTypes.push_back(ToStringType("crx")); 212 expectedTypes.push_back(ToStringType("crx"));
215 expectedTypes.push_back(ToStringType("jso")); 213 expectedTypes.push_back(ToStringType("jso"));
216 CheckExtensions(expectedTypes, file_type_info.extensions[0]); 214 CheckExtensions(expectedTypes, file_type_info.extensions[0]);
217 215
218 // Test that not satisfying the extension will force all types. 216 // Test that not satisfying the extension will force all types.
219 file_type_info = ui::SelectFileDialog::FileTypeInfo(); 217 file_type_info = ui::SelectFileDialog::FileTypeInfo();
220 options.clear(); 218 options.clear();
221 options.push_back(linked_ptr<AcceptOption>(BuildAcceptOption( 219 options.push_back(
222 std::string(), std::string(), "unrelated"))); 220 BuildAcceptOption(std::string(), std::string(), "unrelated"));
223 acceptsAllTypes = false; 221 acceptsAllTypes = false;
224 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, 222 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info,
225 ToStringType(".jso"), &options, &acceptsAllTypes); 223 ToStringType(".jso"), &options, &acceptsAllTypes);
226 EXPECT_TRUE(file_type_info.include_all_files); 224 EXPECT_TRUE(file_type_info.include_all_files);
227 225
228 // Test multiple list entries, all containing their own types. 226 // Test multiple list entries, all containing their own types.
229 file_type_info = ui::SelectFileDialog::FileTypeInfo(); 227 file_type_info = ui::SelectFileDialog::FileTypeInfo();
230 options.clear(); 228 options.clear();
231 options.push_back(linked_ptr<AcceptOption>( 229 options.push_back(BuildAcceptOption(std::string(), std::string(), "jso,js"));
232 BuildAcceptOption(std::string(), std::string(), "jso,js"))); 230 options.push_back(BuildAcceptOption(std::string(), std::string(), "cpp,cc"));
233 options.push_back(linked_ptr<AcceptOption>(
234 BuildAcceptOption(std::string(), std::string(), "cpp,cc")));
235 acceptsAllTypes = false; 231 acceptsAllTypes = false;
236 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, 232 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info,
237 base::FilePath::StringType(), &options, &acceptsAllTypes); 233 base::FilePath::StringType(), &options, &acceptsAllTypes);
238 ASSERT_EQ(file_type_info.extensions.size(), options.size()); 234 ASSERT_EQ(file_type_info.extensions.size(), options.size());
239 235
240 expectedTypes.clear(); 236 expectedTypes.clear();
241 expectedTypes.push_back(ToStringType("js")); 237 expectedTypes.push_back(ToStringType("js"));
242 expectedTypes.push_back(ToStringType("jso")); 238 expectedTypes.push_back(ToStringType("jso"));
243 CheckExtensions(expectedTypes, file_type_info.extensions[0]); 239 CheckExtensions(expectedTypes, file_type_info.extensions[0]);
244 240
245 expectedTypes.clear(); 241 expectedTypes.clear();
246 expectedTypes.push_back(ToStringType("cc")); 242 expectedTypes.push_back(ToStringType("cc"));
247 expectedTypes.push_back(ToStringType("cpp")); 243 expectedTypes.push_back(ToStringType("cpp"));
248 CheckExtensions(expectedTypes, file_type_info.extensions[1]); 244 CheckExtensions(expectedTypes, file_type_info.extensions[1]);
249 245
250 // Test accept type that causes description override. 246 // Test accept type that causes description override.
251 file_type_info = ui::SelectFileDialog::FileTypeInfo(); 247 file_type_info = ui::SelectFileDialog::FileTypeInfo();
252 options.clear(); 248 options.clear();
253 options.push_back(linked_ptr<AcceptOption>( 249 options.push_back(BuildAcceptOption(std::string(), "image/*", "html"));
254 BuildAcceptOption(std::string(), "image/*", "html")));
255 acceptsAllTypes = false; 250 acceptsAllTypes = false;
256 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, 251 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info,
257 base::FilePath::StringType(), &options, &acceptsAllTypes); 252 base::FilePath::StringType(), &options, &acceptsAllTypes);
258 ASSERT_EQ(file_type_info.extension_description_overrides.size(), (size_t) 1); 253 ASSERT_EQ(file_type_info.extension_description_overrides.size(), (size_t) 1);
259 EXPECT_FALSE(file_type_info.extension_description_overrides[0].empty()) << 254 EXPECT_FALSE(file_type_info.extension_description_overrides[0].empty()) <<
260 "Accept type \"image/*\" must generate description override"; 255 "Accept type \"image/*\" must generate description override";
261 256
262 // Test multiple accept types that cause description override causes us to 257 // Test multiple accept types that cause description override causes us to
263 // still present the default. 258 // still present the default.
264 file_type_info = ui::SelectFileDialog::FileTypeInfo(); 259 file_type_info = ui::SelectFileDialog::FileTypeInfo();
265 options.clear(); 260 options.clear();
266 options.push_back(linked_ptr<AcceptOption>(BuildAcceptOption( 261 options.push_back(BuildAcceptOption(std::string(), "image/*,audio/*,video/*",
267 std::string(), "image/*,audio/*,video/*", std::string()))); 262 std::string()));
268 acceptsAllTypes = false; 263 acceptsAllTypes = false;
269 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, 264 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info,
270 base::FilePath::StringType(), &options, &acceptsAllTypes); 265 base::FilePath::StringType(), &options, &acceptsAllTypes);
271 ASSERT_EQ(file_type_info.extension_description_overrides.size(), (size_t) 1); 266 ASSERT_EQ(file_type_info.extension_description_overrides.size(), (size_t) 1);
272 EXPECT_TRUE(file_type_info.extension_description_overrides[0].empty()); 267 EXPECT_TRUE(file_type_info.extension_description_overrides[0].empty());
273 268
274 // Test explicit description override. 269 // Test explicit description override.
275 file_type_info = ui::SelectFileDialog::FileTypeInfo(); 270 file_type_info = ui::SelectFileDialog::FileTypeInfo();
276 options.clear(); 271 options.clear();
277 options.push_back(linked_ptr<AcceptOption>( 272 options.push_back(
278 BuildAcceptOption("File Types 101", "image/jpeg", std::string()))); 273 BuildAcceptOption("File Types 101", "image/jpeg", std::string()));
279 acceptsAllTypes = false; 274 acceptsAllTypes = false;
280 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info, 275 FileSystemChooseEntryFunction::BuildFileTypeInfo(&file_type_info,
281 base::FilePath::StringType(), &options, &acceptsAllTypes); 276 base::FilePath::StringType(), &options, &acceptsAllTypes);
282 EXPECT_EQ(file_type_info.extension_description_overrides[0], 277 EXPECT_EQ(file_type_info.extension_description_overrides[0],
283 base::UTF8ToUTF16("File Types 101")); 278 base::UTF8ToUTF16("File Types 101"));
284 } 279 }
285 280
286 TEST(FileSystemApiUnitTest, FileSystemChooseEntryFunctionSuggestionTest) { 281 TEST(FileSystemApiUnitTest, FileSystemChooseEntryFunctionSuggestionTest) {
287 std::string opt_name; 282 std::string opt_name;
288 base::FilePath suggested_name; 283 base::FilePath suggested_name;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 base::RunLoop().RunUntilIdle(); 432 base::RunLoop().RunUntilIdle();
438 433
439 EXPECT_EQ(1, delegate.show_dialog_counter()); 434 EXPECT_EQ(1, delegate.show_dialog_counter());
440 EXPECT_EQ(0, delegate.show_notification_counter()); 435 EXPECT_EQ(0, delegate.show_notification_counter());
441 EXPECT_EQ(ConsentProvider::CONSENT_REJECTED, result); 436 EXPECT_EQ(ConsentProvider::CONSENT_REJECTED, result);
442 } 437 }
443 } 438 }
444 #endif 439 #endif
445 440
446 } // namespace extensions 441 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/file_system/file_system_api.cc ('k') | chrome/common/extensions/api/file_browser_handler.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698