| 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 <errno.h> | 9 #include <errno.h> |
| 10 #include <sys/xattr.h> | 10 #include <sys/xattr.h> |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 base::FilePath dst_folder = temp_dst_dir.path(); | 78 base::FilePath dst_folder = temp_dst_dir.path(); |
| 79 base::FilePath dst_path = dst_folder.Append(app_name); | 79 base::FilePath dst_path = dst_folder.Append(app_name); |
| 80 | 80 |
| 81 NiceMock<WebAppShortcutCreatorMock> shortcut_creator( | 81 NiceMock<WebAppShortcutCreatorMock> shortcut_creator( |
| 82 temp_app_data_path.path(), info); | 82 temp_app_data_path.path(), info); |
| 83 EXPECT_CALL(shortcut_creator, GetDestinationPath()) | 83 EXPECT_CALL(shortcut_creator, GetDestinationPath()) |
| 84 .WillRepeatedly(Return(dst_folder)); | 84 .WillRepeatedly(Return(dst_folder)); |
| 85 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder()); | 85 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder()); |
| 86 | 86 |
| 87 EXPECT_TRUE(shortcut_creator.CreateShortcuts()); | 87 EXPECT_TRUE(shortcut_creator.CreateShortcuts()); |
| 88 EXPECT_TRUE(file_util::PathExists(app_in_app_data_path_path)); | 88 EXPECT_TRUE(base::PathExists(app_in_app_data_path_path)); |
| 89 EXPECT_TRUE(file_util::PathExists(dst_path)); | 89 EXPECT_TRUE(base::PathExists(dst_path)); |
| 90 EXPECT_EQ(dst_path.BaseName(), shortcut_creator.GetShortcutName()); | 90 EXPECT_EQ(dst_path.BaseName(), shortcut_creator.GetShortcutName()); |
| 91 | 91 |
| 92 base::FilePath plist_path = dst_path.Append("Contents").Append("Info.plist"); | 92 base::FilePath plist_path = dst_path.Append("Contents").Append("Info.plist"); |
| 93 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: | 93 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: |
| 94 base::mac::FilePathToNSString(plist_path)]; | 94 base::mac::FilePathToNSString(plist_path)]; |
| 95 EXPECT_NSEQ(base::SysUTF8ToNSString(info.extension_id), | 95 EXPECT_NSEQ(base::SysUTF8ToNSString(info.extension_id), |
| 96 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); | 96 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); |
| 97 EXPECT_NSEQ(base::SysUTF16ToNSString(info.title), | 97 EXPECT_NSEQ(base::SysUTF16ToNSString(info.title), |
| 98 [plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); | 98 [plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); |
| 99 EXPECT_NSEQ(base::SysUTF8ToNSString(info.url.spec()), | 99 EXPECT_NSEQ(base::SysUTF8ToNSString(info.url.spec()), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 expected_bundle_id += ".app.Profile-1-" + info.extension_id; | 136 expected_bundle_id += ".app.Profile-1-" + info.extension_id; |
| 137 EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id)) | 137 EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id)) |
| 138 .WillOnce(Return(other_folder.Append(app_name))); | 138 .WillOnce(Return(other_folder.Append(app_name))); |
| 139 | 139 |
| 140 shortcut_creator.BuildShortcut(other_folder.Append(app_name)); | 140 shortcut_creator.BuildShortcut(other_folder.Append(app_name)); |
| 141 | 141 |
| 142 EXPECT_TRUE(base::Delete( | 142 EXPECT_TRUE(base::Delete( |
| 143 other_folder.Append(app_name).Append("Contents"), true)); | 143 other_folder.Append(app_name).Append("Contents"), true)); |
| 144 | 144 |
| 145 EXPECT_TRUE(shortcut_creator.UpdateShortcuts()); | 145 EXPECT_TRUE(shortcut_creator.UpdateShortcuts()); |
| 146 EXPECT_FALSE(file_util::PathExists(dst_folder.Append(app_name))); | 146 EXPECT_FALSE(base::PathExists(dst_folder.Append(app_name))); |
| 147 EXPECT_TRUE(file_util::PathExists( | 147 EXPECT_TRUE(base::PathExists( |
| 148 other_folder.Append(app_name).Append("Contents"))); | 148 other_folder.Append(app_name).Append("Contents"))); |
| 149 | 149 |
| 150 // Also test case where GetAppBundleById fails. | 150 // Also test case where GetAppBundleById fails. |
| 151 EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id)) | 151 EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id)) |
| 152 .WillOnce(Return(base::FilePath())); | 152 .WillOnce(Return(base::FilePath())); |
| 153 | 153 |
| 154 shortcut_creator.BuildShortcut(other_folder.Append(app_name)); | 154 shortcut_creator.BuildShortcut(other_folder.Append(app_name)); |
| 155 | 155 |
| 156 EXPECT_TRUE(base::Delete( | 156 EXPECT_TRUE(base::Delete( |
| 157 other_folder.Append(app_name).Append("Contents"), true)); | 157 other_folder.Append(app_name).Append("Contents"), true)); |
| 158 | 158 |
| 159 EXPECT_FALSE(shortcut_creator.UpdateShortcuts()); | 159 EXPECT_FALSE(shortcut_creator.UpdateShortcuts()); |
| 160 EXPECT_FALSE(file_util::PathExists(dst_folder.Append(app_name))); | 160 EXPECT_FALSE(base::PathExists(dst_folder.Append(app_name))); |
| 161 EXPECT_FALSE(file_util::PathExists( | 161 EXPECT_FALSE(base::PathExists( |
| 162 other_folder.Append(app_name).Append("Contents"))); | 162 other_folder.Append(app_name).Append("Contents"))); |
| 163 } | 163 } |
| 164 | 164 |
| 165 TEST(WebAppShortcutCreatorTest, CreateAppListShortcut) { | 165 TEST(WebAppShortcutCreatorTest, CreateAppListShortcut) { |
| 166 base::ScopedTempDir temp_dst_dir; | 166 base::ScopedTempDir temp_dst_dir; |
| 167 EXPECT_TRUE(temp_dst_dir.CreateUniqueTempDir()); | 167 EXPECT_TRUE(temp_dst_dir.CreateUniqueTempDir()); |
| 168 | 168 |
| 169 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); | 169 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); |
| 170 | 170 |
| 171 base::FilePath dst_folder = temp_dst_dir.path(); | 171 base::FilePath dst_folder = temp_dst_dir.path(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 193 base::FilePath dst_path = dst_folder.Append( | 193 base::FilePath dst_path = dst_folder.Append( |
| 194 info.profile_path.value() + " " + info.extension_id + ".app"); | 194 info.profile_path.value() + " " + info.extension_id + ".app"); |
| 195 | 195 |
| 196 NiceMock<WebAppShortcutCreatorMock> shortcut_creator( | 196 NiceMock<WebAppShortcutCreatorMock> shortcut_creator( |
| 197 temp_app_data_path.path(), info); | 197 temp_app_data_path.path(), info); |
| 198 EXPECT_CALL(shortcut_creator, GetDestinationPath()) | 198 EXPECT_CALL(shortcut_creator, GetDestinationPath()) |
| 199 .WillRepeatedly(Return(dst_folder)); | 199 .WillRepeatedly(Return(dst_folder)); |
| 200 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder()); | 200 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder()); |
| 201 | 201 |
| 202 EXPECT_TRUE(shortcut_creator.CreateShortcuts()); | 202 EXPECT_TRUE(shortcut_creator.CreateShortcuts()); |
| 203 EXPECT_TRUE(file_util::PathExists(dst_path)); | 203 EXPECT_TRUE(base::PathExists(dst_path)); |
| 204 | 204 |
| 205 ssize_t status = getxattr( | 205 ssize_t status = getxattr( |
| 206 dst_path.value().c_str(), "com.apple.quarantine", NULL, 0, 0, 0); | 206 dst_path.value().c_str(), "com.apple.quarantine", NULL, 0, 0, 0); |
| 207 EXPECT_EQ(-1, status); | 207 EXPECT_EQ(-1, status); |
| 208 EXPECT_EQ(ENOATTR, errno); | 208 EXPECT_EQ(ENOATTR, errno); |
| 209 } | 209 } |
| 210 | 210 |
| 211 TEST(WebAppShortcutCreatorTest, CreateFailure) { | 211 TEST(WebAppShortcutCreatorTest, CreateFailure) { |
| 212 base::ScopedTempDir temp_app_data_path; | 212 base::ScopedTempDir temp_app_data_path; |
| 213 EXPECT_TRUE(temp_app_data_path.CreateUniqueTempDir()); | 213 EXPECT_TRUE(temp_app_data_path.CreateUniqueTempDir()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 243 dst_path.Append("Contents").Append("Resources").Append("app.icns"); | 243 dst_path.Append("Contents").Append("Resources").Append("app.icns"); |
| 244 | 244 |
| 245 base::scoped_nsobject<NSImage> image([[NSImage alloc] | 245 base::scoped_nsobject<NSImage> image([[NSImage alloc] |
| 246 initWithContentsOfFile:base::mac::FilePathToNSString(icon_path)]); | 246 initWithContentsOfFile:base::mac::FilePathToNSString(icon_path)]); |
| 247 EXPECT_TRUE(image); | 247 EXPECT_TRUE(image); |
| 248 EXPECT_EQ(product_logo.Width(), [image size].width); | 248 EXPECT_EQ(product_logo.Width(), [image size].width); |
| 249 EXPECT_EQ(product_logo.Height(), [image size].height); | 249 EXPECT_EQ(product_logo.Height(), [image size].height); |
| 250 } | 250 } |
| 251 | 251 |
| 252 } // namespace web_app | 252 } // namespace web_app |
| OLD | NEW |