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

Side by Side Diff: chrome/browser/chromeos/file_manager/file_tasks_unittest.cc

Issue 1872223002: Add verbs API to file handlers. Modify the Chrome OS UI so that it displayes the internationalized … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move back to "open-with" for the id of the more actions dialog, as it breaks some browsers tests, a… Created 4 years, 7 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 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 15 matching lines...) Expand all
26 #include "components/prefs/testing_pref_service.h" 26 #include "components/prefs/testing_pref_service.h"
27 #include "content/public/test/test_browser_thread_bundle.h" 27 #include "content/public/test/test_browser_thread_bundle.h"
28 #include "extensions/browser/entry_info.h" 28 #include "extensions/browser/entry_info.h"
29 #include "extensions/browser/extension_prefs.h" 29 #include "extensions/browser/extension_prefs.h"
30 #include "extensions/browser/extension_system.h" 30 #include "extensions/browser/extension_system.h"
31 #include "extensions/common/extension_builder.h" 31 #include "extensions/common/extension_builder.h"
32 #include "google_apis/drive/drive_api_parser.h" 32 #include "google_apis/drive/drive_api_parser.h"
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34 #include "url/gurl.h" 34 #include "url/gurl.h"
35 35
36 using extensions::api::file_manager_private::Verb;
37
36 namespace file_manager { 38 namespace file_manager {
37 namespace file_tasks { 39 namespace file_tasks {
38 namespace { 40 namespace {
39 41
40 // Registers the default task preferences. Used for testing 42 // Registers the default task preferences. Used for testing
41 // ChooseAndSetDefaultTask(). 43 // ChooseAndSetDefaultTask().
42 void RegisterDefaultTaskPreferences(TestingPrefServiceSimple* pref_service) { 44 void RegisterDefaultTaskPreferences(TestingPrefServiceSimple* pref_service) {
43 DCHECK(pref_service); 45 DCHECK(pref_service);
44 46
45 pref_service->registry()->RegisterDictionaryPref( 47 pref_service->registry()->RegisterDictionaryPref(
(...skipping 11 matching lines...) Expand all
57 59
58 pref_service->Set(prefs::kDefaultTasksByMimeType, mime_types); 60 pref_service->Set(prefs::kDefaultTasksByMimeType, mime_types);
59 pref_service->Set(prefs::kDefaultTasksBySuffix, suffixes); 61 pref_service->Set(prefs::kDefaultTasksBySuffix, suffixes);
60 } 62 }
61 63
62 } // namespace 64 } // namespace
63 65
64 TEST(FileManagerFileTasksTest, 66 TEST(FileManagerFileTasksTest,
65 FullTaskDescriptor_NonDriveAppWithIconAndDefault) { 67 FullTaskDescriptor_NonDriveAppWithIconAndDefault) {
66 FullTaskDescriptor full_descriptor( 68 FullTaskDescriptor full_descriptor(
67 TaskDescriptor("app-id", 69 TaskDescriptor("app-id", TASK_TYPE_FILE_BROWSER_HANDLER, "action-id"),
68 TASK_TYPE_FILE_BROWSER_HANDLER, 70 "task title", Verb::VERB_OPEN_WITH, GURL("http://example.com/icon.png"),
69 "action-id"), 71 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 72
75 const std::string task_id = 73 const std::string task_id =
76 TaskDescriptorToId(full_descriptor.task_descriptor()); 74 TaskDescriptorToId(full_descriptor.task_descriptor());
77 EXPECT_EQ("app-id|file|action-id", task_id); 75 EXPECT_EQ("app-id|file|action-id", task_id);
78 EXPECT_EQ("http://example.com/icon.png", full_descriptor.icon_url().spec()); 76 EXPECT_EQ("http://example.com/icon.png", full_descriptor.icon_url().spec());
79 EXPECT_EQ("task title", full_descriptor.task_title()); 77 EXPECT_EQ("task title", full_descriptor.task_title());
78 EXPECT_EQ(Verb::VERB_OPEN_WITH, full_descriptor.task_verb());
80 EXPECT_TRUE(full_descriptor.is_default()); 79 EXPECT_TRUE(full_descriptor.is_default());
81 } 80 }
82 81
83 TEST(FileManagerFileTasksTest, 82 TEST(FileManagerFileTasksTest,
84 FullTaskDescriptor_DriveAppWithoutIconAndNotDefault) { 83 FullTaskDescriptor_DriveAppWithoutIconAndNotDefault) {
85 FullTaskDescriptor full_descriptor( 84 FullTaskDescriptor full_descriptor(
86 TaskDescriptor("app-id", 85 TaskDescriptor("app-id", TASK_TYPE_DRIVE_APP, "action-id"), "task title",
87 TASK_TYPE_DRIVE_APP, 86 Verb::VERB_OPEN_WITH,
88 "action-id"),
89 "task title",
90 GURL(), // No icon URL. 87 GURL(), // No icon URL.
91 false /* is_default */, 88 false /* is_default */, false /* is_generic_file_handler */);
92 false /* is_generic_file_handler */);
93 89
94 const std::string task_id = 90 const std::string task_id =
95 TaskDescriptorToId(full_descriptor.task_descriptor()); 91 TaskDescriptorToId(full_descriptor.task_descriptor());
96 EXPECT_EQ("app-id|drive|action-id", task_id); 92 EXPECT_EQ("app-id|drive|action-id", task_id);
97 EXPECT_TRUE(full_descriptor.icon_url().is_empty()); 93 EXPECT_TRUE(full_descriptor.icon_url().is_empty());
98 EXPECT_EQ("task title", full_descriptor.task_title()); 94 EXPECT_EQ("task title", full_descriptor.task_title());
95 EXPECT_EQ(Verb::VERB_OPEN_WITH, full_descriptor.task_verb());
99 EXPECT_FALSE(full_descriptor.is_default()); 96 EXPECT_FALSE(full_descriptor.is_default());
100 } 97 }
101 98
102 TEST(FileManagerFileTasksTest, MakeTaskID) { 99 TEST(FileManagerFileTasksTest, MakeTaskID) {
103 EXPECT_EQ("app-id|file|action-id", 100 EXPECT_EQ("app-id|file|action-id",
104 MakeTaskID("app-id", TASK_TYPE_FILE_BROWSER_HANDLER, "action-id")); 101 MakeTaskID("app-id", TASK_TYPE_FILE_BROWSER_HANDLER, "action-id"));
105 EXPECT_EQ("app-id|app|action-id", 102 EXPECT_EQ("app-id|app|action-id",
106 MakeTaskID("app-id", TASK_TYPE_FILE_HANDLER, "action-id")); 103 MakeTaskID("app-id", TASK_TYPE_FILE_HANDLER, "action-id"));
107 EXPECT_EQ("app-id|drive|action-id", 104 EXPECT_EQ("app-id|drive|action-id",
108 MakeTaskID("app-id", TASK_TYPE_DRIVE_APP, "action-id")); 105 MakeTaskID("app-id", TASK_TYPE_DRIVE_APP, "action-id"));
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 252
256 // Text.app and Nice.app were found for "foo.txt". 253 // Text.app and Nice.app were found for "foo.txt".
257 TaskDescriptor text_app_task("text-app-id", 254 TaskDescriptor text_app_task("text-app-id",
258 TASK_TYPE_FILE_HANDLER, 255 TASK_TYPE_FILE_HANDLER,
259 "action-id"); 256 "action-id");
260 TaskDescriptor nice_app_task("nice-app-id", 257 TaskDescriptor nice_app_task("nice-app-id",
261 TASK_TYPE_FILE_HANDLER, 258 TASK_TYPE_FILE_HANDLER,
262 "action-id"); 259 "action-id");
263 std::vector<FullTaskDescriptor> tasks; 260 std::vector<FullTaskDescriptor> tasks;
264 tasks.push_back(FullTaskDescriptor( 261 tasks.push_back(FullTaskDescriptor(
265 text_app_task, 262 text_app_task, "Text.app", Verb::VERB_OPEN_WITH,
266 "Text.app", 263 GURL("http://example.com/text_app.png"), false /* is_default */,
267 GURL("http://example.com/text_app.png"),
268 false /* is_default */,
269 false /* is_generic_file_handler */)); 264 false /* is_generic_file_handler */));
270 tasks.push_back(FullTaskDescriptor( 265 tasks.push_back(FullTaskDescriptor(
271 nice_app_task, 266 nice_app_task, "Nice.app", Verb::VERB_ADD_TO,
272 "Nice.app", 267 GURL("http://example.com/nice_app.png"), false /* is_default */,
273 GURL("http://example.com/nice_app.png"),
274 false /* is_default */,
275 false /* is_generic_file_handler */)); 268 false /* is_generic_file_handler */));
276 std::vector<extensions::EntryInfo> entries; 269 std::vector<extensions::EntryInfo> entries;
277 entries.push_back(extensions::EntryInfo( 270 entries.push_back(extensions::EntryInfo(
278 base::FilePath::FromUTF8Unsafe("foo.txt"), "text/plain", false)); 271 base::FilePath::FromUTF8Unsafe("foo.txt"), "text/plain", false));
279 272
280 // None of them should be chosen as default, as nothing is set in the 273 // None of them should be chosen as default, as nothing is set in the
281 // preferences. 274 // preferences.
282 ChooseAndSetDefaultTask(pref_service, entries, &tasks); 275 ChooseAndSetDefaultTask(pref_service, entries, &tasks);
283 EXPECT_FALSE(tasks[0].is_default()); 276 EXPECT_FALSE(tasks[0].is_default());
284 EXPECT_FALSE(tasks[1].is_default()); 277 EXPECT_FALSE(tasks[1].is_default());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 TEST(FileManagerFileTasksTest, ChooseAndSetDefaultTask_FallbackFileBrowser) { 316 TEST(FileManagerFileTasksTest, ChooseAndSetDefaultTask_FallbackFileBrowser) {
324 TestingPrefServiceSimple pref_service; 317 TestingPrefServiceSimple pref_service;
325 RegisterDefaultTaskPreferences(&pref_service); 318 RegisterDefaultTaskPreferences(&pref_service);
326 319
327 // Files.app's internal file browser handler was found for "foo.txt". 320 // Files.app's internal file browser handler was found for "foo.txt".
328 TaskDescriptor files_app_task(kFileManagerAppId, 321 TaskDescriptor files_app_task(kFileManagerAppId,
329 TASK_TYPE_FILE_BROWSER_HANDLER, 322 TASK_TYPE_FILE_BROWSER_HANDLER,
330 "view-in-browser"); 323 "view-in-browser");
331 std::vector<FullTaskDescriptor> tasks; 324 std::vector<FullTaskDescriptor> tasks;
332 tasks.push_back(FullTaskDescriptor( 325 tasks.push_back(FullTaskDescriptor(
333 files_app_task, 326 files_app_task, "View in browser", Verb::VERB_OPEN_WITH,
334 "View in browser", 327 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 */)); 328 false /* is_generic_file_handler */));
338 std::vector<extensions::EntryInfo> entries; 329 std::vector<extensions::EntryInfo> entries;
339 entries.push_back(extensions::EntryInfo( 330 entries.push_back(extensions::EntryInfo(
340 base::FilePath::FromUTF8Unsafe("foo.txt"), "text/plain", false)); 331 base::FilePath::FromUTF8Unsafe("foo.txt"), "text/plain", false));
341 332
342 // The internal file browser handler should be chosen as default, as it's a 333 // The internal file browser handler should be chosen as default, as it's a
343 // fallback file browser handler. 334 // fallback file browser handler.
344 ChooseAndSetDefaultTask(pref_service, entries, &tasks); 335 ChooseAndSetDefaultTask(pref_service, entries, &tasks);
345 EXPECT_TRUE(tasks[0].is_default()); 336 EXPECT_TRUE(tasks[0].is_default());
346 } 337 }
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII("dir"), 1040 drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII("dir"),
1050 "", true)); 1041 "", true));
1051 std::vector<FullTaskDescriptor> dir_result; 1042 std::vector<FullTaskDescriptor> dir_result;
1052 FindFileHandlerTasks(&test_profile_, dir_entries, &dir_result); 1043 FindFileHandlerTasks(&test_profile_, dir_entries, &dir_result);
1053 ASSERT_EQ(1U, dir_result.size()); 1044 ASSERT_EQ(1U, dir_result.size());
1054 // Confirm that only Bar.app is found and that it is a generic file handler. 1045 // 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); 1046 EXPECT_EQ(kBarId, dir_result[0].task_descriptor().app_id);
1056 EXPECT_TRUE(dir_result[0].is_generic_file_handler()); 1047 EXPECT_TRUE(dir_result[0].is_generic_file_handler());
1057 } 1048 }
1058 1049
1050 // The basic logic is similar to a test case for FindDriveAppTasks above.
1051 TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTask_Verbs) {
1052 // kFooId copied from FindFileHandlerTasks test above.
1053 const char kFooId[] = "hhgbjpmdppecanaaogonaigmmifgpaph";
1054
1055 // Foo.app can handle "text/plain" and "text/html".
1056 extensions::ExtensionBuilder foo_app;
1057 foo_app.SetManifest(
1058 extensions::DictionaryBuilder()
1059 .Set("name", "Foo")
1060 .Set("version", "1.0.0")
1061 .Set("manifest_version", 2)
1062 .Set("app", extensions::DictionaryBuilder()
1063 .Set("background",
1064 extensions::DictionaryBuilder()
1065 .Set("scripts", extensions::ListBuilder()
1066 .Append("background.js")
1067 .Build())
1068 .Build())
1069 .Build())
1070 .Set(
1071 "file_handlers",
1072 extensions::DictionaryBuilder()
1073 .Set("any",
1074 extensions::DictionaryBuilder()
1075 .Set("types",
1076 extensions::ListBuilder().Append("*").Build())
1077 .Set("verb", "add_to")
1078 .Build())
1079 .Set("any_with_directories",
1080 extensions::DictionaryBuilder()
1081 .SetBoolean("include_directories", true)
1082 .Set("types",
1083 extensions::ListBuilder().Append("*").Build())
1084 .Set("verb", "pack_with")
1085 .Build())
1086 .Set("all_text", extensions::DictionaryBuilder()
1087 .Set("title", "Text")
1088 .Set("types", extensions::ListBuilder()
1089 .Append("text/plain")
1090 .Append("text/html")
1091 .Build())
1092 .Set("verb", "add_to")
1093 .Build())
1094 .Set("plain_text", extensions::DictionaryBuilder()
1095 .Set("title", "Plain")
1096 .Set("types", extensions::ListBuilder()
1097 .Append("text/plain")
1098 .Build())
1099 .Set("verb", "open_with")
1100 .Build())
1101 .Set("html_text_duplicate_verb",
1102 extensions::DictionaryBuilder()
1103 .Set("title", "Html")
1104 .Set("types", extensions::ListBuilder()
1105 .Append("text/html")
1106 .Build())
1107 .Set("verb", "add_to")
1108 .Build())
1109 .Set("share_plain_text",
1110 extensions::DictionaryBuilder()
1111 .Set("title", "Share Plain")
1112 .Set("types", extensions::ListBuilder()
1113 .Append("text/plain")
1114 .Build())
1115 .Set("verb", "share_with")
1116 .Build())
1117 .Build())
1118 .Build());
1119 foo_app.SetID(kFooId);
1120 extension_service_->AddExtension(foo_app.Build().get());
1121
1122 // Find app with corresponding verbs for a "text/plain" file.
1123 // Foo.app with ADD_TO, OPEN_WITH, PACK_WITH and SHARE_WITH should be found,
1124 // but only one ADD_TO that is not a generic handler will be taken into
1125 // account, even though there are 2 ADD_TO matches for "text/plain".
1126 std::vector<extensions::EntryInfo> entries;
1127 entries.push_back(
1128 extensions::EntryInfo(drive::util::GetDriveMountPointPath(&test_profile_)
1129 .AppendASCII("foo.txt"),
1130 "text/plain", false));
1131
1132 std::vector<FullTaskDescriptor> tasks;
1133 FindFileHandlerTasks(&test_profile_, entries, &tasks);
1134
1135 ASSERT_EQ(4U, tasks.size());
1136 EXPECT_EQ(kFooId, tasks[0].task_descriptor().app_id);
1137 EXPECT_EQ("Foo", tasks[0].task_title());
1138 EXPECT_EQ(Verb::VERB_ADD_TO, tasks[0].task_verb());
1139 EXPECT_EQ(kFooId, tasks[1].task_descriptor().app_id);
1140 EXPECT_EQ("Foo", tasks[1].task_title());
1141 EXPECT_EQ(Verb::VERB_OPEN_WITH, tasks[1].task_verb());
1142 EXPECT_EQ(kFooId, tasks[2].task_descriptor().app_id);
1143 EXPECT_EQ("Foo", tasks[2].task_title());
1144 EXPECT_EQ(Verb::VERB_PACK_WITH, tasks[2].task_verb());
1145 EXPECT_EQ(kFooId, tasks[3].task_descriptor().app_id);
1146 EXPECT_EQ("Foo", tasks[3].task_title());
1147 EXPECT_EQ(Verb::VERB_SHARE_WITH, tasks[3].task_verb());
1148
1149 // Find app with corresponding verbs for a "text/html" file.
1150 // Foo.app with ADD_TO and PACK_WITH should be found, but only the first
1151 // ADD_TO that is a good match will be taken into account, even though there
1152 // are 3 ADD_TO matches for "text/html".
1153 entries.clear();
1154 entries.push_back(
1155 extensions::EntryInfo(drive::util::GetDriveMountPointPath(&test_profile_)
1156 .AppendASCII("foo.html"),
1157 "text/html", false));
1158 tasks.clear();
1159 FindFileHandlerTasks(&test_profile_, entries, &tasks);
1160
1161 ASSERT_EQ(2U, tasks.size());
1162 EXPECT_EQ(kFooId, tasks[0].task_descriptor().app_id);
1163 EXPECT_EQ("Foo", tasks[0].task_title());
1164 EXPECT_EQ(Verb::VERB_ADD_TO, tasks[0].task_verb());
1165 EXPECT_EQ(kFooId, tasks[1].task_descriptor().app_id);
1166 EXPECT_EQ("Foo", tasks[1].task_title());
1167 EXPECT_EQ(Verb::VERB_PACK_WITH, tasks[1].task_verb());
1168
1169 // Find app with corresponding verbs for directories.
1170 // Foo.app with only PACK_WITH should be found.
1171 entries.clear();
1172 entries.push_back(extensions::EntryInfo(
1173 drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII("dir"),
1174 "", true));
1175 tasks.clear();
1176 FindFileHandlerTasks(&test_profile_, entries, &tasks);
1177
1178 ASSERT_EQ(1U, tasks.size());
1179 EXPECT_EQ(kFooId, tasks[0].task_descriptor().app_id);
1180 EXPECT_EQ("Foo", tasks[0].task_title());
1181 EXPECT_EQ(Verb::VERB_PACK_WITH, tasks[0].task_verb());
1182 }
1183
1059 } // namespace file_tasks 1184 } // namespace file_tasks
1060 } // namespace file_manager. 1185 } // namespace file_manager.
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/file_tasks.cc ('k') | chrome/common/extensions/api/file_manager_private.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698