| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/web_applications/web_app_mac.h" | 5 #import "chrome/browser/web_applications/web_app_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include <sys/xattr.h> | 9 #include <sys/xattr.h> |
| 10 #include <errno.h> | 10 #include <errno.h> |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator { | 33 class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator { |
| 34 public: | 34 public: |
| 35 explicit WebAppShortcutCreatorMock( | 35 explicit WebAppShortcutCreatorMock( |
| 36 const ShellIntegration::ShortcutInfo& shortcut_info) | 36 const ShellIntegration::ShortcutInfo& shortcut_info) |
| 37 : WebAppShortcutCreator(base::FilePath("/fake/path"), shortcut_info, | 37 : WebAppShortcutCreator(base::FilePath("/fake/path"), shortcut_info, |
| 38 UTF8ToUTF16("fake.cfbundleidentifier")) { | 38 UTF8ToUTF16("fake.cfbundleidentifier")) { |
| 39 } | 39 } |
| 40 | 40 |
| 41 MOCK_CONST_METHOD0(GetDestinationPath, base::FilePath()); | 41 MOCK_CONST_METHOD0(GetDestinationPath, base::FilePath()); |
| 42 MOCK_CONST_METHOD1(RevealGeneratedBundleInFinder, | |
| 43 void (const base::FilePath&)); | |
| 44 }; | 42 }; |
| 45 | 43 |
| 46 ShellIntegration::ShortcutInfo GetShortcutInfo() { | 44 ShellIntegration::ShortcutInfo GetShortcutInfo() { |
| 47 ShellIntegration::ShortcutInfo info; | 45 ShellIntegration::ShortcutInfo info; |
| 48 info.extension_id = "extension_id"; | 46 info.extension_id = "extension_id"; |
| 49 info.extension_path = base::FilePath("/fake/extension/path"); | 47 info.extension_path = base::FilePath("/fake/extension/path"); |
| 50 info.title = ASCIIToUTF16("Shortcut Title"); | 48 info.title = ASCIIToUTF16("Shortcut Title"); |
| 51 info.url = GURL("http://example.com/"); | 49 info.url = GURL("http://example.com/"); |
| 52 info.profile_path = base::FilePath("Default"); | 50 info.profile_path = base::FilePath("Default"); |
| 53 info.profile_name = "profile name"; | 51 info.profile_name = "profile name"; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 64 | 62 |
| 65 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); | 63 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); |
| 66 | 64 |
| 67 base::FilePath dst_folder = scoped_temp_dir.path(); | 65 base::FilePath dst_folder = scoped_temp_dir.path(); |
| 68 base::FilePath dst_path = dst_folder.Append( | 66 base::FilePath dst_path = dst_folder.Append( |
| 69 info.profile_path.value() + " " + info.extension_id + ".app"); | 67 info.profile_path.value() + " " + info.extension_id + ".app"); |
| 70 | 68 |
| 71 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); | 69 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); |
| 72 EXPECT_CALL(shortcut_creator, GetDestinationPath()) | 70 EXPECT_CALL(shortcut_creator, GetDestinationPath()) |
| 73 .WillRepeatedly(Return(dst_folder)); | 71 .WillRepeatedly(Return(dst_folder)); |
| 74 EXPECT_CALL(shortcut_creator, RevealGeneratedBundleInFinder(dst_path)); | |
| 75 | 72 |
| 76 EXPECT_TRUE(shortcut_creator.CreateShortcut()); | 73 EXPECT_TRUE(shortcut_creator.CreateShortcut()); |
| 77 EXPECT_TRUE(file_util::PathExists(dst_path)); | 74 EXPECT_TRUE(file_util::PathExists(dst_path)); |
| 78 EXPECT_EQ(dst_path.value(), shortcut_creator.GetShortcutPath().value()); | 75 EXPECT_EQ(dst_path.value(), shortcut_creator.GetShortcutPath().value()); |
| 79 | 76 |
| 80 base::FilePath plist_path = dst_path.Append("Contents").Append("Info.plist"); | 77 base::FilePath plist_path = dst_path.Append("Contents").Append("Info.plist"); |
| 81 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: | 78 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: |
| 82 base::mac::FilePathToNSString(plist_path)]; | 79 base::mac::FilePathToNSString(plist_path)]; |
| 83 EXPECT_NSEQ(base::SysUTF8ToNSString(info.extension_id), | 80 EXPECT_NSEQ(base::SysUTF8ToNSString(info.extension_id), |
| 84 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); | 81 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 104 | 101 |
| 105 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); | 102 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); |
| 106 | 103 |
| 107 base::FilePath dst_folder = scoped_temp_dir.path(); | 104 base::FilePath dst_folder = scoped_temp_dir.path(); |
| 108 base::FilePath dst_path = dst_folder.Append( | 105 base::FilePath dst_path = dst_folder.Append( |
| 109 info.profile_path.value() + " " + info.extension_id + ".app"); | 106 info.profile_path.value() + " " + info.extension_id + ".app"); |
| 110 | 107 |
| 111 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); | 108 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); |
| 112 EXPECT_CALL(shortcut_creator, GetDestinationPath()) | 109 EXPECT_CALL(shortcut_creator, GetDestinationPath()) |
| 113 .WillRepeatedly(Return(dst_folder)); | 110 .WillRepeatedly(Return(dst_folder)); |
| 114 EXPECT_CALL(shortcut_creator, RevealGeneratedBundleInFinder(dst_path)); | |
| 115 | 111 |
| 116 EXPECT_TRUE(shortcut_creator.CreateShortcut()); | 112 EXPECT_TRUE(shortcut_creator.CreateShortcut()); |
| 117 EXPECT_TRUE(file_util::PathExists(dst_path)); | 113 EXPECT_TRUE(file_util::PathExists(dst_path)); |
| 118 | 114 |
| 119 ssize_t status = getxattr( | 115 ssize_t status = getxattr( |
| 120 dst_path.value().c_str(), "com.apple.quarantine", NULL, 0, 0, 0); | 116 dst_path.value().c_str(), "com.apple.quarantine", NULL, 0, 0, 0); |
| 121 EXPECT_EQ(-1, status); | 117 EXPECT_EQ(-1, status); |
| 122 EXPECT_EQ(ENOATTR, errno); | 118 EXPECT_EQ(ENOATTR, errno); |
| 123 } | 119 } |
| 124 | 120 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 152 dst_path.Append("Contents").Append("Resources").Append("app.icns"); | 148 dst_path.Append("Contents").Append("Resources").Append("app.icns"); |
| 153 | 149 |
| 154 scoped_nsobject<NSImage> image([[NSImage alloc] initWithContentsOfFile: | 150 scoped_nsobject<NSImage> image([[NSImage alloc] initWithContentsOfFile: |
| 155 base::mac::FilePathToNSString(icon_path)]); | 151 base::mac::FilePathToNSString(icon_path)]); |
| 156 EXPECT_TRUE(image); | 152 EXPECT_TRUE(image); |
| 157 EXPECT_EQ(product_logo.Width(), [image size].width); | 153 EXPECT_EQ(product_logo.Width(), [image size].width); |
| 158 EXPECT_EQ(product_logo.Height(), [image size].height); | 154 EXPECT_EQ(product_logo.Height(), [image size].height); |
| 159 } | 155 } |
| 160 | 156 |
| 161 } // namespace web_app | 157 } // namespace web_app |
| OLD | NEW |