Use audio player and the Office Editing apps as the init default task.

We have several component extension as the initial default app, which
means set to default before user explicitly changes default app.
Audio player and the "Office Editing for Docs, Sheets & Slides" app
were not included in that list despite these are also components.

Bug: 810986
Test: unit_tests --gtest_filter=FileManagerFileTasksTest.*
Test: manually verified Office Editing shown as default

Change-Id: I1ee20773714ecda50fbe3d17f8cda1c0bb72fd96
Reviewed-on: https://chromium-review.googlesource.com/920124
Reviewed-by: Naoki Fukino <fukino@chromium.org>
Commit-Queue: Tatsuhisa Yamaguchi <yamaguchi@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#537247}(cherry picked from commit b5d0b2f01bf6fc4abb7990aa434f02a10fa9d3ac)
Reviewed-on: https://chromium-review.googlesource.com/927841
Reviewed-by: Tatsuhisa Yamaguchi <yamaguchi@chromium.org>
Cr-Commit-Position: refs/branch-heads/3325@{#524}
Cr-Branched-From: bc084a8b5afa3744a74927344e304c02ae54189f-refs/heads/master@{#530369}
diff --git a/chrome/browser/chromeos/file_manager/file_tasks.cc b/chrome/browser/chromeos/file_manager/file_tasks.cc
index b734937..d76cca9 100644
--- a/chrome/browser/chromeos/file_manager/file_tasks.cc
+++ b/chrome/browser/chromeos/file_manager/file_tasks.cc
@@ -129,8 +129,14 @@
     return false;
 
   const char* const kBuiltInApps[] = {
-      kFileManagerAppId, kVideoPlayerAppId, kGalleryAppId, kTextEditorAppId,
-  };
+      kFileManagerAppId,
+      kVideoPlayerAppId,
+      kGalleryAppId,
+      kTextEditorAppId,
+      kAudioPlayerAppId,
+      extension_misc::kQuickOfficeComponentExtensionId,
+      extension_misc::kQuickOfficeInternalExtensionId,
+      extension_misc::kQuickOfficeExtensionId};
 
   for (size_t i = 0; i < arraysize(kBuiltInApps); ++i) {
     if (task.app_id == kBuiltInApps[i])
diff --git a/chrome/browser/chromeos/file_manager/file_tasks_unittest.cc b/chrome/browser/chromeos/file_manager/file_tasks_unittest.cc
index 24cc6c0..4efd884 100644
--- a/chrome/browser/chromeos/file_manager/file_tasks_unittest.cc
+++ b/chrome/browser/chromeos/file_manager/file_tasks_unittest.cc
@@ -28,6 +28,7 @@
 #include "extensions/browser/entry_info.h"
 #include "extensions/browser/extension_prefs.h"
 #include "extensions/browser/extension_system.h"
+#include "extensions/common/constants.h"
 #include "extensions/common/extension_builder.h"
 #include "google_apis/drive/drive_api_parser.h"
 #include "testing/gtest/include/gtest/gtest.h"
@@ -359,6 +360,56 @@
   EXPECT_TRUE(tasks[0].is_default());
 }
 
+// Test that Audio Player is chosen as default even if nothing is set in the
+// preferences.
+TEST(FileManagerFileTasksTest, ChooseAndSetDefaultTask_FallbackAudioPlayer) {
+  TestingPrefServiceSimple pref_service;
+  RegisterDefaultTaskPreferences(&pref_service);
+
+  // The Audio Player app was found for "sound.wav".
+  TaskDescriptor files_app_task(kAudioPlayerAppId, TASK_TYPE_FILE_HANDLER,
+                                "Audio Player");
+  std::vector<FullTaskDescriptor> tasks;
+  tasks.push_back(FullTaskDescriptor(
+      files_app_task, "Audio Player", Verb::VERB_OPEN_WITH,
+      GURL("chrome://extension-icon/cjbfomnbifhcdnihkgipgfcihmgjfhbf/32/1"),
+      false /* is_default */, false /* is_generic_file_handler */));
+  std::vector<extensions::EntryInfo> entries;
+  entries.push_back(extensions::EntryInfo(
+      base::FilePath::FromUTF8Unsafe("sound.wav"), "audio/wav", false));
+
+  // The Audio Player app should be chosen as default, as it's a fallback file
+  // browser handler.
+  ChooseAndSetDefaultTask(pref_service, entries, &tasks);
+  EXPECT_TRUE(tasks[0].is_default());
+}
+
+// Test that Office Editing is chosen as default even if nothing is set in the
+// preferences.
+TEST(FileManagerFileTasksTest, ChooseAndSetDefaultTask_FallbackOfficeEditing) {
+  TestingPrefServiceSimple pref_service;
+  RegisterDefaultTaskPreferences(&pref_service);
+
+  // The Office Editing app was found for "slides.pptx".
+  TaskDescriptor files_app_task(
+      extension_misc::kQuickOfficeComponentExtensionId, TASK_TYPE_FILE_HANDLER,
+      "Office Editing for Docs, Sheets & Slides");
+  std::vector<FullTaskDescriptor> tasks;
+  tasks.push_back(FullTaskDescriptor(
+      files_app_task, "Office Editing for Docs, Sheets & Slides",
+      Verb::VERB_OPEN_WITH,
+      GURL("chrome://extension-icon/bpmcpldpdmajfigpchkicefoigmkfalc/32/1"),
+      false /* is_default */, false /* is_generic_file_handler */));
+  std::vector<extensions::EntryInfo> entries;
+  entries.push_back(extensions::EntryInfo(
+      base::FilePath::FromUTF8Unsafe("slides.pptx"), "", false));
+
+  // The Office Editing app should be chosen as default, as it's a fallback
+  // file browser handler.
+  ChooseAndSetDefaultTask(pref_service, entries, &tasks);
+  EXPECT_TRUE(tasks[0].is_default());
+}
+
 // Test IsGoodMatchFileHandler which returns whether a file handle info matches
 // with files as good match or not.
 TEST(FileManagerFileTasksTest, IsGoodMatchFileHandler) {