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

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: Fix comments mentioned by fukino@. 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..29e081b317c57618c24fe6d959b4d5042d732fb6 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"
#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,31 @@ 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"),
+ base::UTF8ToUTF16("task title"), 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(base::UTF8ToUTF16("task title"), full_descriptor.task_title());
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"),
+ base::UTF8ToUTF16("task title"),
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(base::UTF8ToUTF16("task title"), full_descriptor.task_title());
EXPECT_FALSE(full_descriptor.is_default());
}
@@ -258,16 +252,12 @@ TEST(FileManagerFileTasksTest, ChooseAndSetDefaultTask_MultipleTasks) {
"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 */,
+ text_app_task, base::UTF8ToUTF16("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 */,
+ nice_app_task, base::UTF8ToUTF16("Nice.app"),
+ 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(
@@ -326,10 +316,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, base::UTF8ToUTF16("View in browser"),
+ 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(
@@ -980,16 +968,16 @@ TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTask_Generic) {
FindFileHandlerTasks(&test_profile_, txt_entries, &txt_result);
EXPECT_EQ(4U, txt_result.size());
// Foo app provides a handler for text/plain.
- EXPECT_EQ("Foo", txt_result[0].task_title());
+ EXPECT_EQ(base::UTF8ToUTF16("Open with Foo"), txt_result[0].task_title());
EXPECT_FALSE(txt_result[0].is_generic_file_handler());
// Bar app provides a handler for .txt.
- EXPECT_EQ("Bar", txt_result[1].task_title());
+ EXPECT_EQ(base::UTF8ToUTF16("Open with Bar"), txt_result[1].task_title());
EXPECT_FALSE(txt_result[1].is_generic_file_handler());
// Baz app provides a handler for all extensions.
- EXPECT_EQ("Baz", txt_result[2].task_title());
+ EXPECT_EQ(base::UTF8ToUTF16("Open with Baz"), txt_result[2].task_title());
EXPECT_TRUE(txt_result[2].is_generic_file_handler());
// Qux app provides a handler for all types.
- EXPECT_EQ("Qux", txt_result[3].task_title());
+ EXPECT_EQ(base::UTF8ToUTF16("Open with Qux"), txt_result[3].task_title());
EXPECT_TRUE(txt_result[3].is_generic_file_handler());
// Test case with .jpg file
@@ -1002,14 +990,14 @@ 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(base::UTF8ToUTF16("Open with Foo"), txt_result[0].task_title());
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.
- EXPECT_EQ("Baz", jpg_result[1].task_title());
+ EXPECT_EQ(base::UTF8ToUTF16("Open with Baz"), jpg_result[1].task_title());
EXPECT_FALSE(jpg_result[1].is_generic_file_handler());
// Qux app provides a handler for all types.
- EXPECT_EQ("Qux", jpg_result[2].task_title());
+ EXPECT_EQ(base::UTF8ToUTF16("Open with Qux"), jpg_result[2].task_title());
EXPECT_TRUE(jpg_result[2].is_generic_file_handler());
// Test case with directories.
@@ -1025,5 +1013,122 @@ 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(base::UTF8ToUTF16("Add to Foo"), tasks[0].task_title());
+ EXPECT_EQ(kFooId, tasks[1].task_descriptor().app_id);
+ EXPECT_EQ(base::UTF8ToUTF16("Open with Foo"), tasks[1].task_title());
+ EXPECT_EQ(kFooId, tasks[2].task_descriptor().app_id);
+ EXPECT_EQ(base::UTF8ToUTF16("Pack with Foo"), tasks[2].task_title());
+
+ // 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(base::UTF8ToUTF16("Add to Foo"), tasks[0].task_title());
+ EXPECT_EQ(kFooId, tasks[1].task_descriptor().app_id);
+ EXPECT_EQ(base::UTF8ToUTF16("Pack with Foo"), tasks[1].task_title());
+
+ // 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(base::UTF8ToUTF16("Pack with Foo"), tasks[0].task_title());
+}
+
} // namespace file_tasks
} // namespace file_manager.

Powered by Google App Engine
This is Rietveld 408576698