Index: chrome/browser/web_applications/web_app_mac_unittest.mm |
diff --git a/chrome/browser/web_applications/web_app_mac_unittest.mm b/chrome/browser/web_applications/web_app_mac_unittest.mm |
index 463383770b8baedb14348a2b14f13576517fcce7..76b15e98d4ea01594eb2a918a6fc6551478b46ad 100644 |
--- a/chrome/browser/web_applications/web_app_mac_unittest.mm |
+++ b/chrome/browser/web_applications/web_app_mac_unittest.mm |
@@ -8,6 +8,7 @@ |
#include <errno.h> |
#include <sys/xattr.h> |
+#include "base/command_line.h" |
#include "base/file_util.h" |
#include "base/files/scoped_temp_dir.h" |
#include "base/mac/foundation_util.h" |
@@ -16,6 +17,7 @@ |
#include "base/strings/sys_string_conversions.h" |
#include "base/strings/utf_string_conversions.h" |
#include "chrome/common/chrome_paths.h" |
+#include "chrome/common/chrome_switches.h" |
#import "chrome/common/mac/app_mode_common.h" |
#include "grit/theme_resources.h" |
#include "testing/gmock/include/gmock/gmock.h" |
@@ -35,11 +37,21 @@ const char kFakeChromeBundleId[] = "fake.cfbundleidentifier"; |
class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator { |
public: |
- explicit WebAppShortcutCreatorMock( |
+ WebAppShortcutCreatorMock( |
const base::FilePath& app_data_dir, |
const ShellIntegration::ShortcutInfo& shortcut_info) |
: WebAppShortcutCreator(app_data_dir, |
- shortcut_info) { |
+ shortcut_info, |
+ extensions::FileHandlersInfo(NULL)) { |
+ } |
+ |
+ WebAppShortcutCreatorMock( |
+ const base::FilePath& app_data_dir, |
+ const ShellIntegration::ShortcutInfo& shortcut_info, |
+ const extensions::FileHandlersInfo& file_handlers_info) |
+ : WebAppShortcutCreator(app_data_dir, |
+ shortcut_info, |
+ file_handlers_info) { |
} |
MOCK_CONST_METHOD0(GetApplicationsDirname, base::FilePath()); |
@@ -290,4 +302,56 @@ TEST_F(WebAppShortcutCreatorTest, RevealAppShimInFinder) { |
SHORTCUT_CREATION_BY_USER, ShellIntegration::ShortcutLocations())); |
} |
+TEST_F(WebAppShortcutCreatorTest, FileHandlers) { |
+ CommandLine::ForCurrentProcess()->AppendSwitch( |
+ switches::kEnableAppsFileAssociations); |
+ std::vector<extensions::FileHandlerInfo> handlers; |
+ extensions::FileHandlerInfo handler_0; |
+ handler_0.extensions.insert("ext0"); |
+ handler_0.extensions.insert("ext1"); |
+ handler_0.types.insert("type0"); |
+ handler_0.types.insert("type1"); |
+ handlers.push_back(handler_0); |
+ extensions::FileHandlerInfo handler_1; |
+ handler_1.extensions.insert("ext2"); |
+ handler_1.types.insert("type2"); |
+ handlers.push_back(handler_1); |
+ |
+ NiceMock<WebAppShortcutCreatorMock> shortcut_creator( |
+ app_data_dir_, info_, extensions::FileHandlersInfo(&handlers)); |
+ EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) |
+ .WillRepeatedly(Return(destination_dir_)); |
+ EXPECT_TRUE(shortcut_creator.CreateShortcuts( |
+ SHORTCUT_CREATION_AUTOMATED, ShellIntegration::ShortcutLocations())); |
+ |
+ base::FilePath plist_path = |
+ shim_path_.Append("Contents").Append("Info.plist"); |
+ NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: |
+ base::mac::FilePathToNSString(plist_path)]; |
+ NSArray* file_handlers = |
+ [plist objectForKey:app_mode::kCFBundleDocumentTypesKey]; |
+ |
+ NSDictionary* file_handler_0 = [file_handlers objectAtIndex:0]; |
+ EXPECT_NSEQ(app_mode::kBundleTypeRoleViewer, |
+ [file_handler_0 objectForKey:app_mode::kCFBundleTypeRoleKey]); |
+ NSArray* file_handler_0_extensions = |
+ [file_handler_0 objectForKey:app_mode::kCFBundleTypeExtensionsKey]; |
+ EXPECT_TRUE([file_handler_0_extensions containsObject:@"ext0"]); |
+ EXPECT_TRUE([file_handler_0_extensions containsObject:@"ext1"]); |
+ NSArray* file_handler_0_types = |
+ [file_handler_0 objectForKey:app_mode::kCFBundleTypeMIMETypesKey]; |
+ EXPECT_TRUE([file_handler_0_types containsObject:@"type0"]); |
+ EXPECT_TRUE([file_handler_0_types containsObject:@"type1"]); |
+ |
+ NSDictionary* file_handler_1 = [file_handlers objectAtIndex:1]; |
+ EXPECT_NSEQ(app_mode::kBundleTypeRoleViewer, |
+ [file_handler_1 objectForKey:app_mode::kCFBundleTypeRoleKey]); |
+ NSArray* file_handler_1_extensions = |
+ [file_handler_1 objectForKey:app_mode::kCFBundleTypeExtensionsKey]; |
+ EXPECT_TRUE([file_handler_1_extensions containsObject:@"ext2"]); |
+ NSArray* file_handler_1_types = |
+ [file_handler_1 objectForKey:app_mode::kCFBundleTypeMIMETypesKey]; |
+ EXPECT_TRUE([file_handler_1_types containsObject:@"type2"]); |
+} |
+ |
} // namespace web_app |