Chromium Code Reviews| 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..cb2d00d850bc1fe8b030d3b0f2526b20cf377603 100644 |
| --- a/chrome/browser/chromeos/file_manager/file_tasks_unittest.cc |
| +++ b/chrome/browser/chromeos/file_manager/file_tasks_unittest.cc |
| @@ -64,38 +64,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"), |
|
Devlin
2016/05/16 16:17:32
OPEN_WITH isn't a valid verb anymore (the suggesti
cmihail
2016/05/18 02:35:31
Done.
|
| + 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()); |
| } |
| @@ -261,18 +256,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)); |
| @@ -330,10 +321,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( |
| @@ -1056,5 +1045,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. |