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

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: 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 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 afb46b32895d6af0218753685730774bfabada10..a013bd9585dc6be2aeea4de45302a857ccaa83b0 100644
--- a/chrome/browser/chromeos/file_manager/file_tasks_unittest.cc
+++ b/chrome/browser/chromeos/file_manager/file_tasks_unittest.cc
@@ -33,6 +33,8 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
+using extensions::api::file_manager_private::Verb;
+
namespace file_manager {
namespace file_tasks {
namespace {
@@ -64,38 +66,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", Verb::VERB_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(Verb::VERB_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",
+ Verb::VERB_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(Verb::VERB_OPEN_WITH, full_descriptor.task_verb());
EXPECT_FALSE(full_descriptor.is_default());
}
@@ -262,16 +259,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, "Text.app", Verb::VERB_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",
- GURL("http://example.com/nice_app.png"),
- false /* is_default */,
+ nice_app_task, "Nice.app", Verb::VERB_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(
@@ -330,10 +323,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", Verb::VERB_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(
@@ -1056,5 +1047,139 @@ 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())
+ .Set("share_plain_text",
+ extensions::DictionaryBuilder()
+ .Set("title", "Share Plain")
+ .Set("types", extensions::ListBuilder()
+ .Append("text/plain")
+ .Build())
+ .Set("verb", "share_with")
+ .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, PACK_WITH and SHARE_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(4U, tasks.size());
+ EXPECT_EQ(kFooId, tasks[0].task_descriptor().app_id);
+ EXPECT_EQ("Foo", tasks[0].task_title());
+ EXPECT_EQ(Verb::VERB_ADD_TO, tasks[0].task_verb());
+ EXPECT_EQ(kFooId, tasks[1].task_descriptor().app_id);
+ EXPECT_EQ("Foo", tasks[1].task_title());
+ EXPECT_EQ(Verb::VERB_OPEN_WITH, tasks[1].task_verb());
+ EXPECT_EQ(kFooId, tasks[2].task_descriptor().app_id);
+ EXPECT_EQ("Foo", tasks[2].task_title());
+ EXPECT_EQ(Verb::VERB_PACK_WITH, tasks[2].task_verb());
+ EXPECT_EQ(kFooId, tasks[3].task_descriptor().app_id);
+ EXPECT_EQ("Foo", tasks[3].task_title());
+ EXPECT_EQ(Verb::VERB_SHARE_WITH, tasks[3].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(Verb::VERB_ADD_TO, tasks[0].task_verb());
+ EXPECT_EQ(kFooId, tasks[1].task_descriptor().app_id);
+ EXPECT_EQ("Foo", tasks[1].task_title());
+ EXPECT_EQ(Verb::VERB_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(Verb::VERB_PACK_WITH, tasks[0].task_verb());
+}
+
} // namespace file_tasks
} // namespace file_manager.
« 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