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 ad056e7070d7920210f6b10c854b898db2921026..a4957b8f42e958f7708c0505eb1858276b99dbd1 100644 |
--- a/chrome/browser/web_applications/web_app_mac_unittest.mm |
+++ b/chrome/browser/web_applications/web_app_mac_unittest.mm |
@@ -54,49 +54,67 @@ ShellIntegration::ShortcutInfo GetShortcutInfo() { |
info.extension_path = base::FilePath("/fake/extension/path"); |
info.title = ASCIIToUTF16("Shortcut Title"); |
info.url = GURL("http://example.com/"); |
- info.profile_path = base::FilePath("Profile 1"); |
+ info.profile_path = base::FilePath("user_data_dir").Append("Profile 1"); |
info.profile_name = "profile name"; |
return info; |
} |
-} // namespace |
+class WebAppShortcutCreatorTest : public testing::Test { |
+ protected: |
+ WebAppShortcutCreatorTest() {} |
+ |
+ virtual void SetUp() { |
+ EXPECT_TRUE(app_data_path_temp_dir_.CreateUniqueTempDir()); |
+ EXPECT_TRUE(destination_path_temp_dir_.CreateUniqueTempDir()); |
+ app_data_path_ = app_data_path_temp_dir_.path(); |
+ destination_path_ = destination_path_temp_dir_.path(); |
+ |
+ info_ = GetShortcutInfo(); |
+ shim_base_name_ = base::FilePath( |
+ info_.profile_path.BaseName().value() + |
+ " " + info_.extension_id + ".app"); |
+ internal_shim_path_ = app_data_path_.Append(shim_base_name_); |
+ shim_path_ = destination_path_.Append(shim_base_name_); |
+ } |
-namespace web_app { |
+ base::ScopedTempDir app_data_path_temp_dir_; |
+ base::ScopedTempDir destination_path_temp_dir_; |
+ base::FilePath app_data_path_; |
+ base::FilePath destination_path_; |
+ |
+ ShellIntegration::ShortcutInfo info_; |
+ base::FilePath shim_base_name_; |
+ base::FilePath internal_shim_path_; |
+ base::FilePath shim_path_; |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(WebAppShortcutCreatorTest); |
+}; |
-TEST(WebAppShortcutCreatorTest, CreateShortcuts) { |
- base::ScopedTempDir temp_app_data_path; |
- EXPECT_TRUE(temp_app_data_path.CreateUniqueTempDir()); |
- base::ScopedTempDir temp_dst_dir; |
- EXPECT_TRUE(temp_dst_dir.CreateUniqueTempDir()); |
- ShellIntegration::ShortcutInfo info = GetShortcutInfo(); |
+} // namespace |
- base::FilePath app_name( |
- info.profile_path.value() + " " + info.extension_id + ".app"); |
- base::FilePath app_in_app_data_path_path = |
- temp_app_data_path.path().Append(app_name); |
- base::FilePath dst_folder = temp_dst_dir.path(); |
- base::FilePath dst_path = dst_folder.Append(app_name); |
+namespace web_app { |
- NiceMock<WebAppShortcutCreatorMock> shortcut_creator( |
- temp_app_data_path.path(), info); |
+TEST_F(WebAppShortcutCreatorTest, CreateShortcuts) { |
+ NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_path_, info_); |
EXPECT_CALL(shortcut_creator, GetDestinationPath()) |
- .WillRepeatedly(Return(dst_folder)); |
+ .WillRepeatedly(Return(destination_path_)); |
EXPECT_CALL(shortcut_creator, RevealAppShimInFinder()); |
EXPECT_TRUE(shortcut_creator.CreateShortcuts()); |
- EXPECT_TRUE(base::PathExists(app_in_app_data_path_path)); |
- EXPECT_TRUE(base::PathExists(dst_path)); |
- EXPECT_EQ(dst_path.BaseName(), shortcut_creator.GetShortcutName()); |
+ EXPECT_TRUE(base::PathExists(shim_path_)); |
+ EXPECT_TRUE(base::PathExists(destination_path_)); |
+ EXPECT_EQ(shim_base_name_, shortcut_creator.GetShortcutName()); |
- base::FilePath plist_path = dst_path.Append("Contents").Append("Info.plist"); |
+ base::FilePath plist_path = |
+ shim_path_.Append("Contents").Append("Info.plist"); |
NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: |
base::mac::FilePathToNSString(plist_path)]; |
- EXPECT_NSEQ(base::SysUTF8ToNSString(info.extension_id), |
+ EXPECT_NSEQ(base::SysUTF8ToNSString(info_.extension_id), |
[plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); |
- EXPECT_NSEQ(base::SysUTF16ToNSString(info.title), |
+ EXPECT_NSEQ(base::SysUTF16ToNSString(info_.title), |
[plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); |
- EXPECT_NSEQ(base::SysUTF8ToNSString(info.url.spec()), |
+ EXPECT_NSEQ(base::SysUTF8ToNSString(info_.url.spec()), |
[plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); |
// Make sure all values in the plist are actually filled in. |
@@ -110,137 +128,90 @@ TEST(WebAppShortcutCreatorTest, CreateShortcuts) { |
} |
} |
-TEST(WebAppShortcutCreatorTest, UpdateShortcuts) { |
- base::ScopedTempDir temp_app_data_path; |
- EXPECT_TRUE(temp_app_data_path.CreateUniqueTempDir()); |
- base::ScopedTempDir temp_dst_dir; |
- EXPECT_TRUE(temp_dst_dir.CreateUniqueTempDir()); |
- base::ScopedTempDir temp_dst_dir_other; |
- EXPECT_TRUE(temp_dst_dir_other.CreateUniqueTempDir()); |
- |
- ShellIntegration::ShortcutInfo info = GetShortcutInfo(); |
- |
- base::FilePath app_name( |
- info.profile_path.value() + " " + info.extension_id + ".app"); |
- base::FilePath app_in_app_data_path_path = |
- temp_app_data_path.path().Append(app_name); |
- base::FilePath dst_folder = temp_dst_dir.path(); |
- base::FilePath other_folder = temp_dst_dir_other.path(); |
- |
- NiceMock<WebAppShortcutCreatorMock> shortcut_creator( |
- temp_app_data_path.path(), info); |
+TEST_F(WebAppShortcutCreatorTest, UpdateShortcuts) { |
+ base::ScopedTempDir other_folder_temp_dir; |
+ EXPECT_TRUE(other_folder_temp_dir.CreateUniqueTempDir()); |
+ base::FilePath other_folder = other_folder_temp_dir.path(); |
+ base::FilePath other_shim_path = other_folder.Append(shim_base_name_); |
+ |
+ NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_path_, info_); |
EXPECT_CALL(shortcut_creator, GetDestinationPath()) |
- .WillRepeatedly(Return(dst_folder)); |
+ .WillRepeatedly(Return(destination_path_)); |
std::string expected_bundle_id = kFakeChromeBundleId; |
- expected_bundle_id += ".app.Profile-1-" + info.extension_id; |
+ expected_bundle_id += ".app.Profile-1-" + info_.extension_id; |
EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id)) |
- .WillOnce(Return(other_folder.Append(app_name))); |
+ .WillOnce(Return(other_shim_path)); |
- shortcut_creator.BuildShortcut(other_folder.Append(app_name)); |
+ EXPECT_TRUE(shortcut_creator.BuildShortcut(other_shim_path)); |
- EXPECT_TRUE(base::DeleteFile( |
- other_folder.Append(app_name).Append("Contents"), true)); |
+ EXPECT_TRUE(base::DeleteFile(other_shim_path.Append("Contents"), true)); |
EXPECT_TRUE(shortcut_creator.UpdateShortcuts()); |
- EXPECT_FALSE(base::PathExists(dst_folder.Append(app_name))); |
- EXPECT_TRUE(base::PathExists( |
- other_folder.Append(app_name).Append("Contents"))); |
+ EXPECT_FALSE(base::PathExists(shim_path_)); |
+ EXPECT_TRUE(base::PathExists(other_shim_path.Append("Contents"))); |
// Also test case where GetAppBundleById fails. |
EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id)) |
.WillOnce(Return(base::FilePath())); |
- shortcut_creator.BuildShortcut(other_folder.Append(app_name)); |
+ EXPECT_TRUE(shortcut_creator.BuildShortcut(other_shim_path)); |
- EXPECT_TRUE(base::DeleteFile( |
- other_folder.Append(app_name).Append("Contents"), true)); |
+ EXPECT_TRUE(base::DeleteFile(other_shim_path.Append("Contents"), true)); |
EXPECT_FALSE(shortcut_creator.UpdateShortcuts()); |
- EXPECT_FALSE(base::PathExists(dst_folder.Append(app_name))); |
- EXPECT_FALSE(base::PathExists( |
- other_folder.Append(app_name).Append("Contents"))); |
+ EXPECT_FALSE(base::PathExists(shim_path_)); |
+ EXPECT_FALSE(base::PathExists(other_shim_path.Append("Contents"))); |
} |
-TEST(WebAppShortcutCreatorTest, CreateAppListShortcut) { |
- base::ScopedTempDir temp_dst_dir; |
- EXPECT_TRUE(temp_dst_dir.CreateUniqueTempDir()); |
- |
- ShellIntegration::ShortcutInfo info = GetShortcutInfo(); |
- |
- base::FilePath dst_folder = temp_dst_dir.path(); |
- |
+TEST_F(WebAppShortcutCreatorTest, CreateAppListShortcut) { |
// With an empty |profile_name|, the shortcut path should not have the profile |
// directory prepended to the extension id on the app bundle name. |
- info.profile_name.clear(); |
- base::FilePath dst_path = dst_folder.Append(info.extension_id + ".app"); |
+ info_.profile_name.clear(); |
+ base::FilePath dst_path = |
+ destination_path_.Append(info_.extension_id + ".app"); |
- NiceMock<WebAppShortcutCreatorMock> shortcut_creator(base::FilePath(), info); |
+ NiceMock<WebAppShortcutCreatorMock> shortcut_creator(base::FilePath(), info_); |
EXPECT_CALL(shortcut_creator, GetDestinationPath()) |
- .WillRepeatedly(Return(dst_folder)); |
+ .WillRepeatedly(Return(destination_path_)); |
EXPECT_EQ(dst_path.BaseName(), shortcut_creator.GetShortcutName()); |
} |
-TEST(WebAppShortcutCreatorTest, RunShortcut) { |
- base::ScopedTempDir temp_app_data_path; |
- EXPECT_TRUE(temp_app_data_path.CreateUniqueTempDir()); |
- base::ScopedTempDir temp_dst_dir; |
- EXPECT_TRUE(temp_dst_dir.CreateUniqueTempDir()); |
- |
- ShellIntegration::ShortcutInfo info = GetShortcutInfo(); |
- |
- base::FilePath dst_folder = temp_dst_dir.path(); |
- base::FilePath dst_path = dst_folder.Append( |
- info.profile_path.value() + " " + info.extension_id + ".app"); |
- |
- NiceMock<WebAppShortcutCreatorMock> shortcut_creator( |
- temp_app_data_path.path(), info); |
+TEST_F(WebAppShortcutCreatorTest, RunShortcut) { |
+ NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_path_, info_); |
EXPECT_CALL(shortcut_creator, GetDestinationPath()) |
- .WillRepeatedly(Return(dst_folder)); |
+ .WillRepeatedly(Return(destination_path_)); |
EXPECT_CALL(shortcut_creator, RevealAppShimInFinder()); |
EXPECT_TRUE(shortcut_creator.CreateShortcuts()); |
- EXPECT_TRUE(base::PathExists(dst_path)); |
+ EXPECT_TRUE(base::PathExists(shim_path_)); |
ssize_t status = getxattr( |
- dst_path.value().c_str(), "com.apple.quarantine", NULL, 0, 0, 0); |
+ shim_path_.value().c_str(), "com.apple.quarantine", NULL, 0, 0, 0); |
EXPECT_EQ(-1, status); |
EXPECT_EQ(ENOATTR, errno); |
} |
-TEST(WebAppShortcutCreatorTest, CreateFailure) { |
- base::ScopedTempDir temp_app_data_path; |
- EXPECT_TRUE(temp_app_data_path.CreateUniqueTempDir()); |
- base::ScopedTempDir temp_dst_dir; |
- EXPECT_TRUE(temp_dst_dir.CreateUniqueTempDir()); |
- |
+TEST_F(WebAppShortcutCreatorTest, CreateFailure) { |
base::FilePath non_existent_path = |
- temp_dst_dir.path().Append("not-existent").Append("name.app"); |
+ destination_path_.Append("not-existent").Append("name.app"); |
- NiceMock<WebAppShortcutCreatorMock> shortcut_creator( |
- temp_app_data_path.path(), GetShortcutInfo()); |
+ NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_path_, info_); |
EXPECT_CALL(shortcut_creator, GetDestinationPath()) |
.WillRepeatedly(Return(non_existent_path)); |
EXPECT_FALSE(shortcut_creator.CreateShortcuts()); |
} |
-TEST(WebAppShortcutCreatorTest, UpdateIcon) { |
- base::ScopedTempDir temp_app_data_path; |
- EXPECT_TRUE(temp_app_data_path.CreateUniqueTempDir()); |
- base::ScopedTempDir temp_dst_dir; |
- EXPECT_TRUE(temp_dst_dir.CreateUniqueTempDir()); |
- base::FilePath dst_path = temp_dst_dir.path(); |
- |
- ShellIntegration::ShortcutInfo info = GetShortcutInfo(); |
+TEST_F(WebAppShortcutCreatorTest, UpdateIcon) { |
gfx::Image product_logo = |
ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
IDR_PRODUCT_LOGO_32); |
- info.favicon.Add(product_logo); |
- WebAppShortcutCreatorMock shortcut_creator(temp_app_data_path.path(), info); |
+ info_.favicon.Add(product_logo); |
+ WebAppShortcutCreatorMock shortcut_creator(app_data_path_, info_); |
- ASSERT_TRUE(shortcut_creator.UpdateIcon(dst_path)); |
+ ASSERT_TRUE(shortcut_creator.UpdateIcon(shim_path_)); |
base::FilePath icon_path = |
- dst_path.Append("Contents").Append("Resources").Append("app.icns"); |
+ shim_path_.Append("Contents").Append("Resources").Append("app.icns"); |
base::scoped_nsobject<NSImage> image([[NSImage alloc] |
initWithContentsOfFile:base::mac::FilePathToNSString(icon_path)]); |