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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/file_manager/file_tasks_unittest.cc
diff --git a/chrome/browser/chromeos/file_manager/file_tasks_unittest.cc b/chrome/browser/chromeos/file_manager/file_tasks_unittest.cc
index 0bfc3330f9ee271375b16fa65065fb40e05a2217..e4021a3be13a85c7ce30a8ca2a2d9af4fb76d9df 100644
--- a/chrome/browser/chromeos/file_manager/file_tasks_unittest.cc
+++ b/chrome/browser/chromeos/file_manager/file_tasks_unittest.cc
@@ -9,6 +9,7 @@
#include <utility>
#include "base/command_line.h"
+#include "base/strings/utf_string_conversions.h"
fukino 2016/04/18 08:06:05 looks unnecessary
cmihail 2016/04/21 09:36:44 Done.
#include "base/values.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/file_manager/app_id.h"
@@ -62,38 +63,33 @@ void UpdateDefaultTaskPreferences(TestingPrefServiceSimple* pref_service,
TEST(FileManagerFileTasksTest,
FullTaskDescriptor_NonDriveAppWithIconAndDefault) {
FullTaskDescriptor full_descriptor(
- TaskDescriptor("app-id",
- TASK_TYPE_FILE_BROWSER_HANDLER,
- "action-id"),
- "task title",
- GURL("http://example.com/icon.png"),
- true /* is_default */,
- false /* is_generic_file_handler */);
+ TaskDescriptor("app-id", TASK_TYPE_FILE_BROWSER_HANDLER, "action-id"),
+ "task title", "OPEN_WITH", GURL("http://example.com/icon.png"),
+ true /* is_default */, false /* is_generic_file_handler */);
const std::string task_id =
TaskDescriptorToId(full_descriptor.task_descriptor());
EXPECT_EQ("app-id|file|action-id", task_id);
EXPECT_EQ("http://example.com/icon.png", full_descriptor.icon_url().spec());
EXPECT_EQ("task title", full_descriptor.task_title());
+ EXPECT_EQ("OPEN_WITH", full_descriptor.task_verb());
EXPECT_TRUE(full_descriptor.is_default());
}
TEST(FileManagerFileTasksTest,
FullTaskDescriptor_DriveAppWithoutIconAndNotDefault) {
FullTaskDescriptor full_descriptor(
- TaskDescriptor("app-id",
- TASK_TYPE_DRIVE_APP,
- "action-id"),
- "task title",
+ TaskDescriptor("app-id", TASK_TYPE_DRIVE_APP, "action-id"), "task title",
+ "OPEN_WITH",
GURL(), // No icon URL.
- false /* is_default */,
- false /* is_generic_file_handler */);
+ false /* is_default */, false /* is_generic_file_handler */);
const std::string task_id =
TaskDescriptorToId(full_descriptor.task_descriptor());
EXPECT_EQ("app-id|drive|action-id", task_id);
EXPECT_TRUE(full_descriptor.icon_url().is_empty());
EXPECT_EQ("task title", full_descriptor.task_title());
+ EXPECT_EQ("OPEN_WITH", full_descriptor.task_verb());
EXPECT_FALSE(full_descriptor.is_default());
}
@@ -257,18 +253,14 @@ TEST(FileManagerFileTasksTest, ChooseAndSetDefaultTask_MultipleTasks) {
TASK_TYPE_FILE_HANDLER,
"action-id");
std::vector<FullTaskDescriptor> tasks;
- tasks.push_back(FullTaskDescriptor(
- text_app_task,
- "Text.app",
- GURL("http://example.com/text_app.png"),
- false /* is_default */,
- false /* is_generic_file_handler */));
- tasks.push_back(FullTaskDescriptor(
- nice_app_task,
- "Nice.app",
- GURL("http://example.com/nice_app.png"),
- false /* is_default */,
- false /* is_generic_file_handler */));
+ tasks.push_back(FullTaskDescriptor(text_app_task, "Text.app", "OPEN_WITH",
+ GURL("http://example.com/text_app.png"),
+ false /* is_default */,
+ false /* is_generic_file_handler */));
+ tasks.push_back(FullTaskDescriptor(nice_app_task, "Nice.app", "ADD_TO",
+ GURL("http://example.com/nice_app.png"),
+ false /* is_default */,
+ false /* is_generic_file_handler */));
std::vector<extensions::EntryInfo> entries;
entries.push_back(extensions::EntryInfo(
base::FilePath::FromUTF8Unsafe("foo.txt"), "text/plain", false));
@@ -326,10 +318,8 @@ TEST(FileManagerFileTasksTest, ChooseAndSetDefaultTask_FallbackFileBrowser) {
"view-in-browser");
std::vector<FullTaskDescriptor> tasks;
tasks.push_back(FullTaskDescriptor(
- files_app_task,
- "View in browser",
- GURL("http://example.com/some_icon.png"),
- false /* is_default */,
+ files_app_task, "View in browser", "OPEN_WITH",
+ GURL("http://example.com/some_icon.png"), false /* is_default */,
false /* is_generic_file_handler */));
std::vector<extensions::EntryInfo> entries;
entries.push_back(extensions::EntryInfo(
@@ -1002,7 +992,7 @@ TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTask_Generic) {
FindFileHandlerTasks(&test_profile_, jpg_entries, &jpg_result);
EXPECT_EQ(3U, jpg_result.size());
// Foo app provides a handler for all types.
- EXPECT_EQ("Foo", jpg_result[0].task_title());
+ 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.
EXPECT_TRUE(jpg_result[0].is_generic_file_handler());
// Baz app provides a handler for image/*. A partial wildcarded handler is
// treated as non-generic handler.
@@ -1025,5 +1015,128 @@ TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTask_Generic) {
EXPECT_TRUE(dir_result[0].is_generic_file_handler());
}
+// The basic logic is similar to a test case for FindDriveAppTasks above.
+TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTask_Verbs) {
+ // kFooId copied from FindFileHandlerTasks test above.
+ const char kFooId[] = "hhgbjpmdppecanaaogonaigmmifgpaph";
+
+ // Foo.app can handle "text/plain" and "text/html".
+ extensions::ExtensionBuilder foo_app;
+ foo_app.SetManifest(
+ extensions::DictionaryBuilder()
+ .Set("name", "Foo")
+ .Set("version", "1.0.0")
+ .Set("manifest_version", 2)
+ .Set("app", extensions::DictionaryBuilder()
+ .Set("background",
+ extensions::DictionaryBuilder()
+ .Set("scripts", extensions::ListBuilder()
+ .Append("background.js")
+ .Build())
+ .Build())
+ .Build())
+ .Set(
+ "file_handlers",
+ extensions::DictionaryBuilder()
+ .Set("any",
+ extensions::DictionaryBuilder()
+ .Set("types",
+ extensions::ListBuilder().Append("*").Build())
+ .Set("verb", "ADD_TO")
+ .Build())
+ .Set("any_with_directories",
+ extensions::DictionaryBuilder()
+ .SetBoolean("include_directories", true)
+ .Set("types",
+ extensions::ListBuilder().Append("*").Build())
+ .Set("verb", "PACK_WITH")
+ .Build())
+ .Set("all_text", extensions::DictionaryBuilder()
+ .Set("title", "Text")
+ .Set("types", extensions::ListBuilder()
+ .Append("text/plain")
+ .Append("text/html")
+ .Build())
+ .Set("verb", "ADD_TO")
+ .Build())
+ .Set("plain_text", extensions::DictionaryBuilder()
+ .Set("title", "Plain")
+ .Set("types", extensions::ListBuilder()
+ .Append("text/plain")
+ .Build())
+ .Set("verb", "OPEN_WITH")
+ .Build())
+ .Set("html_text_duplicate_verb",
+ extensions::DictionaryBuilder()
+ .Set("title", "Html")
+ .Set("types", extensions::ListBuilder()
+ .Append("text/html")
+ .Build())
+ .Set("verb", "ADD_TO")
+ .Build())
+ .Build())
+ .Build());
+ foo_app.SetID(kFooId);
+ extension_service_->AddExtension(foo_app.Build().get());
+
+ // Find app with corresponding verbs for a "text/plain" file.
+ // Foo.app with ADD_TO, OPEN_WITH and PACK_WITH should be found, but only
+ // one ADD_TO that is not a generic handler will be taken into account,
+ // even though there are 2 ADD_TO matches for "text/plain".
+ std::vector<extensions::EntryInfo> entries;
+ entries.push_back(
+ extensions::EntryInfo(drive::util::GetDriveMountPointPath(&test_profile_)
+ .AppendASCII("foo.txt"),
+ "text/plain", false));
+
+ std::vector<FullTaskDescriptor> tasks;
+ FindFileHandlerTasks(&test_profile_, entries, &tasks);
+
+ ASSERT_EQ(3U, tasks.size());
+ EXPECT_EQ(kFooId, tasks[0].task_descriptor().app_id);
+ EXPECT_EQ("Foo", tasks[0].task_title());
+ EXPECT_EQ("ADD_TO", tasks[0].task_verb());
+ EXPECT_EQ(kFooId, tasks[1].task_descriptor().app_id);
+ EXPECT_EQ("Foo", tasks[1].task_title());
+ EXPECT_EQ("OPEN_WITH", tasks[1].task_verb());
+ EXPECT_EQ(kFooId, tasks[2].task_descriptor().app_id);
+ EXPECT_EQ("Foo", tasks[2].task_title());
+ EXPECT_EQ("PACK_WITH", tasks[2].task_verb());
+
+ // Find app with corresponding verbs for a "text/html" file.
+ // Foo.app with ADD_TO and PACK_WITH should be found, but only the first
+ // ADD_TO that is a good match will be taken into account, even though there
+ // are 3 ADD_TO matches for "text/html".
+ entries.clear();
+ entries.push_back(
+ extensions::EntryInfo(drive::util::GetDriveMountPointPath(&test_profile_)
+ .AppendASCII("foo.html"),
+ "text/html", false));
+ tasks.clear();
+ FindFileHandlerTasks(&test_profile_, entries, &tasks);
+
+ ASSERT_EQ(2U, tasks.size());
+ EXPECT_EQ(kFooId, tasks[0].task_descriptor().app_id);
+ EXPECT_EQ("Foo", tasks[0].task_title());
+ EXPECT_EQ("ADD_TO", tasks[0].task_verb());
+ EXPECT_EQ(kFooId, tasks[1].task_descriptor().app_id);
+ EXPECT_EQ("Foo", tasks[1].task_title());
+ EXPECT_EQ("PACK_WITH", tasks[1].task_verb());
+
+ // Find app with corresponding verbs for directories.
+ // Foo.app with only PACK_WITH should be found.
+ entries.clear();
+ entries.push_back(extensions::EntryInfo(
+ drive::util::GetDriveMountPointPath(&test_profile_).AppendASCII("dir"),
+ "", true));
+ tasks.clear();
+ FindFileHandlerTasks(&test_profile_, entries, &tasks);
+
+ ASSERT_EQ(1U, tasks.size());
+ EXPECT_EQ(kFooId, tasks[0].task_descriptor().app_id);
+ EXPECT_EQ("Foo", tasks[0].task_title());
+ EXPECT_EQ("PACK_WITH", tasks[0].task_verb());
+}
+
} // namespace file_tasks
} // namespace file_manager.

Powered by Google App Engine
This is Rietveld 408576698