| 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 } |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 std::vector<FullTaskDescriptor> tasks; | 792 std::vector<FullTaskDescriptor> tasks; |
| 788 FindAllTypesOfTasks(&test_profile_, | 793 FindAllTypesOfTasks(&test_profile_, |
| 789 &drive_app_registry, | 794 &drive_app_registry, |
| 790 path_mime_set, | 795 path_mime_set, |
| 791 file_urls, | 796 file_urls, |
| 792 &tasks); | 797 &tasks); |
| 793 ASSERT_EQ(1U, tasks.size()); | 798 ASSERT_EQ(1U, tasks.size()); |
| 794 EXPECT_EQ(kFileManagerAppId, tasks[0].task_descriptor().app_id); | 799 EXPECT_EQ(kFileManagerAppId, tasks[0].task_descriptor().app_id); |
| 795 } | 800 } |
| 796 | 801 |
| 802 TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTask_Generic) { |
| 803 // Since we want to keep the order of the result as foo,bar,baz,qux, |
| 804 // keep the ids in alphabetical order. |
| 805 const char kFooId[] = "hhgbjpmdppecanaaogonaigmmifgpaph"; |
| 806 const char kBarId[] = "odlhccgofgkadkkhcmhgnhgahonahoca"; |
| 807 const char kBazId[] = "plifkpkakemokpflgbnnigcoldgcbdmc"; |
| 808 const char kQuxId[] = "pmifkpkakgkadkkhcmhgnigmmifgpaph"; |
| 809 |
| 810 // Foo app provides file handler for text/plain and all file types. |
| 811 extensions::ExtensionBuilder foo_app; |
| 812 foo_app.SetManifest(extensions::DictionaryBuilder() |
| 813 .Set("name", "Foo") |
| 814 .Set("version", "1.0.0") |
| 815 .Set("manifest_version", 2) |
| 816 .Set("app", extensions::DictionaryBuilder() |
| 817 .Set("background", extensions::DictionaryBuilder() |
| 818 .Set("scripts", extensions::ListBuilder() |
| 819 .Append("background.js")))) |
| 820 .Set("file_handlers", |
| 821 extensions::DictionaryBuilder() |
| 822 .Set("any", |
| 823 extensions::DictionaryBuilder() |
| 824 .Set("types", extensions::ListBuilder() |
| 825 .Append("*/*"))) |
| 826 .Set("text", |
| 827 extensions::DictionaryBuilder() |
| 828 .Set("types", extensions::ListBuilder() |
| 829 .Append("text/plain"))))); |
| 830 foo_app.SetID(kFooId); |
| 831 extension_service_->AddExtension(foo_app.Build().get()); |
| 832 |
| 833 // Bar app provides file handler for .txt and not provide generic file |
| 834 // handler. |
| 835 extensions::ExtensionBuilder bar_app; |
| 836 bar_app.SetManifest(extensions::DictionaryBuilder() |
| 837 .Set("name", "Bar") |
| 838 .Set("version", "1.0.0") |
| 839 .Set("manifest_version", 2) |
| 840 .Set("app", extensions::DictionaryBuilder() |
| 841 .Set("background", extensions::DictionaryBuilder() |
| 842 .Set("scripts", extensions::ListBuilder() |
| 843 .Append("background.js")))) |
| 844 .Set("file_handlers", |
| 845 extensions::DictionaryBuilder() |
| 846 .Set("text", |
| 847 extensions::DictionaryBuilder() |
| 848 .Set("extensions", extensions::ListBuilder() |
| 849 .Append("txt"))))); |
| 850 bar_app.SetID(kBarId); |
| 851 extension_service_->AddExtension(bar_app.Build().get()); |
| 852 |
| 853 // Baz app provides file handler for all extensions and images. |
| 854 extensions::ExtensionBuilder baz_app; |
| 855 baz_app.SetManifest(extensions::DictionaryBuilder() |
| 856 .Set("name", "Baz") |
| 857 .Set("version", "1.0.0") |
| 858 .Set("manifest_version", 2) |
| 859 .Set("app", extensions::DictionaryBuilder() |
| 860 .Set("background", extensions::DictionaryBuilder() |
| 861 .Set("scripts", extensions::ListBuilder() |
| 862 .Append("background.js")))) |
| 863 .Set("file_handlers", |
| 864 extensions::DictionaryBuilder() |
| 865 .Set("any", |
| 866 extensions::DictionaryBuilder() |
| 867 .Set("extensions", extensions::ListBuilder() |
| 868 .Append("*") |
| 869 .Append("bar"))) |
| 870 .Set("image", |
| 871 extensions::DictionaryBuilder() |
| 872 .Set("types", extensions::ListBuilder() |
| 873 .Append("image/*"))))); |
| 874 baz_app.SetID(kBazId); |
| 875 extension_service_->AddExtension(baz_app.Build().get()); |
| 876 |
| 877 // Qux app provides file handler for all types. |
| 878 extensions::ExtensionBuilder qux_app; |
| 879 qux_app.SetManifest(extensions::DictionaryBuilder() |
| 880 .Set("name", "Qux") |
| 881 .Set("version", "1.0.0") |
| 882 .Set("manifest_version", 2) |
| 883 .Set("app", extensions::DictionaryBuilder() |
| 884 .Set("background", extensions::DictionaryBuilder() |
| 885 .Set("scripts", extensions::ListBuilder() |
| 886 .Append("background.js")))) |
| 887 .Set("file_handlers", |
| 888 extensions::DictionaryBuilder() |
| 889 .Set("any", |
| 890 extensions::DictionaryBuilder() |
| 891 .Set("types", extensions::ListBuilder() |
| 892 .Append("*"))))); |
| 893 qux_app.SetID(kQuxId); |
| 894 extension_service_->AddExtension(qux_app.Build().get()); |
| 895 |
| 896 // Test case with .txt file |
| 897 PathAndMimeTypeSet txt_path_mime_set; |
| 898 txt_path_mime_set.insert( |
| 899 std::make_pair( |
| 900 drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII( |
| 901 "foo.txt"), |
| 902 "text/plain")); |
| 903 std::vector<FullTaskDescriptor> txt_result; |
| 904 FindFileHandlerTasks(&test_profile_, txt_path_mime_set, &txt_result); |
| 905 EXPECT_EQ(4U, txt_result.size()); |
| 906 // Foo app provides a handler for text/plain. |
| 907 EXPECT_EQ("Foo", txt_result[0].task_title()); |
| 908 EXPECT_FALSE(txt_result[0].is_generic_file_handler()); |
| 909 // Bar app provides a handler for .txt. |
| 910 EXPECT_EQ("Bar", txt_result[1].task_title()); |
| 911 EXPECT_FALSE(txt_result[1].is_generic_file_handler()); |
| 912 // Baz app provides a handler for all extensions. |
| 913 EXPECT_EQ("Baz", txt_result[2].task_title()); |
| 914 EXPECT_TRUE(txt_result[2].is_generic_file_handler()); |
| 915 // Qux app provides a handler for all types. |
| 916 EXPECT_EQ("Qux", txt_result[3].task_title()); |
| 917 EXPECT_TRUE(txt_result[3].is_generic_file_handler()); |
| 918 |
| 919 // Test case with .jpg file |
| 920 PathAndMimeTypeSet jpg_path_mime_set; |
| 921 jpg_path_mime_set.insert( |
| 922 std::make_pair( |
| 923 drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII( |
| 924 "foo.jpg"), |
| 925 "image/jpeg")); |
| 926 std::vector<FullTaskDescriptor> jpg_result; |
| 927 FindFileHandlerTasks(&test_profile_, jpg_path_mime_set, &jpg_result); |
| 928 EXPECT_EQ(3U, jpg_result.size()); |
| 929 // Foo app provides a handler for all types. |
| 930 EXPECT_EQ("Foo", jpg_result[0].task_title()); |
| 931 EXPECT_TRUE(jpg_result[0].is_generic_file_handler()); |
| 932 // Baz app provides a handler for image/*. A partial wildcarded handler is |
| 933 // treated as non-generic handler. |
| 934 EXPECT_EQ("Baz", jpg_result[1].task_title()); |
| 935 EXPECT_FALSE(jpg_result[1].is_generic_file_handler()); |
| 936 // Qux app provides a handler for all types. |
| 937 EXPECT_EQ("Qux", jpg_result[2].task_title()); |
| 938 EXPECT_TRUE(jpg_result[2].is_generic_file_handler()); |
| 939 } |
| 940 |
| 797 } // namespace file_tasks | 941 } // namespace file_tasks |
| 798 } // namespace file_manager. | 942 } // namespace file_manager. |
| OLD | NEW |