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

Side by Side 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 unified diff | Download patch
OLDNEW
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 #include "chrome/browser/shell_integration.h" 5 #include "chrome/browser/shell_integration.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/test/test_shortcut_win.h" 13 #include "base/test/test_shortcut_win.h"
14 #include "base/win/scoped_com_initializer.h" 14 #include "base/win/scoped_com_initializer.h"
15 #include "base/win/windows_version.h" 15 #include "base/win/windows_version.h"
16 #include "chrome/common/chrome_constants.h" 16 #include "chrome/common/chrome_constants.h"
17 #include "chrome/common/chrome_paths_internal.h" 17 #include "chrome/common/chrome_paths_internal.h"
18 #include "chrome/installer/util/browser_distribution.h" 18 #include "chrome/installer/util/browser_distribution.h"
19 #include "chrome/installer/util/shell_util.h" 19 #include "chrome/installer/util/shell_util.h"
20 #include "chrome/installer/util/util_constants.h" 20 #include "chrome/installer/util/util_constants.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 namespace { 23 namespace {
24 24
25 class ShellIntegrationWinMigrateShortcutTest : public testing::Test { 25 class ShortcutTest : public testing::Test {
26 protected: 26 protected:
27 virtual void CreateShortcuts() = 0;
28
27 virtual void SetUp() OVERRIDE { 29 virtual void SetUp() OVERRIDE {
28 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 30 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
29 31
30 // A path to a random target. 32 // A path to a random target.
31 base::FilePath other_target; 33 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &other_target_);
32 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &other_target);
33 34
34 // This doesn't need to actually have a base name of "chrome.exe". 35 // This doesn't need to actually have a base name of "chrome.exe".
35 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &chrome_exe_); 36 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &chrome_exe_);
37 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &app_host_exe_);
36 38
37 chrome_app_id_ = 39 chrome_app_id_ =
38 ShellUtil::GetBrowserModelId(BrowserDistribution::GetDistribution(), 40 ShellUtil::GetBrowserModelId(BrowserDistribution::GetDistribution(),
39 true); 41 true);
40 42
43 base::FilePath default_user_data_dir;
44 chrome::GetDefaultUserDataDirectory(&default_user_data_dir);
45 base::FilePath default_profile_path =
46 default_user_data_dir.AppendASCII(chrome::kInitialProfile);
47 app_list_app_id_ =
48 ShellIntegration::GetAppListAppModelIdForProfile(default_profile_path);
49 non_default_profile_ = string16(L"NonDefault");
50 non_default_chrome_app_id_ =
51 ShellIntegration::GetChromiumModelIdForProfile(
52 default_user_data_dir.Append(non_default_profile_));
53
54 CreateShortcuts();
55 }
56
57 void AddTestShortcut(
58 const base::win::ShortcutProperties& shortcut_properties) {
59 shortcuts_properties_.push_back(shortcut_properties);
60 base::FilePath shortcut_path =
61 temp_dir_.path().Append(L"Shortcut " +
62 base::IntToString16(shortcuts_.size()) +
63 installer::kLnkExt);
64 shortcuts_.push_back(shortcut_path);
65 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink(
66 shortcut_path, shortcut_properties,
67 base::win::SHORTCUT_CREATE_ALWAYS));
68 }
69
70 base::win::ScopedCOMInitializer com_initializer_;
71
72 base::ScopedTempDir temp_dir_;
73
74 // Test shortcuts.
75 std::vector<base::FilePath> shortcuts_;
76
77 // Initial properties for the test shortcuts.
78 std::vector<base::win::ShortcutProperties> shortcuts_properties_;
79
80 // The path to a fake chrome.exe.
81 base::FilePath chrome_exe_;
82
83 // The path to a fake app_host.exe.
84 base::FilePath app_host_exe_;
85
86 // The path to a random target.
87 base::FilePath other_target_;
88
89 // Chrome's AppUserModelId.
90 string16 chrome_app_id_;
91
92 // A profile that isn't the Default profile.
93 string16 non_default_profile_;
94
95 // Chrome's AppUserModelId for the non-default profile.
96 string16 non_default_chrome_app_id_;
97
98 // The app launcher's app id.
99 string16 app_list_app_id_;
100 };
101
102 class ShellIntegrationWinMigrateShortcutTest : public ShortcutTest {
103 protected:
104 virtual void CreateShortcuts() OVERRIDE {
41 // A temporary object to pass properties to AddTestShortcut(). 105 // A temporary object to pass properties to AddTestShortcut().
42 base::win::ShortcutProperties temp_properties; 106 base::win::ShortcutProperties temp_properties;
43 107
44 // Shortcut 0 doesn't point to chrome.exe and thus should never be migrated. 108 // Shortcut 0 doesn't point to chrome.exe and thus should never be migrated.
45 temp_properties.set_target(other_target); 109 temp_properties.set_target(other_target_);
46 temp_properties.set_app_id(L"Dumbo"); 110 temp_properties.set_app_id(L"Dumbo");
47 temp_properties.set_dual_mode(false); 111 temp_properties.set_dual_mode(false);
48 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties)); 112 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties));
49 113
50 // Shortcut 1 points to chrome.exe and thus should be migrated. 114 // Shortcut 1 points to chrome.exe and thus should be migrated.
51 temp_properties.set_target(chrome_exe_); 115 temp_properties.set_target(chrome_exe_);
52 temp_properties.set_app_id(L"Dumbo"); 116 temp_properties.set_app_id(L"Dumbo");
53 temp_properties.set_dual_mode(false); 117 temp_properties.set_dual_mode(false);
54 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties)); 118 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties));
55 119
(...skipping 26 matching lines...) Expand all
82 temp_properties.set_target(chrome_exe_); 146 temp_properties.set_target(chrome_exe_);
83 temp_properties.set_app_id(same_size_as_chrome_app_id); 147 temp_properties.set_app_id(same_size_as_chrome_app_id);
84 temp_properties.set_dual_mode(false); 148 temp_properties.set_dual_mode(false);
85 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties)); 149 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties));
86 150
87 // Shortcut 6 doesn't have an app_id, nor is dual_mode even set; they should 151 // Shortcut 6 doesn't have an app_id, nor is dual_mode even set; they should
88 // be set as expected upon migration. 152 // be set as expected upon migration.
89 base::win::ShortcutProperties no_properties; 153 base::win::ShortcutProperties no_properties;
90 no_properties.set_target(chrome_exe_); 154 no_properties.set_target(chrome_exe_);
91 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(no_properties)); 155 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(no_properties));
156
157 // Shortcut 7 has a non-default profile directory and so should get a non-
158 // default app id.
159 temp_properties.set_target(chrome_exe_);
160 temp_properties.set_app_id(L"Dumbo");
161 temp_properties.set_arguments(
162 string16(L"--profile-directory=") + non_default_profile_);
163 temp_properties.set_dual_mode(false);
164 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties));
92 } 165 }
93
94 void AddTestShortcut(
95 const base::win::ShortcutProperties& shortcut_properties) {
96 shortcuts_properties_.push_back(shortcut_properties);
97 base::FilePath shortcut_path =
98 temp_dir_.path().Append(L"Shortcut " +
99 base::IntToString16(shortcuts_.size()) +
100 installer::kLnkExt);
101 shortcuts_.push_back(shortcut_path);
102 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink(
103 shortcut_path, shortcut_properties,
104 base::win::SHORTCUT_CREATE_ALWAYS));
105 }
106
107 base::win::ScopedCOMInitializer com_initializer_;
108 base::ScopedTempDir temp_dir_;
109
110 // The path to a fake chrome.exe.
111 base::FilePath chrome_exe_;
112
113 // Test shortcuts.
114 std::vector<base::FilePath> shortcuts_;
115
116 // Initial properties for the test shortcuts.
117 std::vector<base::win::ShortcutProperties> shortcuts_properties_;
118
119 // Chrome's AppUserModelId.
120 string16 chrome_app_id_;
121 }; 166 };
122 167
123 } // namespace 168 } // namespace
124 169
125 // Test migration when not checking for dual mode. 170 // Test migration when not checking for dual mode.
126 TEST_F(ShellIntegrationWinMigrateShortcutTest, DontCheckDualMode) { 171 TEST_F(ShellIntegrationWinMigrateShortcutTest, DontCheckDualMode) {
127 if (base::win::GetVersion() < base::win::VERSION_WIN7) 172 if (base::win::GetVersion() < base::win::VERSION_WIN7)
128 return; 173 return;
129 174
130 EXPECT_EQ(4, 175 EXPECT_EQ(5,
131 ShellIntegration::MigrateShortcutsInPathInternal( 176 ShellIntegration::MigrateShortcutsInPathInternal(
132 chrome_exe_, temp_dir_.path(), false)); 177 chrome_exe_, temp_dir_.path(), false));
133 178
134 // Only shortcut 1, 4, 5, and 6 should have been migrated. 179 // Only shortcut 1, 4, 5, 6 and 7 should have been migrated.
135 shortcuts_properties_[1].set_app_id(chrome_app_id_); 180 shortcuts_properties_[1].set_app_id(chrome_app_id_);
136 shortcuts_properties_[4].set_app_id(chrome_app_id_); 181 shortcuts_properties_[4].set_app_id(chrome_app_id_);
137 shortcuts_properties_[5].set_app_id(chrome_app_id_); 182 shortcuts_properties_[5].set_app_id(chrome_app_id_);
138 shortcuts_properties_[6].set_app_id(chrome_app_id_); 183 shortcuts_properties_[6].set_app_id(chrome_app_id_);
184 shortcuts_properties_[7].set_app_id(non_default_chrome_app_id_);
139 185
140 for (size_t i = 0; i < shortcuts_.size(); ++i) 186 for (size_t i = 0; i < shortcuts_.size(); ++i)
141 base::win::ValidateShortcut(shortcuts_[i], shortcuts_properties_[i]); 187 base::win::ValidateShortcut(shortcuts_[i], shortcuts_properties_[i]);
142 } 188 }
143 189
144 // Test migration when also checking for dual mode. 190 // Test migration when also checking for dual mode.
145 TEST_F(ShellIntegrationWinMigrateShortcutTest, CheckDualMode) { 191 TEST_F(ShellIntegrationWinMigrateShortcutTest, CheckDualMode) {
146 if (base::win::GetVersion() < base::win::VERSION_WIN7) 192 if (base::win::GetVersion() < base::win::VERSION_WIN7)
147 return; 193 return;
148 194
149 EXPECT_EQ(5, 195 EXPECT_EQ(6,
150 ShellIntegration::MigrateShortcutsInPathInternal( 196 ShellIntegration::MigrateShortcutsInPathInternal(
151 chrome_exe_, temp_dir_.path(), true)); 197 chrome_exe_, temp_dir_.path(), true));
152 198
153 // Shortcut 1, 4, 5, and 6 should have had both their app_id and dual_mode 199 // Shortcut 1, 4, 5, 6 and 7 should have had both their app_id and dual_mode
154 // properties fixed and shortcut 2 should also have had it's dual_mode 200 // properties fixed and shortcut 2 should also have had it's dual_mode
155 // property fixed. 201 // property fixed.
156 shortcuts_properties_[1].set_app_id(chrome_app_id_); 202 shortcuts_properties_[1].set_app_id(chrome_app_id_);
157 shortcuts_properties_[4].set_app_id(chrome_app_id_); 203 shortcuts_properties_[4].set_app_id(chrome_app_id_);
158 shortcuts_properties_[5].set_app_id(chrome_app_id_); 204 shortcuts_properties_[5].set_app_id(chrome_app_id_);
159 shortcuts_properties_[6].set_app_id(chrome_app_id_); 205 shortcuts_properties_[6].set_app_id(chrome_app_id_);
206 shortcuts_properties_[7].set_app_id(non_default_chrome_app_id_);
160 207
161 shortcuts_properties_[1].set_dual_mode(true); 208 shortcuts_properties_[1].set_dual_mode(true);
162 shortcuts_properties_[2].set_dual_mode(true); 209 shortcuts_properties_[2].set_dual_mode(true);
163 shortcuts_properties_[4].set_dual_mode(true); 210 shortcuts_properties_[4].set_dual_mode(true);
164 shortcuts_properties_[5].set_dual_mode(true); 211 shortcuts_properties_[5].set_dual_mode(true);
165 shortcuts_properties_[6].set_dual_mode(true); 212 shortcuts_properties_[6].set_dual_mode(true);
213 shortcuts_properties_[7].set_dual_mode(true);
166 214
167 for (size_t i = 0; i < shortcuts_.size(); ++i) 215 for (size_t i = 0; i < shortcuts_.size(); ++i)
168 base::win::ValidateShortcut(shortcuts_[i], shortcuts_properties_[i]); 216 base::win::ValidateShortcut(shortcuts_[i], shortcuts_properties_[i]);
169 } 217 }
170 218
171 TEST(ShellIntegrationWinTest, GetAppModelIdForProfileTest) { 219 TEST(ShellIntegrationWinTest, GetAppModelIdForProfileTest) {
172 const string16 base_app_id( 220 const string16 base_app_id(
173 BrowserDistribution::GetDistribution()->GetBaseAppId()); 221 BrowserDistribution::GetDistribution()->GetBaseAppId());
174 222
175 // Empty profile path should get chrome::kBrowserAppID 223 // Empty profile path should get chrome::kBrowserAppID
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 default_profile_path)); 263 default_profile_path));
216 264
217 // Non-default profile path should get chrome::kBrowserAppID + AppList joined 265 // Non-default profile path should get chrome::kBrowserAppID + AppList joined
218 // with profile info. 266 // with profile info.
219 base::FilePath profile_path(FILE_PATH_LITERAL("root")); 267 base::FilePath profile_path(FILE_PATH_LITERAL("root"));
220 profile_path = profile_path.Append(FILE_PATH_LITERAL("udd")); 268 profile_path = profile_path.Append(FILE_PATH_LITERAL("udd"));
221 profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test")); 269 profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test"));
222 EXPECT_EQ(base_app_id + L".udd.UserDataTest", 270 EXPECT_EQ(base_app_id + L".udd.UserDataTest",
223 ShellIntegration::GetAppListAppModelIdForProfile(profile_path)); 271 ShellIntegration::GetAppListAppModelIdForProfile(profile_path));
224 } 272 }
273
274 // TODO(calamity): remove this test once app_host.exe is removed
275 class AppHostMigrateShortcutTest : public ShortcutTest {
276 protected:
277 virtual void CreateShortcuts() OVERRIDE {
278 base::win::ShortcutProperties temp_properties;
279
280 // Shortcut 0 points to app_host.exe and should be retargeted to chrome.exe.
281 temp_properties.set_target(app_host_exe_);
282 temp_properties.set_app_id(L"SomeAppId");
283 temp_properties.set_arguments(L"--show-app-list");
284 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties));
285 }
286 };
287
288 // Test migration when not checking for dual mode.
289 TEST_F(AppHostMigrateShortcutTest, AppHostExeRetargetsToChromeExe) {
290 EXPECT_EQ(1,
291 ShellIntegration::MigrateAppHostShortcutsInPathInternal(
292 chrome_exe_, app_host_exe_, temp_dir_.path(), false));
293
294 // app_host.exe should now be chrome.exe
295 shortcuts_properties_[0].set_target(chrome_exe_);
296
297 for (size_t i = 0; i < shortcuts_.size(); ++i)
298 base::win::ValidateShortcut(shortcuts_[i], shortcuts_properties_[i]);
299 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698