|
|
Created:
7 years, 5 months ago by jackhou1 Modified:
7 years, 5 months ago Reviewers:
benwells CC:
chromium-reviews, chrome-apps-syd-reviews_chromium.org Base URL:
svn://svn.chromium.org/chrome/trunk/src Visibility:
Public. |
DescriptionRefactor WebAppShortcutCreatorTest.
There is a lot of setup code duplicated between TESTs. Factor out a test
fixture to reduce duplication.
BUG=
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=213353
Patch Set 1 #Patch Set 2 : Sync and rebase #Messages
Total messages: 6 (0 generated)
lgtm
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/jackhou@chromium.org/19603004/1
Failed to apply patch for chrome/browser/web_applications/web_app_mac_unittest.mm: While running patch -p1 --forward --force --no-backup-if-mismatch; patching file chrome/browser/web_applications/web_app_mac_unittest.mm Hunk #2 FAILED at 128. 1 out of 2 hunks FAILED -- saving rejects to file chrome/browser/web_applications/web_app_mac_unittest.mm.rej Patch: chrome/browser/web_applications/web_app_mac_unittest.mm 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 34ca57016c9c4bf6af61773f5f37c9c4ff21433e..909d5ce264d9c1decd500e7345353d1ec7f64a17 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)); + shortcut_creator.BuildShortcut(other_shim_path_); - EXPECT_TRUE(base::Delete( - other_folder.Append(app_name).Append("Contents"), true)); + EXPECT_TRUE(base::Delete(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)); + shortcut_creator.BuildShortcut(other_shim_path_); - EXPECT_TRUE(base::Delete( - other_folder.Append(app_name).Append("Contents"), true)); + EXPECT_TRUE(base::Delete(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… (message too large)
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/jackhou@chromium.org/19603004/5001
Message was sent while issue was closed.
Change committed as 213353 |