OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_manager/file_tasks.h" | 5 #include "chrome/browser/chromeos/file_manager/file_tasks.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 } // namespace | 58 } // namespace |
59 | 59 |
60 TEST(FileManagerFileTasksTest, | 60 TEST(FileManagerFileTasksTest, |
61 FullTaskDescriptor_NonDriveAppWithIconAndDefault) { | 61 FullTaskDescriptor_NonDriveAppWithIconAndDefault) { |
62 FullTaskDescriptor full_descriptor( | 62 FullTaskDescriptor full_descriptor( |
63 TaskDescriptor("app-id", | 63 TaskDescriptor("app-id", |
64 TASK_TYPE_FILE_BROWSER_HANDLER, | 64 TASK_TYPE_FILE_BROWSER_HANDLER, |
65 "action-id"), | 65 "action-id"), |
66 "task title", | 66 "task title", |
67 GURL("http://example.com/icon.png"), | 67 GURL("http://example.com/icon.png"), |
68 true /* is_default */); | 68 true /* is_default */, |
| 69 false /* is_generic_file_handler */); |
69 | 70 |
70 const std::string task_id = | 71 const std::string task_id = |
71 TaskDescriptorToId(full_descriptor.task_descriptor()); | 72 TaskDescriptorToId(full_descriptor.task_descriptor()); |
72 EXPECT_EQ("app-id|file|action-id", task_id); | 73 EXPECT_EQ("app-id|file|action-id", task_id); |
73 EXPECT_EQ("http://example.com/icon.png", full_descriptor.icon_url().spec()); | 74 EXPECT_EQ("http://example.com/icon.png", full_descriptor.icon_url().spec()); |
74 EXPECT_EQ("task title", full_descriptor.task_title()); | 75 EXPECT_EQ("task title", full_descriptor.task_title()); |
75 EXPECT_TRUE(full_descriptor.is_default()); | 76 EXPECT_TRUE(full_descriptor.is_default()); |
76 } | 77 } |
77 | 78 |
78 TEST(FileManagerFileTasksTest, | 79 TEST(FileManagerFileTasksTest, |
79 FullTaskDescriptor_DriveAppWithoutIconAndNotDefault) { | 80 FullTaskDescriptor_DriveAppWithoutIconAndNotDefault) { |
80 FullTaskDescriptor full_descriptor( | 81 FullTaskDescriptor full_descriptor( |
81 TaskDescriptor("app-id", | 82 TaskDescriptor("app-id", |
82 TASK_TYPE_DRIVE_APP, | 83 TASK_TYPE_DRIVE_APP, |
83 "action-id"), | 84 "action-id"), |
84 "task title", | 85 "task title", |
85 GURL(), // No icon URL. | 86 GURL(), // No icon URL. |
86 false /* is_default */); | 87 false /* is_default */, |
| 88 false /* is_generic_file_handler */); |
87 | 89 |
88 const std::string task_id = | 90 const std::string task_id = |
89 TaskDescriptorToId(full_descriptor.task_descriptor()); | 91 TaskDescriptorToId(full_descriptor.task_descriptor()); |
90 EXPECT_EQ("app-id|drive|action-id", task_id); | 92 EXPECT_EQ("app-id|drive|action-id", task_id); |
91 EXPECT_TRUE(full_descriptor.icon_url().is_empty()); | 93 EXPECT_TRUE(full_descriptor.icon_url().is_empty()); |
92 EXPECT_EQ("task title", full_descriptor.task_title()); | 94 EXPECT_EQ("task title", full_descriptor.task_title()); |
93 EXPECT_FALSE(full_descriptor.is_default()); | 95 EXPECT_FALSE(full_descriptor.is_default()); |
94 } | 96 } |
95 | 97 |
96 TEST(FileManagerFileTasksTest, MakeTaskID) { | 98 TEST(FileManagerFileTasksTest, MakeTaskID) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 TASK_TYPE_FILE_HANDLER, | 262 TASK_TYPE_FILE_HANDLER, |
261 "action-id"); | 263 "action-id"); |
262 TaskDescriptor nice_app_task("nice-app-id", | 264 TaskDescriptor nice_app_task("nice-app-id", |
263 TASK_TYPE_FILE_HANDLER, | 265 TASK_TYPE_FILE_HANDLER, |
264 "action-id"); | 266 "action-id"); |
265 std::vector<FullTaskDescriptor> tasks; | 267 std::vector<FullTaskDescriptor> tasks; |
266 tasks.push_back(FullTaskDescriptor( | 268 tasks.push_back(FullTaskDescriptor( |
267 text_app_task, | 269 text_app_task, |
268 "Text.app", | 270 "Text.app", |
269 GURL("http://example.com/text_app.png"), | 271 GURL("http://example.com/text_app.png"), |
270 false /* is_default */)); | 272 false /* is_default */, |
| 273 false /* is_generic_file_handler */)); |
271 tasks.push_back(FullTaskDescriptor( | 274 tasks.push_back(FullTaskDescriptor( |
272 nice_app_task, | 275 nice_app_task, |
273 "Nice.app", | 276 "Nice.app", |
274 GURL("http://example.com/nice_app.png"), | 277 GURL("http://example.com/nice_app.png"), |
275 false /* is_default */)); | 278 false /* is_default */, |
| 279 false /* is_generic_file_handler */)); |
276 PathAndMimeTypeSet path_mime_set; | 280 PathAndMimeTypeSet path_mime_set; |
277 path_mime_set.insert(std::make_pair( | 281 path_mime_set.insert(std::make_pair( |
278 base::FilePath::FromUTF8Unsafe("foo.txt"), | 282 base::FilePath::FromUTF8Unsafe("foo.txt"), |
279 "text/plain")); | 283 "text/plain")); |
280 | 284 |
281 // None of them should be chosen as default, as nothing is set in the | 285 // None of them should be chosen as default, as nothing is set in the |
282 // preferences. | 286 // preferences. |
283 ChooseAndSetDefaultTask(pref_service, path_mime_set, &tasks); | 287 ChooseAndSetDefaultTask(pref_service, path_mime_set, &tasks); |
284 EXPECT_FALSE(tasks[0].is_default()); | 288 EXPECT_FALSE(tasks[0].is_default()); |
285 EXPECT_FALSE(tasks[1].is_default()); | 289 EXPECT_FALSE(tasks[1].is_default()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 | 331 |
328 // Files.app's internal file browser handler was found for "foo.txt". | 332 // Files.app's internal file browser handler was found for "foo.txt". |
329 TaskDescriptor files_app_task(kFileManagerAppId, | 333 TaskDescriptor files_app_task(kFileManagerAppId, |
330 TASK_TYPE_FILE_BROWSER_HANDLER, | 334 TASK_TYPE_FILE_BROWSER_HANDLER, |
331 "view-in-browser"); | 335 "view-in-browser"); |
332 std::vector<FullTaskDescriptor> tasks; | 336 std::vector<FullTaskDescriptor> tasks; |
333 tasks.push_back(FullTaskDescriptor( | 337 tasks.push_back(FullTaskDescriptor( |
334 files_app_task, | 338 files_app_task, |
335 "View in browser", | 339 "View in browser", |
336 GURL("http://example.com/some_icon.png"), | 340 GURL("http://example.com/some_icon.png"), |
337 false /* is_default */)); | 341 false /* is_default */, |
| 342 false /* is_generic_file_handler */)); |
338 PathAndMimeTypeSet path_mime_set; | 343 PathAndMimeTypeSet path_mime_set; |
339 path_mime_set.insert(std::make_pair( | 344 path_mime_set.insert(std::make_pair( |
340 base::FilePath::FromUTF8Unsafe("foo.txt"), | 345 base::FilePath::FromUTF8Unsafe("foo.txt"), |
341 "text/plain")); | 346 "text/plain")); |
342 | 347 |
343 // The internal file browser handler should be chosen as default, as it's a | 348 // The internal file browser handler should be chosen as default, as it's a |
344 // fallback file browser handler. | 349 // fallback file browser handler. |
345 ChooseAndSetDefaultTask(pref_service, path_mime_set, &tasks); | 350 ChooseAndSetDefaultTask(pref_service, path_mime_set, &tasks); |
346 EXPECT_TRUE(tasks[0].is_default()); | 351 EXPECT_TRUE(tasks[0].is_default()); |
347 } | 352 } |
348 | 353 |
| 354 // Test IsGenericFileHandler which returns whether a file handle info is a |
| 355 // generic file handler or not. |
| 356 TEST(FileManagerFileTasksTest, IsGenericFileHandler) { |
| 357 using FileHandlerInfo = extensions::FileHandlerInfo; |
| 358 |
| 359 // extensions: ["*"] |
| 360 FileHandlerInfo file_handler_info_1; |
| 361 file_handler_info_1.extensions.insert("*"); |
| 362 EXPECT_TRUE(IsGenericFileHandler(file_handler_info_1)); |
| 363 |
| 364 // extensions: ["*", "jpg"] |
| 365 FileHandlerInfo file_handler_info_2; |
| 366 file_handler_info_2.extensions.insert("*"); |
| 367 file_handler_info_2.extensions.insert("jpg"); |
| 368 EXPECT_TRUE(IsGenericFileHandler(file_handler_info_2)); |
| 369 |
| 370 // extensions: ["jpg"] |
| 371 FileHandlerInfo file_handler_info_3; |
| 372 file_handler_info_3.extensions.insert("jpg"); |
| 373 EXPECT_FALSE(IsGenericFileHandler(file_handler_info_3)); |
| 374 |
| 375 // types: ["*"] |
| 376 FileHandlerInfo file_handler_info_4; |
| 377 file_handler_info_4.types.insert("*"); |
| 378 EXPECT_TRUE(IsGenericFileHandler(file_handler_info_4)); |
| 379 |
| 380 // types: ["*/*"] |
| 381 FileHandlerInfo file_handler_info_5; |
| 382 file_handler_info_5.types.insert("*/*"); |
| 383 EXPECT_TRUE(IsGenericFileHandler(file_handler_info_5)); |
| 384 |
| 385 // types: ["image/*"] |
| 386 FileHandlerInfo file_handler_info_6; |
| 387 file_handler_info_6.types.insert("image/*"); |
| 388 // Partial wild card is not generic. |
| 389 EXPECT_FALSE(IsGenericFileHandler(file_handler_info_6)); |
| 390 |
| 391 // types: ["*", "image/*"] |
| 392 FileHandlerInfo file_handler_info_7; |
| 393 file_handler_info_7.types.insert("*"); |
| 394 file_handler_info_7.types.insert("image/*"); |
| 395 EXPECT_TRUE(IsGenericFileHandler(file_handler_info_7)); |
| 396 |
| 397 // extensions: ["*"], types: ["image/*"] |
| 398 FileHandlerInfo file_handler_info_8; |
| 399 file_handler_info_8.extensions.insert("*"); |
| 400 file_handler_info_8.types.insert("image/*"); |
| 401 EXPECT_TRUE(IsGenericFileHandler(file_handler_info_8)); |
| 402 } |
| 403 |
349 // Test using the test extension system, which needs lots of setup. | 404 // Test using the test extension system, which needs lots of setup. |
350 class FileManagerFileTasksComplexTest : public testing::Test { | 405 class FileManagerFileTasksComplexTest : public testing::Test { |
351 protected: | 406 protected: |
352 FileManagerFileTasksComplexTest() | 407 FileManagerFileTasksComplexTest() |
353 : command_line_(CommandLine::NO_PROGRAM), | 408 : command_line_(CommandLine::NO_PROGRAM), |
354 extension_service_(NULL) { | 409 extension_service_(NULL) { |
355 extensions::TestExtensionSystem* test_extension_system = | 410 extensions::TestExtensionSystem* test_extension_system = |
356 static_cast<extensions::TestExtensionSystem*>( | 411 static_cast<extensions::TestExtensionSystem*>( |
357 extensions::ExtensionSystem::Get(&test_profile_)); | 412 extensions::ExtensionSystem::Get(&test_profile_)); |
358 extension_service_ = test_extension_system->CreateExtensionService( | 413 extension_service_ = test_extension_system->CreateExtensionService( |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 std::vector<FullTaskDescriptor> tasks; | 842 std::vector<FullTaskDescriptor> tasks; |
788 FindAllTypesOfTasks(&test_profile_, | 843 FindAllTypesOfTasks(&test_profile_, |
789 &drive_app_registry, | 844 &drive_app_registry, |
790 path_mime_set, | 845 path_mime_set, |
791 file_urls, | 846 file_urls, |
792 &tasks); | 847 &tasks); |
793 ASSERT_EQ(1U, tasks.size()); | 848 ASSERT_EQ(1U, tasks.size()); |
794 EXPECT_EQ(kFileManagerAppId, tasks[0].task_descriptor().app_id); | 849 EXPECT_EQ(kFileManagerAppId, tasks[0].task_descriptor().app_id); |
795 } | 850 } |
796 | 851 |
| 852 TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTask_Generic) { |
| 853 // Since we want to keep the order of the result as foo,bar,baz,qux, |
| 854 // keep the ids in alphabetical order. |
| 855 const char kFooId[] = "hhgbjpmdppecanaaogonaigmmifgpaph"; |
| 856 const char kBarId[] = "odlhccgofgkadkkhcmhgnhgahonahoca"; |
| 857 const char kBazId[] = "plifkpkakemokpflgbnnigcoldgcbdmc"; |
| 858 const char kQuxId[] = "pmifkpkakgkadkkhcmhgnigmmifgpaph"; |
| 859 |
| 860 // Foo app provides file handler for text/plain and all file types. |
| 861 extensions::ExtensionBuilder foo_app; |
| 862 foo_app.SetManifest(extensions::DictionaryBuilder() |
| 863 .Set("name", "Foo") |
| 864 .Set("version", "1.0.0") |
| 865 .Set("manifest_version", 2) |
| 866 .Set("app", extensions::DictionaryBuilder() |
| 867 .Set("background", extensions::DictionaryBuilder() |
| 868 .Set("scripts", extensions::ListBuilder() |
| 869 .Append("background.js")))) |
| 870 .Set("file_handlers", |
| 871 extensions::DictionaryBuilder() |
| 872 .Set("any", |
| 873 extensions::DictionaryBuilder() |
| 874 .Set("types", extensions::ListBuilder() |
| 875 .Append("*/*"))) |
| 876 .Set("text", |
| 877 extensions::DictionaryBuilder() |
| 878 .Set("types", extensions::ListBuilder() |
| 879 .Append("text/plain"))))); |
| 880 foo_app.SetID(kFooId); |
| 881 extension_service_->AddExtension(foo_app.Build().get()); |
| 882 |
| 883 // Bar app provides file handler for .txt and not provide generic file |
| 884 // handler. |
| 885 extensions::ExtensionBuilder bar_app; |
| 886 bar_app.SetManifest(extensions::DictionaryBuilder() |
| 887 .Set("name", "Bar") |
| 888 .Set("version", "1.0.0") |
| 889 .Set("manifest_version", 2) |
| 890 .Set("app", extensions::DictionaryBuilder() |
| 891 .Set("background", extensions::DictionaryBuilder() |
| 892 .Set("scripts", extensions::ListBuilder() |
| 893 .Append("background.js")))) |
| 894 .Set("file_handlers", |
| 895 extensions::DictionaryBuilder() |
| 896 .Set("text", |
| 897 extensions::DictionaryBuilder() |
| 898 .Set("extensions", extensions::ListBuilder() |
| 899 .Append("txt"))))); |
| 900 bar_app.SetID(kBarId); |
| 901 extension_service_->AddExtension(bar_app.Build().get()); |
| 902 |
| 903 // Baz app provides file handler for all extensions and images. |
| 904 extensions::ExtensionBuilder baz_app; |
| 905 baz_app.SetManifest(extensions::DictionaryBuilder() |
| 906 .Set("name", "Baz") |
| 907 .Set("version", "1.0.0") |
| 908 .Set("manifest_version", 2) |
| 909 .Set("app", extensions::DictionaryBuilder() |
| 910 .Set("background", extensions::DictionaryBuilder() |
| 911 .Set("scripts", extensions::ListBuilder() |
| 912 .Append("background.js")))) |
| 913 .Set("file_handlers", |
| 914 extensions::DictionaryBuilder() |
| 915 .Set("any", |
| 916 extensions::DictionaryBuilder() |
| 917 .Set("extensions", extensions::ListBuilder() |
| 918 .Append("*") |
| 919 .Append("bar"))) |
| 920 .Set("image", |
| 921 extensions::DictionaryBuilder() |
| 922 .Set("types", extensions::ListBuilder() |
| 923 .Append("image/*"))))); |
| 924 baz_app.SetID(kBazId); |
| 925 extension_service_->AddExtension(baz_app.Build().get()); |
| 926 |
| 927 // Qux app provides file handler for all types. |
| 928 extensions::ExtensionBuilder qux_app; |
| 929 qux_app.SetManifest(extensions::DictionaryBuilder() |
| 930 .Set("name", "Qux") |
| 931 .Set("version", "1.0.0") |
| 932 .Set("manifest_version", 2) |
| 933 .Set("app", extensions::DictionaryBuilder() |
| 934 .Set("background", extensions::DictionaryBuilder() |
| 935 .Set("scripts", extensions::ListBuilder() |
| 936 .Append("background.js")))) |
| 937 .Set("file_handlers", |
| 938 extensions::DictionaryBuilder() |
| 939 .Set("any", |
| 940 extensions::DictionaryBuilder() |
| 941 .Set("types", extensions::ListBuilder() |
| 942 .Append("*"))))); |
| 943 qux_app.SetID(kQuxId); |
| 944 extension_service_->AddExtension(qux_app.Build().get()); |
| 945 |
| 946 // Test case with .txt file |
| 947 PathAndMimeTypeSet txt_path_mime_set; |
| 948 txt_path_mime_set.insert( |
| 949 std::make_pair( |
| 950 drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII( |
| 951 "foo.txt"), |
| 952 "text/plain")); |
| 953 std::vector<FullTaskDescriptor> txt_result; |
| 954 FindFileHandlerTasks(&test_profile_, txt_path_mime_set, &txt_result); |
| 955 EXPECT_EQ(4U, txt_result.size()); |
| 956 // Foo app provides a handler for text/plain. |
| 957 EXPECT_EQ("Foo", txt_result[0].task_title()); |
| 958 EXPECT_FALSE(txt_result[0].is_generic_file_handler()); |
| 959 // Bar app provides a handler for .txt. |
| 960 EXPECT_EQ("Bar", txt_result[1].task_title()); |
| 961 EXPECT_FALSE(txt_result[1].is_generic_file_handler()); |
| 962 // Baz app provides a handler for all extensions. |
| 963 EXPECT_EQ("Baz", txt_result[2].task_title()); |
| 964 EXPECT_TRUE(txt_result[2].is_generic_file_handler()); |
| 965 // Qux app provides a handler for all types. |
| 966 EXPECT_EQ("Qux", txt_result[3].task_title()); |
| 967 EXPECT_TRUE(txt_result[3].is_generic_file_handler()); |
| 968 |
| 969 // Test case with .jpg file |
| 970 PathAndMimeTypeSet jpg_path_mime_set; |
| 971 jpg_path_mime_set.insert( |
| 972 std::make_pair( |
| 973 drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII( |
| 974 "foo.jpg"), |
| 975 "image/jpeg")); |
| 976 std::vector<FullTaskDescriptor> jpg_result; |
| 977 FindFileHandlerTasks(&test_profile_, jpg_path_mime_set, &jpg_result); |
| 978 EXPECT_EQ(3U, jpg_result.size()); |
| 979 // Foo app provides a handler for all types. |
| 980 EXPECT_EQ("Foo", jpg_result[0].task_title()); |
| 981 EXPECT_TRUE(jpg_result[0].is_generic_file_handler()); |
| 982 // Baz app provides a handler for image/*. A partial wildcarded handler is |
| 983 // treated as non-generic handler. |
| 984 EXPECT_EQ("Baz", jpg_result[1].task_title()); |
| 985 EXPECT_FALSE(jpg_result[1].is_generic_file_handler()); |
| 986 // Qux app provides a handler for all types. |
| 987 EXPECT_EQ("Qux", jpg_result[2].task_title()); |
| 988 EXPECT_TRUE(jpg_result[2].is_generic_file_handler()); |
| 989 } |
| 990 |
797 } // namespace file_tasks | 991 } // namespace file_tasks |
798 } // namespace file_manager. | 992 } // namespace file_manager. |
OLD | NEW |