Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3633)

Unified Diff: chrome/browser/shell_integration_win_unittest.cc

Issue 14027008: Migrate app_host.exe shortcuts to chrome.exe shortcuts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rework Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/shell_integration_win_unittest.cc
diff --git a/chrome/browser/shell_integration_win_unittest.cc b/chrome/browser/shell_integration_win_unittest.cc
index 04b600d01aff02218c765fcedda398d4e803cfa6..53ff859a6c54029741999b4089b5215203992228 100644
--- a/chrome/browser/shell_integration_win_unittest.cc
+++ b/chrome/browser/shell_integration_win_unittest.cc
@@ -22,27 +22,91 @@
namespace {
-class ShellIntegrationWinMigrateShortcutTest : public testing::Test {
+class ShortcutTest : public testing::Test {
protected:
+ virtual void CreateShortcuts() = 0;
+
virtual void SetUp() OVERRIDE {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
// A path to a random target.
- base::FilePath other_target;
- file_util::CreateTemporaryFileInDir(temp_dir_.path(), &other_target);
+ file_util::CreateTemporaryFileInDir(temp_dir_.path(), &other_target_);
// This doesn't need to actually have a base name of "chrome.exe".
file_util::CreateTemporaryFileInDir(temp_dir_.path(), &chrome_exe_);
+ file_util::CreateTemporaryFileInDir(temp_dir_.path(), &app_host_exe_);
chrome_app_id_ =
ShellUtil::GetBrowserModelId(BrowserDistribution::GetDistribution(),
true);
+ base::FilePath default_user_data_dir;
+ chrome::GetDefaultUserDataDirectory(&default_user_data_dir);
+ base::FilePath default_profile_path =
+ default_user_data_dir.AppendASCII(chrome::kInitialProfile);
+ app_list_app_id_ =
+ ShellIntegration::GetAppListAppModelIdForProfile(default_profile_path);
+ non_default_profile_ = string16(L"NonDefault");
+ non_default_chrome_app_id_ =
+ ShellIntegration::GetChromiumModelIdForProfile(
+ default_user_data_dir.Append(non_default_profile_));
+
+ CreateShortcuts();
+ }
+
+ void AddTestShortcut(
+ const base::win::ShortcutProperties& shortcut_properties) {
+ shortcuts_properties_.push_back(shortcut_properties);
+ base::FilePath shortcut_path =
+ temp_dir_.path().Append(L"Shortcut " +
+ base::IntToString16(shortcuts_.size()) +
+ installer::kLnkExt);
+ shortcuts_.push_back(shortcut_path);
+ ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink(
+ shortcut_path, shortcut_properties,
+ base::win::SHORTCUT_CREATE_ALWAYS));
+ }
+
+ base::win::ScopedCOMInitializer com_initializer_;
+
+ base::ScopedTempDir temp_dir_;
+
+ // Test shortcuts.
+ std::vector<base::FilePath> shortcuts_;
+
+ // Initial properties for the test shortcuts.
+ std::vector<base::win::ShortcutProperties> shortcuts_properties_;
+
+ // The path to a fake chrome.exe.
+ base::FilePath chrome_exe_;
+
+ // The path to a fake app_host.exe.
+ base::FilePath app_host_exe_;
+
+ // The path to a random target.
+ base::FilePath other_target_;
+
+ // Chrome's AppUserModelId.
+ string16 chrome_app_id_;
+
+ // A profile that isn't the Default profile.
+ string16 non_default_profile_;
+
+ // Chrome's AppUserModelId for the non-default profile.
+ string16 non_default_chrome_app_id_;
+
+ // The app launcher's app id.
+ string16 app_list_app_id_;
+};
+
+class ShellIntegrationWinMigrateShortcutTest : public ShortcutTest {
+ protected:
+ virtual void CreateShortcuts() OVERRIDE {
// A temporary object to pass properties to AddTestShortcut().
base::win::ShortcutProperties temp_properties;
// Shortcut 0 doesn't point to chrome.exe and thus should never be migrated.
- temp_properties.set_target(other_target);
+ temp_properties.set_target(other_target_);
temp_properties.set_app_id(L"Dumbo");
temp_properties.set_dual_mode(false);
ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties));
@@ -89,35 +153,16 @@ class ShellIntegrationWinMigrateShortcutTest : public testing::Test {
base::win::ShortcutProperties no_properties;
no_properties.set_target(chrome_exe_);
ASSERT_NO_FATAL_FAILURE(AddTestShortcut(no_properties));
- }
- void AddTestShortcut(
- const base::win::ShortcutProperties& shortcut_properties) {
- shortcuts_properties_.push_back(shortcut_properties);
- base::FilePath shortcut_path =
- temp_dir_.path().Append(L"Shortcut " +
- base::IntToString16(shortcuts_.size()) +
- installer::kLnkExt);
- shortcuts_.push_back(shortcut_path);
- ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink(
- shortcut_path, shortcut_properties,
- base::win::SHORTCUT_CREATE_ALWAYS));
+ // Shortcut 7 has a non-default profile directory and so should get a non-
+ // default app id.
+ temp_properties.set_target(chrome_exe_);
+ temp_properties.set_app_id(L"Dumbo");
+ temp_properties.set_arguments(
+ string16(L"--profile-directory=") + non_default_profile_);
+ temp_properties.set_dual_mode(false);
+ ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties));
}
-
- base::win::ScopedCOMInitializer com_initializer_;
- base::ScopedTempDir temp_dir_;
-
- // The path to a fake chrome.exe.
- base::FilePath chrome_exe_;
-
- // Test shortcuts.
- std::vector<base::FilePath> shortcuts_;
-
- // Initial properties for the test shortcuts.
- std::vector<base::win::ShortcutProperties> shortcuts_properties_;
-
- // Chrome's AppUserModelId.
- string16 chrome_app_id_;
};
} // namespace
@@ -127,15 +172,16 @@ TEST_F(ShellIntegrationWinMigrateShortcutTest, DontCheckDualMode) {
if (base::win::GetVersion() < base::win::VERSION_WIN7)
return;
- EXPECT_EQ(4,
+ EXPECT_EQ(5,
ShellIntegration::MigrateShortcutsInPathInternal(
chrome_exe_, temp_dir_.path(), false));
- // Only shortcut 1, 4, 5, and 6 should have been migrated.
+ // Only shortcut 1, 4, 5, 6 and 7 should have been migrated.
shortcuts_properties_[1].set_app_id(chrome_app_id_);
shortcuts_properties_[4].set_app_id(chrome_app_id_);
shortcuts_properties_[5].set_app_id(chrome_app_id_);
shortcuts_properties_[6].set_app_id(chrome_app_id_);
+ shortcuts_properties_[7].set_app_id(non_default_chrome_app_id_);
for (size_t i = 0; i < shortcuts_.size(); ++i)
base::win::ValidateShortcut(shortcuts_[i], shortcuts_properties_[i]);
@@ -146,23 +192,25 @@ TEST_F(ShellIntegrationWinMigrateShortcutTest, CheckDualMode) {
if (base::win::GetVersion() < base::win::VERSION_WIN7)
return;
- EXPECT_EQ(5,
+ EXPECT_EQ(6,
ShellIntegration::MigrateShortcutsInPathInternal(
chrome_exe_, temp_dir_.path(), true));
- // Shortcut 1, 4, 5, and 6 should have had both their app_id and dual_mode
+ // Shortcut 1, 4, 5, 6 and 7 should have had both their app_id and dual_mode
// properties fixed and shortcut 2 should also have had it's dual_mode
// property fixed.
shortcuts_properties_[1].set_app_id(chrome_app_id_);
shortcuts_properties_[4].set_app_id(chrome_app_id_);
shortcuts_properties_[5].set_app_id(chrome_app_id_);
shortcuts_properties_[6].set_app_id(chrome_app_id_);
+ shortcuts_properties_[7].set_app_id(non_default_chrome_app_id_);
shortcuts_properties_[1].set_dual_mode(true);
shortcuts_properties_[2].set_dual_mode(true);
shortcuts_properties_[4].set_dual_mode(true);
shortcuts_properties_[5].set_dual_mode(true);
shortcuts_properties_[6].set_dual_mode(true);
+ shortcuts_properties_[7].set_dual_mode(true);
for (size_t i = 0; i < shortcuts_.size(); ++i)
base::win::ValidateShortcut(shortcuts_[i], shortcuts_properties_[i]);
@@ -222,3 +270,30 @@ TEST(ShellIntegrationWinTest, GetAppListAppModelIdForProfileTest) {
EXPECT_EQ(base_app_id + L".udd.UserDataTest",
ShellIntegration::GetAppListAppModelIdForProfile(profile_path));
}
+
+// TODO(calamity): remove this test once app_host.exe is removed
+class AppHostMigrateShortcutTest : public ShortcutTest {
+ protected:
+ virtual void CreateShortcuts() OVERRIDE {
+ base::win::ShortcutProperties temp_properties;
+
+ // Shortcut 0 points to app_host.exe and should be retargeted to chrome.exe.
+ temp_properties.set_target(app_host_exe_);
+ temp_properties.set_app_id(L"SomeAppId");
+ temp_properties.set_arguments(L"--show-app-list");
+ ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties));
+ }
+};
+
+// Test migration when not checking for dual mode.
+TEST_F(AppHostMigrateShortcutTest, AppHostExeRetargetsToChromeExe) {
+ EXPECT_EQ(1,
+ ShellIntegration::MigrateAppHostShortcutsInPathInternal(
+ chrome_exe_, app_host_exe_, temp_dir_.path(), false));
+
+ // app_host.exe should now be chrome.exe
+ shortcuts_properties_[0].set_target(chrome_exe_);
+
+ for (size_t i = 0; i < shortcuts_.size(); ++i)
+ base::win::ValidateShortcut(shortcuts_[i], shortcuts_properties_[i]);
+}

Powered by Google App Engine
This is Rietveld 408576698