Chromium Code Reviews| 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 <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 | 57 |
| 58 pref_service->Set(prefs::kDefaultTasksByMimeType, mime_types); | 58 pref_service->Set(prefs::kDefaultTasksByMimeType, mime_types); |
| 59 pref_service->Set(prefs::kDefaultTasksBySuffix, suffixes); | 59 pref_service->Set(prefs::kDefaultTasksBySuffix, suffixes); |
| 60 } | 60 } |
| 61 | 61 |
| 62 } // namespace | 62 } // namespace |
| 63 | 63 |
| 64 TEST(FileManagerFileTasksTest, | 64 TEST(FileManagerFileTasksTest, |
| 65 FullTaskDescriptor_NonDriveAppWithIconAndDefault) { | 65 FullTaskDescriptor_NonDriveAppWithIconAndDefault) { |
| 66 FullTaskDescriptor full_descriptor( | 66 FullTaskDescriptor full_descriptor( |
| 67 TaskDescriptor("app-id", | 67 TaskDescriptor("app-id", TASK_TYPE_FILE_BROWSER_HANDLER, "action-id"), |
| 68 TASK_TYPE_FILE_BROWSER_HANDLER, | 68 "task title", "OPEN_WITH", GURL("http://example.com/icon.png"), |
|
Devlin
2016/05/16 16:17:32
OPEN_WITH isn't a valid verb anymore (the suggesti
cmihail
2016/05/18 02:35:31
Done.
| |
| 69 "action-id"), | 69 true /* is_default */, false /* is_generic_file_handler */); |
| 70 "task title", | |
| 71 GURL("http://example.com/icon.png"), | |
| 72 true /* is_default */, | |
| 73 false /* is_generic_file_handler */); | |
| 74 | 70 |
| 75 const std::string task_id = | 71 const std::string task_id = |
| 76 TaskDescriptorToId(full_descriptor.task_descriptor()); | 72 TaskDescriptorToId(full_descriptor.task_descriptor()); |
| 77 EXPECT_EQ("app-id|file|action-id", task_id); | 73 EXPECT_EQ("app-id|file|action-id", task_id); |
| 78 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()); |
| 79 EXPECT_EQ("task title", full_descriptor.task_title()); | 75 EXPECT_EQ("task title", full_descriptor.task_title()); |
| 76 EXPECT_EQ("OPEN_WITH", full_descriptor.task_verb()); | |
| 80 EXPECT_TRUE(full_descriptor.is_default()); | 77 EXPECT_TRUE(full_descriptor.is_default()); |
| 81 } | 78 } |
| 82 | 79 |
| 83 TEST(FileManagerFileTasksTest, | 80 TEST(FileManagerFileTasksTest, |
| 84 FullTaskDescriptor_DriveAppWithoutIconAndNotDefault) { | 81 FullTaskDescriptor_DriveAppWithoutIconAndNotDefault) { |
| 85 FullTaskDescriptor full_descriptor( | 82 FullTaskDescriptor full_descriptor( |
| 86 TaskDescriptor("app-id", | 83 TaskDescriptor("app-id", TASK_TYPE_DRIVE_APP, "action-id"), "task title", |
| 87 TASK_TYPE_DRIVE_APP, | 84 "OPEN_WITH", |
| 88 "action-id"), | |
| 89 "task title", | |
| 90 GURL(), // No icon URL. | 85 GURL(), // No icon URL. |
| 91 false /* is_default */, | 86 false /* is_default */, false /* is_generic_file_handler */); |
| 92 false /* is_generic_file_handler */); | |
| 93 | 87 |
| 94 const std::string task_id = | 88 const std::string task_id = |
| 95 TaskDescriptorToId(full_descriptor.task_descriptor()); | 89 TaskDescriptorToId(full_descriptor.task_descriptor()); |
| 96 EXPECT_EQ("app-id|drive|action-id", task_id); | 90 EXPECT_EQ("app-id|drive|action-id", task_id); |
| 97 EXPECT_TRUE(full_descriptor.icon_url().is_empty()); | 91 EXPECT_TRUE(full_descriptor.icon_url().is_empty()); |
| 98 EXPECT_EQ("task title", full_descriptor.task_title()); | 92 EXPECT_EQ("task title", full_descriptor.task_title()); |
| 93 EXPECT_EQ("OPEN_WITH", full_descriptor.task_verb()); | |
| 99 EXPECT_FALSE(full_descriptor.is_default()); | 94 EXPECT_FALSE(full_descriptor.is_default()); |
| 100 } | 95 } |
| 101 | 96 |
| 102 TEST(FileManagerFileTasksTest, MakeTaskID) { | 97 TEST(FileManagerFileTasksTest, MakeTaskID) { |
| 103 EXPECT_EQ("app-id|file|action-id", | 98 EXPECT_EQ("app-id|file|action-id", |
| 104 MakeTaskID("app-id", TASK_TYPE_FILE_BROWSER_HANDLER, "action-id")); | 99 MakeTaskID("app-id", TASK_TYPE_FILE_BROWSER_HANDLER, "action-id")); |
| 105 EXPECT_EQ("app-id|app|action-id", | 100 EXPECT_EQ("app-id|app|action-id", |
| 106 MakeTaskID("app-id", TASK_TYPE_FILE_HANDLER, "action-id")); | 101 MakeTaskID("app-id", TASK_TYPE_FILE_HANDLER, "action-id")); |
| 107 EXPECT_EQ("app-id|drive|action-id", | 102 EXPECT_EQ("app-id|drive|action-id", |
| 108 MakeTaskID("app-id", TASK_TYPE_DRIVE_APP, "action-id")); | 103 MakeTaskID("app-id", TASK_TYPE_DRIVE_APP, "action-id")); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 RegisterDefaultTaskPreferences(&pref_service); | 249 RegisterDefaultTaskPreferences(&pref_service); |
| 255 | 250 |
| 256 // Text.app and Nice.app were found for "foo.txt". | 251 // Text.app and Nice.app were found for "foo.txt". |
| 257 TaskDescriptor text_app_task("text-app-id", | 252 TaskDescriptor text_app_task("text-app-id", |
| 258 TASK_TYPE_FILE_HANDLER, | 253 TASK_TYPE_FILE_HANDLER, |
| 259 "action-id"); | 254 "action-id"); |
| 260 TaskDescriptor nice_app_task("nice-app-id", | 255 TaskDescriptor nice_app_task("nice-app-id", |
| 261 TASK_TYPE_FILE_HANDLER, | 256 TASK_TYPE_FILE_HANDLER, |
| 262 "action-id"); | 257 "action-id"); |
| 263 std::vector<FullTaskDescriptor> tasks; | 258 std::vector<FullTaskDescriptor> tasks; |
| 264 tasks.push_back(FullTaskDescriptor( | 259 tasks.push_back(FullTaskDescriptor(text_app_task, "Text.app", "OPEN_WITH", |
| 265 text_app_task, | 260 GURL("http://example.com/text_app.png"), |
| 266 "Text.app", | 261 false /* is_default */, |
| 267 GURL("http://example.com/text_app.png"), | 262 false /* is_generic_file_handler */)); |
| 268 false /* is_default */, | 263 tasks.push_back(FullTaskDescriptor(nice_app_task, "Nice.app", "ADD_TO", |
| 269 false /* is_generic_file_handler */)); | 264 GURL("http://example.com/nice_app.png"), |
| 270 tasks.push_back(FullTaskDescriptor( | 265 false /* is_default */, |
| 271 nice_app_task, | 266 false /* is_generic_file_handler */)); |
| 272 "Nice.app", | |
| 273 GURL("http://example.com/nice_app.png"), | |
| 274 false /* is_default */, | |
| 275 false /* is_generic_file_handler */)); | |
| 276 std::vector<extensions::EntryInfo> entries; | 267 std::vector<extensions::EntryInfo> entries; |
| 277 entries.push_back(extensions::EntryInfo( | 268 entries.push_back(extensions::EntryInfo( |
| 278 base::FilePath::FromUTF8Unsafe("foo.txt"), "text/plain", false)); | 269 base::FilePath::FromUTF8Unsafe("foo.txt"), "text/plain", false)); |
| 279 | 270 |
| 280 // None of them should be chosen as default, as nothing is set in the | 271 // None of them should be chosen as default, as nothing is set in the |
| 281 // preferences. | 272 // preferences. |
| 282 ChooseAndSetDefaultTask(pref_service, entries, &tasks); | 273 ChooseAndSetDefaultTask(pref_service, entries, &tasks); |
| 283 EXPECT_FALSE(tasks[0].is_default()); | 274 EXPECT_FALSE(tasks[0].is_default()); |
| 284 EXPECT_FALSE(tasks[1].is_default()); | 275 EXPECT_FALSE(tasks[1].is_default()); |
| 285 | 276 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 TEST(FileManagerFileTasksTest, ChooseAndSetDefaultTask_FallbackFileBrowser) { | 314 TEST(FileManagerFileTasksTest, ChooseAndSetDefaultTask_FallbackFileBrowser) { |
| 324 TestingPrefServiceSimple pref_service; | 315 TestingPrefServiceSimple pref_service; |
| 325 RegisterDefaultTaskPreferences(&pref_service); | 316 RegisterDefaultTaskPreferences(&pref_service); |
| 326 | 317 |
| 327 // Files.app's internal file browser handler was found for "foo.txt". | 318 // Files.app's internal file browser handler was found for "foo.txt". |
| 328 TaskDescriptor files_app_task(kFileManagerAppId, | 319 TaskDescriptor files_app_task(kFileManagerAppId, |
| 329 TASK_TYPE_FILE_BROWSER_HANDLER, | 320 TASK_TYPE_FILE_BROWSER_HANDLER, |
| 330 "view-in-browser"); | 321 "view-in-browser"); |
| 331 std::vector<FullTaskDescriptor> tasks; | 322 std::vector<FullTaskDescriptor> tasks; |
| 332 tasks.push_back(FullTaskDescriptor( | 323 tasks.push_back(FullTaskDescriptor( |
| 333 files_app_task, | 324 files_app_task, "View in browser", "OPEN_WITH", |
| 334 "View in browser", | 325 GURL("http://example.com/some_icon.png"), false /* is_default */, |
| 335 GURL("http://example.com/some_icon.png"), | |
| 336 false /* is_default */, | |
| 337 false /* is_generic_file_handler */)); | 326 false /* is_generic_file_handler */)); |
| 338 std::vector<extensions::EntryInfo> entries; | 327 std::vector<extensions::EntryInfo> entries; |
| 339 entries.push_back(extensions::EntryInfo( | 328 entries.push_back(extensions::EntryInfo( |
| 340 base::FilePath::FromUTF8Unsafe("foo.txt"), "text/plain", false)); | 329 base::FilePath::FromUTF8Unsafe("foo.txt"), "text/plain", false)); |
| 341 | 330 |
| 342 // The internal file browser handler should be chosen as default, as it's a | 331 // The internal file browser handler should be chosen as default, as it's a |
| 343 // fallback file browser handler. | 332 // fallback file browser handler. |
| 344 ChooseAndSetDefaultTask(pref_service, entries, &tasks); | 333 ChooseAndSetDefaultTask(pref_service, entries, &tasks); |
| 345 EXPECT_TRUE(tasks[0].is_default()); | 334 EXPECT_TRUE(tasks[0].is_default()); |
| 346 } | 335 } |
| (...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1049 drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII("dir"), | 1038 drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII("dir"), |
| 1050 "", true)); | 1039 "", true)); |
| 1051 std::vector<FullTaskDescriptor> dir_result; | 1040 std::vector<FullTaskDescriptor> dir_result; |
| 1052 FindFileHandlerTasks(&test_profile_, dir_entries, &dir_result); | 1041 FindFileHandlerTasks(&test_profile_, dir_entries, &dir_result); |
| 1053 ASSERT_EQ(1U, dir_result.size()); | 1042 ASSERT_EQ(1U, dir_result.size()); |
| 1054 // Confirm that only Bar.app is found and that it is a generic file handler. | 1043 // Confirm that only Bar.app is found and that it is a generic file handler. |
| 1055 EXPECT_EQ(kBarId, dir_result[0].task_descriptor().app_id); | 1044 EXPECT_EQ(kBarId, dir_result[0].task_descriptor().app_id); |
| 1056 EXPECT_TRUE(dir_result[0].is_generic_file_handler()); | 1045 EXPECT_TRUE(dir_result[0].is_generic_file_handler()); |
| 1057 } | 1046 } |
| 1058 | 1047 |
| 1048 // The basic logic is similar to a test case for FindDriveAppTasks above. | |
| 1049 TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTask_Verbs) { | |
| 1050 // kFooId copied from FindFileHandlerTasks test above. | |
| 1051 const char kFooId[] = "hhgbjpmdppecanaaogonaigmmifgpaph"; | |
| 1052 | |
| 1053 // Foo.app can handle "text/plain" and "text/html". | |
| 1054 extensions::ExtensionBuilder foo_app; | |
| 1055 foo_app.SetManifest( | |
| 1056 extensions::DictionaryBuilder() | |
| 1057 .Set("name", "Foo") | |
| 1058 .Set("version", "1.0.0") | |
| 1059 .Set("manifest_version", 2) | |
| 1060 .Set("app", extensions::DictionaryBuilder() | |
| 1061 .Set("background", | |
| 1062 extensions::DictionaryBuilder() | |
| 1063 .Set("scripts", extensions::ListBuilder() | |
| 1064 .Append("background.js") | |
| 1065 .Build()) | |
| 1066 .Build()) | |
| 1067 .Build()) | |
| 1068 .Set( | |
| 1069 "file_handlers", | |
| 1070 extensions::DictionaryBuilder() | |
| 1071 .Set("any", | |
| 1072 extensions::DictionaryBuilder() | |
| 1073 .Set("types", | |
| 1074 extensions::ListBuilder().Append("*").Build()) | |
| 1075 .Set("verb", "ADD_TO") | |
| 1076 .Build()) | |
| 1077 .Set("any_with_directories", | |
| 1078 extensions::DictionaryBuilder() | |
| 1079 .SetBoolean("include_directories", true) | |
| 1080 .Set("types", | |
| 1081 extensions::ListBuilder().Append("*").Build()) | |
| 1082 .Set("verb", "PACK_WITH") | |
| 1083 .Build()) | |
| 1084 .Set("all_text", extensions::DictionaryBuilder() | |
| 1085 .Set("title", "Text") | |
| 1086 .Set("types", extensions::ListBuilder() | |
| 1087 .Append("text/plain") | |
| 1088 .Append("text/html") | |
| 1089 .Build()) | |
| 1090 .Set("verb", "ADD_TO") | |
| 1091 .Build()) | |
| 1092 .Set("plain_text", extensions::DictionaryBuilder() | |
| 1093 .Set("title", "Plain") | |
| 1094 .Set("types", extensions::ListBuilder() | |
| 1095 .Append("text/plain") | |
| 1096 .Build()) | |
| 1097 .Set("verb", "OPEN_WITH") | |
| 1098 .Build()) | |
| 1099 .Set("html_text_duplicate_verb", | |
| 1100 extensions::DictionaryBuilder() | |
| 1101 .Set("title", "Html") | |
| 1102 .Set("types", extensions::ListBuilder() | |
| 1103 .Append("text/html") | |
| 1104 .Build()) | |
| 1105 .Set("verb", "ADD_TO") | |
| 1106 .Build()) | |
| 1107 .Build()) | |
| 1108 .Build()); | |
| 1109 foo_app.SetID(kFooId); | |
| 1110 extension_service_->AddExtension(foo_app.Build().get()); | |
| 1111 | |
| 1112 // Find app with corresponding verbs for a "text/plain" file. | |
| 1113 // Foo.app with ADD_TO, OPEN_WITH and PACK_WITH should be found, but only | |
| 1114 // one ADD_TO that is not a generic handler will be taken into account, | |
| 1115 // even though there are 2 ADD_TO matches for "text/plain". | |
| 1116 std::vector<extensions::EntryInfo> entries; | |
| 1117 entries.push_back( | |
| 1118 extensions::EntryInfo(drive::util::GetDriveMountPointPath(&test_profile_) | |
| 1119 .AppendASCII("foo.txt"), | |
| 1120 "text/plain", false)); | |
| 1121 | |
| 1122 std::vector<FullTaskDescriptor> tasks; | |
| 1123 FindFileHandlerTasks(&test_profile_, entries, &tasks); | |
| 1124 | |
| 1125 ASSERT_EQ(3U, tasks.size()); | |
| 1126 EXPECT_EQ(kFooId, tasks[0].task_descriptor().app_id); | |
| 1127 EXPECT_EQ("Foo", tasks[0].task_title()); | |
| 1128 EXPECT_EQ("ADD_TO", tasks[0].task_verb()); | |
| 1129 EXPECT_EQ(kFooId, tasks[1].task_descriptor().app_id); | |
| 1130 EXPECT_EQ("Foo", tasks[1].task_title()); | |
| 1131 EXPECT_EQ("OPEN_WITH", tasks[1].task_verb()); | |
| 1132 EXPECT_EQ(kFooId, tasks[2].task_descriptor().app_id); | |
| 1133 EXPECT_EQ("Foo", tasks[2].task_title()); | |
| 1134 EXPECT_EQ("PACK_WITH", tasks[2].task_verb()); | |
| 1135 | |
| 1136 // Find app with corresponding verbs for a "text/html" file. | |
| 1137 // Foo.app with ADD_TO and PACK_WITH should be found, but only the first | |
| 1138 // ADD_TO that is a good match will be taken into account, even though there | |
| 1139 // are 3 ADD_TO matches for "text/html". | |
| 1140 entries.clear(); | |
| 1141 entries.push_back( | |
| 1142 extensions::EntryInfo(drive::util::GetDriveMountPointPath(&test_profile_) | |
| 1143 .AppendASCII("foo.html"), | |
| 1144 "text/html", false)); | |
| 1145 tasks.clear(); | |
| 1146 FindFileHandlerTasks(&test_profile_, entries, &tasks); | |
| 1147 | |
| 1148 ASSERT_EQ(2U, tasks.size()); | |
| 1149 EXPECT_EQ(kFooId, tasks[0].task_descriptor().app_id); | |
| 1150 EXPECT_EQ("Foo", tasks[0].task_title()); | |
| 1151 EXPECT_EQ("ADD_TO", tasks[0].task_verb()); | |
| 1152 EXPECT_EQ(kFooId, tasks[1].task_descriptor().app_id); | |
| 1153 EXPECT_EQ("Foo", tasks[1].task_title()); | |
| 1154 EXPECT_EQ("PACK_WITH", tasks[1].task_verb()); | |
| 1155 | |
| 1156 // Find app with corresponding verbs for directories. | |
| 1157 // Foo.app with only PACK_WITH should be found. | |
| 1158 entries.clear(); | |
| 1159 entries.push_back(extensions::EntryInfo( | |
| 1160 drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII("dir"), | |
| 1161 "", true)); | |
| 1162 tasks.clear(); | |
| 1163 FindFileHandlerTasks(&test_profile_, entries, &tasks); | |
| 1164 | |
| 1165 ASSERT_EQ(1U, tasks.size()); | |
| 1166 EXPECT_EQ(kFooId, tasks[0].task_descriptor().app_id); | |
| 1167 EXPECT_EQ("Foo", tasks[0].task_title()); | |
| 1168 EXPECT_EQ("PACK_WITH", tasks[0].task_verb()); | |
| 1169 } | |
| 1170 | |
| 1059 } // namespace file_tasks | 1171 } // namespace file_tasks |
| 1060 } // namespace file_manager. | 1172 } // namespace file_manager. |
| OLD | NEW |