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

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: Remove unused internationalization function on C++ code. Created 4 years, 8 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
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/strings/utf_string_conversions.h"
fukino 2016/04/18 08:06:05 looks unnecessary
cmihail 2016/04/21 09:36:44 Done.
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "chrome/browser/chromeos/drive/file_system_util.h" 14 #include "chrome/browser/chromeos/drive/file_system_util.h"
14 #include "chrome/browser/chromeos/file_manager/app_id.h" 15 #include "chrome/browser/chromeos/file_manager/app_id.h"
15 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" 16 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h"
16 #include "chrome/browser/chromeos/settings/cros_settings.h" 17 #include "chrome/browser/chromeos/settings/cros_settings.h"
17 #include "chrome/browser/chromeos/settings/device_settings_service.h" 18 #include "chrome/browser/chromeos/settings/device_settings_service.h"
18 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
19 #include "chrome/browser/extensions/test_extension_system.h" 20 #include "chrome/browser/extensions/test_extension_system.h"
20 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
21 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 56
56 pref_service->Set(prefs::kDefaultTasksByMimeType, mime_types); 57 pref_service->Set(prefs::kDefaultTasksByMimeType, mime_types);
57 pref_service->Set(prefs::kDefaultTasksBySuffix, suffixes); 58 pref_service->Set(prefs::kDefaultTasksBySuffix, suffixes);
58 } 59 }
59 60
60 } // namespace 61 } // namespace
61 62
62 TEST(FileManagerFileTasksTest, 63 TEST(FileManagerFileTasksTest,
63 FullTaskDescriptor_NonDriveAppWithIconAndDefault) { 64 FullTaskDescriptor_NonDriveAppWithIconAndDefault) {
64 FullTaskDescriptor full_descriptor( 65 FullTaskDescriptor full_descriptor(
65 TaskDescriptor("app-id", 66 TaskDescriptor("app-id", TASK_TYPE_FILE_BROWSER_HANDLER, "action-id"),
66 TASK_TYPE_FILE_BROWSER_HANDLER, 67 "task title", "OPEN_WITH", GURL("http://example.com/icon.png"),
67 "action-id"), 68 true /* is_default */, false /* is_generic_file_handler */);
68 "task title",
69 GURL("http://example.com/icon.png"),
70 true /* is_default */,
71 false /* is_generic_file_handler */);
72 69
73 const std::string task_id = 70 const std::string task_id =
74 TaskDescriptorToId(full_descriptor.task_descriptor()); 71 TaskDescriptorToId(full_descriptor.task_descriptor());
75 EXPECT_EQ("app-id|file|action-id", task_id); 72 EXPECT_EQ("app-id|file|action-id", task_id);
76 EXPECT_EQ("http://example.com/icon.png", full_descriptor.icon_url().spec()); 73 EXPECT_EQ("http://example.com/icon.png", full_descriptor.icon_url().spec());
77 EXPECT_EQ("task title", full_descriptor.task_title()); 74 EXPECT_EQ("task title", full_descriptor.task_title());
75 EXPECT_EQ("OPEN_WITH", full_descriptor.task_verb());
78 EXPECT_TRUE(full_descriptor.is_default()); 76 EXPECT_TRUE(full_descriptor.is_default());
79 } 77 }
80 78
81 TEST(FileManagerFileTasksTest, 79 TEST(FileManagerFileTasksTest,
82 FullTaskDescriptor_DriveAppWithoutIconAndNotDefault) { 80 FullTaskDescriptor_DriveAppWithoutIconAndNotDefault) {
83 FullTaskDescriptor full_descriptor( 81 FullTaskDescriptor full_descriptor(
84 TaskDescriptor("app-id", 82 TaskDescriptor("app-id", TASK_TYPE_DRIVE_APP, "action-id"), "task title",
85 TASK_TYPE_DRIVE_APP, 83 "OPEN_WITH",
86 "action-id"),
87 "task title",
88 GURL(), // No icon URL. 84 GURL(), // No icon URL.
89 false /* is_default */, 85 false /* is_default */, false /* is_generic_file_handler */);
90 false /* is_generic_file_handler */);
91 86
92 const std::string task_id = 87 const std::string task_id =
93 TaskDescriptorToId(full_descriptor.task_descriptor()); 88 TaskDescriptorToId(full_descriptor.task_descriptor());
94 EXPECT_EQ("app-id|drive|action-id", task_id); 89 EXPECT_EQ("app-id|drive|action-id", task_id);
95 EXPECT_TRUE(full_descriptor.icon_url().is_empty()); 90 EXPECT_TRUE(full_descriptor.icon_url().is_empty());
96 EXPECT_EQ("task title", full_descriptor.task_title()); 91 EXPECT_EQ("task title", full_descriptor.task_title());
92 EXPECT_EQ("OPEN_WITH", full_descriptor.task_verb());
97 EXPECT_FALSE(full_descriptor.is_default()); 93 EXPECT_FALSE(full_descriptor.is_default());
98 } 94 }
99 95
100 TEST(FileManagerFileTasksTest, MakeTaskID) { 96 TEST(FileManagerFileTasksTest, MakeTaskID) {
101 EXPECT_EQ("app-id|file|action-id", 97 EXPECT_EQ("app-id|file|action-id",
102 MakeTaskID("app-id", TASK_TYPE_FILE_BROWSER_HANDLER, "action-id")); 98 MakeTaskID("app-id", TASK_TYPE_FILE_BROWSER_HANDLER, "action-id"));
103 EXPECT_EQ("app-id|app|action-id", 99 EXPECT_EQ("app-id|app|action-id",
104 MakeTaskID("app-id", TASK_TYPE_FILE_HANDLER, "action-id")); 100 MakeTaskID("app-id", TASK_TYPE_FILE_HANDLER, "action-id"));
105 EXPECT_EQ("app-id|drive|action-id", 101 EXPECT_EQ("app-id|drive|action-id",
106 MakeTaskID("app-id", TASK_TYPE_DRIVE_APP, "action-id")); 102 MakeTaskID("app-id", TASK_TYPE_DRIVE_APP, "action-id"));
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 RegisterDefaultTaskPreferences(&pref_service); 246 RegisterDefaultTaskPreferences(&pref_service);
251 247
252 // Text.app and Nice.app were found for "foo.txt". 248 // Text.app and Nice.app were found for "foo.txt".
253 TaskDescriptor text_app_task("text-app-id", 249 TaskDescriptor text_app_task("text-app-id",
254 TASK_TYPE_FILE_HANDLER, 250 TASK_TYPE_FILE_HANDLER,
255 "action-id"); 251 "action-id");
256 TaskDescriptor nice_app_task("nice-app-id", 252 TaskDescriptor nice_app_task("nice-app-id",
257 TASK_TYPE_FILE_HANDLER, 253 TASK_TYPE_FILE_HANDLER,
258 "action-id"); 254 "action-id");
259 std::vector<FullTaskDescriptor> tasks; 255 std::vector<FullTaskDescriptor> tasks;
260 tasks.push_back(FullTaskDescriptor( 256 tasks.push_back(FullTaskDescriptor(text_app_task, "Text.app", "OPEN_WITH",
261 text_app_task, 257 GURL("http://example.com/text_app.png"),
262 "Text.app", 258 false /* is_default */,
263 GURL("http://example.com/text_app.png"), 259 false /* is_generic_file_handler */));
264 false /* is_default */, 260 tasks.push_back(FullTaskDescriptor(nice_app_task, "Nice.app", "ADD_TO",
265 false /* is_generic_file_handler */)); 261 GURL("http://example.com/nice_app.png"),
266 tasks.push_back(FullTaskDescriptor( 262 false /* is_default */,
267 nice_app_task, 263 false /* is_generic_file_handler */));
268 "Nice.app",
269 GURL("http://example.com/nice_app.png"),
270 false /* is_default */,
271 false /* is_generic_file_handler */));
272 std::vector<extensions::EntryInfo> entries; 264 std::vector<extensions::EntryInfo> entries;
273 entries.push_back(extensions::EntryInfo( 265 entries.push_back(extensions::EntryInfo(
274 base::FilePath::FromUTF8Unsafe("foo.txt"), "text/plain", false)); 266 base::FilePath::FromUTF8Unsafe("foo.txt"), "text/plain", false));
275 267
276 // None of them should be chosen as default, as nothing is set in the 268 // None of them should be chosen as default, as nothing is set in the
277 // preferences. 269 // preferences.
278 ChooseAndSetDefaultTask(pref_service, entries, &tasks); 270 ChooseAndSetDefaultTask(pref_service, entries, &tasks);
279 EXPECT_FALSE(tasks[0].is_default()); 271 EXPECT_FALSE(tasks[0].is_default());
280 EXPECT_FALSE(tasks[1].is_default()); 272 EXPECT_FALSE(tasks[1].is_default());
281 273
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 TEST(FileManagerFileTasksTest, ChooseAndSetDefaultTask_FallbackFileBrowser) { 311 TEST(FileManagerFileTasksTest, ChooseAndSetDefaultTask_FallbackFileBrowser) {
320 TestingPrefServiceSimple pref_service; 312 TestingPrefServiceSimple pref_service;
321 RegisterDefaultTaskPreferences(&pref_service); 313 RegisterDefaultTaskPreferences(&pref_service);
322 314
323 // Files.app's internal file browser handler was found for "foo.txt". 315 // Files.app's internal file browser handler was found for "foo.txt".
324 TaskDescriptor files_app_task(kFileManagerAppId, 316 TaskDescriptor files_app_task(kFileManagerAppId,
325 TASK_TYPE_FILE_BROWSER_HANDLER, 317 TASK_TYPE_FILE_BROWSER_HANDLER,
326 "view-in-browser"); 318 "view-in-browser");
327 std::vector<FullTaskDescriptor> tasks; 319 std::vector<FullTaskDescriptor> tasks;
328 tasks.push_back(FullTaskDescriptor( 320 tasks.push_back(FullTaskDescriptor(
329 files_app_task, 321 files_app_task, "View in browser", "OPEN_WITH",
330 "View in browser", 322 GURL("http://example.com/some_icon.png"), false /* is_default */,
331 GURL("http://example.com/some_icon.png"),
332 false /* is_default */,
333 false /* is_generic_file_handler */)); 323 false /* is_generic_file_handler */));
334 std::vector<extensions::EntryInfo> entries; 324 std::vector<extensions::EntryInfo> entries;
335 entries.push_back(extensions::EntryInfo( 325 entries.push_back(extensions::EntryInfo(
336 base::FilePath::FromUTF8Unsafe("foo.txt"), "text/plain", false)); 326 base::FilePath::FromUTF8Unsafe("foo.txt"), "text/plain", false));
337 327
338 // The internal file browser handler should be chosen as default, as it's a 328 // The internal file browser handler should be chosen as default, as it's a
339 // fallback file browser handler. 329 // fallback file browser handler.
340 ChooseAndSetDefaultTask(pref_service, entries, &tasks); 330 ChooseAndSetDefaultTask(pref_service, entries, &tasks);
341 EXPECT_TRUE(tasks[0].is_default()); 331 EXPECT_TRUE(tasks[0].is_default());
342 } 332 }
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 // Test case with .jpg file 985 // Test case with .jpg file
996 std::vector<extensions::EntryInfo> jpg_entries; 986 std::vector<extensions::EntryInfo> jpg_entries;
997 jpg_entries.push_back( 987 jpg_entries.push_back(
998 extensions::EntryInfo(drive::util::GetDriveMountPointPath(&test_profile_) 988 extensions::EntryInfo(drive::util::GetDriveMountPointPath(&test_profile_)
999 .AppendASCII("foo.jpg"), 989 .AppendASCII("foo.jpg"),
1000 "image/jpeg", false)); 990 "image/jpeg", false));
1001 std::vector<FullTaskDescriptor> jpg_result; 991 std::vector<FullTaskDescriptor> jpg_result;
1002 FindFileHandlerTasks(&test_profile_, jpg_entries, &jpg_result); 992 FindFileHandlerTasks(&test_profile_, jpg_entries, &jpg_result);
1003 EXPECT_EQ(3U, jpg_result.size()); 993 EXPECT_EQ(3U, jpg_result.size());
1004 // Foo app provides a handler for all types. 994 // Foo app provides a handler for all types.
1005 EXPECT_EQ("Foo", jpg_result[0].task_title()); 995 EXPECT_EQ("Foo", txt_result[0].task_title());
fukino 2016/04/18 08:06:06 Is this an intended modification?
cmihail 2016/04/21 09:36:43 Thx for the catch, didn't observe it.
1006 EXPECT_TRUE(jpg_result[0].is_generic_file_handler()); 996 EXPECT_TRUE(jpg_result[0].is_generic_file_handler());
1007 // Baz app provides a handler for image/*. A partial wildcarded handler is 997 // Baz app provides a handler for image/*. A partial wildcarded handler is
1008 // treated as non-generic handler. 998 // treated as non-generic handler.
1009 EXPECT_EQ("Baz", jpg_result[1].task_title()); 999 EXPECT_EQ("Baz", jpg_result[1].task_title());
1010 EXPECT_FALSE(jpg_result[1].is_generic_file_handler()); 1000 EXPECT_FALSE(jpg_result[1].is_generic_file_handler());
1011 // Qux app provides a handler for all types. 1001 // Qux app provides a handler for all types.
1012 EXPECT_EQ("Qux", jpg_result[2].task_title()); 1002 EXPECT_EQ("Qux", jpg_result[2].task_title());
1013 EXPECT_TRUE(jpg_result[2].is_generic_file_handler()); 1003 EXPECT_TRUE(jpg_result[2].is_generic_file_handler());
1014 1004
1015 // Test case with directories. 1005 // Test case with directories.
1016 std::vector<extensions::EntryInfo> dir_entries; 1006 std::vector<extensions::EntryInfo> dir_entries;
1017 dir_entries.push_back(extensions::EntryInfo( 1007 dir_entries.push_back(extensions::EntryInfo(
1018 drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII("dir"), 1008 drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII("dir"),
1019 "", true)); 1009 "", true));
1020 std::vector<FullTaskDescriptor> dir_result; 1010 std::vector<FullTaskDescriptor> dir_result;
1021 FindFileHandlerTasks(&test_profile_, dir_entries, &dir_result); 1011 FindFileHandlerTasks(&test_profile_, dir_entries, &dir_result);
1022 ASSERT_EQ(1U, dir_result.size()); 1012 ASSERT_EQ(1U, dir_result.size());
1023 // Confirm that only Bar.app is found and that it is a generic file handler. 1013 // Confirm that only Bar.app is found and that it is a generic file handler.
1024 EXPECT_EQ(kBarId, dir_result[0].task_descriptor().app_id); 1014 EXPECT_EQ(kBarId, dir_result[0].task_descriptor().app_id);
1025 EXPECT_TRUE(dir_result[0].is_generic_file_handler()); 1015 EXPECT_TRUE(dir_result[0].is_generic_file_handler());
1026 } 1016 }
1027 1017
1018 // The basic logic is similar to a test case for FindDriveAppTasks above.
1019 TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTask_Verbs) {
1020 // kFooId copied from FindFileHandlerTasks test above.
1021 const char kFooId[] = "hhgbjpmdppecanaaogonaigmmifgpaph";
1022
1023 // Foo.app can handle "text/plain" and "text/html".
1024 extensions::ExtensionBuilder foo_app;
1025 foo_app.SetManifest(
1026 extensions::DictionaryBuilder()
1027 .Set("name", "Foo")
1028 .Set("version", "1.0.0")
1029 .Set("manifest_version", 2)
1030 .Set("app", extensions::DictionaryBuilder()
1031 .Set("background",
1032 extensions::DictionaryBuilder()
1033 .Set("scripts", extensions::ListBuilder()
1034 .Append("background.js")
1035 .Build())
1036 .Build())
1037 .Build())
1038 .Set(
1039 "file_handlers",
1040 extensions::DictionaryBuilder()
1041 .Set("any",
1042 extensions::DictionaryBuilder()
1043 .Set("types",
1044 extensions::ListBuilder().Append("*").Build())
1045 .Set("verb", "ADD_TO")
1046 .Build())
1047 .Set("any_with_directories",
1048 extensions::DictionaryBuilder()
1049 .SetBoolean("include_directories", true)
1050 .Set("types",
1051 extensions::ListBuilder().Append("*").Build())
1052 .Set("verb", "PACK_WITH")
1053 .Build())
1054 .Set("all_text", extensions::DictionaryBuilder()
1055 .Set("title", "Text")
1056 .Set("types", extensions::ListBuilder()
1057 .Append("text/plain")
1058 .Append("text/html")
1059 .Build())
1060 .Set("verb", "ADD_TO")
1061 .Build())
1062 .Set("plain_text", extensions::DictionaryBuilder()
1063 .Set("title", "Plain")
1064 .Set("types", extensions::ListBuilder()
1065 .Append("text/plain")
1066 .Build())
1067 .Set("verb", "OPEN_WITH")
1068 .Build())
1069 .Set("html_text_duplicate_verb",
1070 extensions::DictionaryBuilder()
1071 .Set("title", "Html")
1072 .Set("types", extensions::ListBuilder()
1073 .Append("text/html")
1074 .Build())
1075 .Set("verb", "ADD_TO")
1076 .Build())
1077 .Build())
1078 .Build());
1079 foo_app.SetID(kFooId);
1080 extension_service_->AddExtension(foo_app.Build().get());
1081
1082 // Find app with corresponding verbs for a "text/plain" file.
1083 // Foo.app with ADD_TO, OPEN_WITH and PACK_WITH should be found, but only
1084 // one ADD_TO that is not a generic handler will be taken into account,
1085 // even though there are 2 ADD_TO matches for "text/plain".
1086 std::vector<extensions::EntryInfo> entries;
1087 entries.push_back(
1088 extensions::EntryInfo(drive::util::GetDriveMountPointPath(&test_profile_)
1089 .AppendASCII("foo.txt"),
1090 "text/plain", false));
1091
1092 std::vector<FullTaskDescriptor> tasks;
1093 FindFileHandlerTasks(&test_profile_, entries, &tasks);
1094
1095 ASSERT_EQ(3U, tasks.size());
1096 EXPECT_EQ(kFooId, tasks[0].task_descriptor().app_id);
1097 EXPECT_EQ("Foo", tasks[0].task_title());
1098 EXPECT_EQ("ADD_TO", tasks[0].task_verb());
1099 EXPECT_EQ(kFooId, tasks[1].task_descriptor().app_id);
1100 EXPECT_EQ("Foo", tasks[1].task_title());
1101 EXPECT_EQ("OPEN_WITH", tasks[1].task_verb());
1102 EXPECT_EQ(kFooId, tasks[2].task_descriptor().app_id);
1103 EXPECT_EQ("Foo", tasks[2].task_title());
1104 EXPECT_EQ("PACK_WITH", tasks[2].task_verb());
1105
1106 // Find app with corresponding verbs for a "text/html" file.
1107 // Foo.app with ADD_TO and PACK_WITH should be found, but only the first
1108 // ADD_TO that is a good match will be taken into account, even though there
1109 // are 3 ADD_TO matches for "text/html".
1110 entries.clear();
1111 entries.push_back(
1112 extensions::EntryInfo(drive::util::GetDriveMountPointPath(&test_profile_)
1113 .AppendASCII("foo.html"),
1114 "text/html", false));
1115 tasks.clear();
1116 FindFileHandlerTasks(&test_profile_, entries, &tasks);
1117
1118 ASSERT_EQ(2U, tasks.size());
1119 EXPECT_EQ(kFooId, tasks[0].task_descriptor().app_id);
1120 EXPECT_EQ("Foo", tasks[0].task_title());
1121 EXPECT_EQ("ADD_TO", tasks[0].task_verb());
1122 EXPECT_EQ(kFooId, tasks[1].task_descriptor().app_id);
1123 EXPECT_EQ("Foo", tasks[1].task_title());
1124 EXPECT_EQ("PACK_WITH", tasks[1].task_verb());
1125
1126 // Find app with corresponding verbs for directories.
1127 // Foo.app with only PACK_WITH should be found.
1128 entries.clear();
1129 entries.push_back(extensions::EntryInfo(
1130 drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII("dir"),
1131 "", true));
1132 tasks.clear();
1133 FindFileHandlerTasks(&test_profile_, entries, &tasks);
1134
1135 ASSERT_EQ(1U, tasks.size());
1136 EXPECT_EQ(kFooId, tasks[0].task_descriptor().app_id);
1137 EXPECT_EQ("Foo", tasks[0].task_title());
1138 EXPECT_EQ("PACK_WITH", tasks[0].task_verb());
1139 }
1140
1028 } // namespace file_tasks 1141 } // namespace file_tasks
1029 } // namespace file_manager. 1142 } // namespace file_manager.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698