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

Side by Side Diff: chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc

Issue 11299160: Find shortcuts that don't have a profile command line set when creating 2nd profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years 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 | Annotate | Revision Log
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 <objbase.h> // For CoInitialize(). 5 #include <objbase.h> // For CoInitialize().
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/location.h"
8 #include "base/message_loop.h" 9 #include "base/message_loop.h"
9 #include "base/path_service.h" 10 #include "base/path_service.h"
10 #include "base/test/scoped_path_override.h" 11 #include "base/test/scoped_path_override.h"
11 #include "base/string16.h" 12 #include "base/string16.h"
12 #include "base/test/test_shortcut_win.h" 13 #include "base/test/test_shortcut_win.h"
13 #include "base/win/shortcut.h" 14 #include "base/win/shortcut.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_manager.h" 16 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/profiles/profile_shortcut_manager.h" 17 #include "chrome/browser/profiles/profile_shortcut_manager.h"
17 #include "chrome/browser/profiles/profile_shortcut_manager_win.h" 18 #include "chrome/browser/profiles/profile_shortcut_manager_win.h"
18 #include "chrome/installer/util/browser_distribution.h" 19 #include "chrome/installer/util/browser_distribution.h"
20 #include "chrome/installer/util/product.h"
19 #include "chrome/installer/util/shell_util.h" 21 #include "chrome/installer/util/shell_util.h"
20 #include "chrome/test/base/testing_browser_process.h" 22 #include "chrome/test/base/testing_browser_process.h"
21 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
22 #include "chrome/test/base/testing_profile_manager.h" 24 #include "chrome/test/base/testing_profile_manager.h"
23 #include "content/public/test/test_browser_thread.h" 25 #include "content/public/test/test_browser_thread.h"
24 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
25 27
26 using content::BrowserThread; 28 using content::BrowserThread;
27 29
28 class ProfileShortcutManagerTest : public testing::Test { 30 class ProfileShortcutManagerTest : public testing::Test {
29 protected: 31 protected:
30 ProfileShortcutManagerTest() 32 ProfileShortcutManagerTest()
31 : distribution_(NULL), 33 : distribution_(NULL),
32 ui_thread_(BrowserThread::UI, &message_loop_), 34 ui_thread_(BrowserThread::UI, &message_loop_),
33 file_thread_(BrowserThread::FILE, &message_loop_), 35 file_thread_(BrowserThread::FILE, &message_loop_),
34 profile_shortcut_manager_(NULL), 36 profile_shortcut_manager_(NULL),
35 profile_info_cache_(NULL), 37 profile_info_cache_(NULL),
36 fake_user_desktop_(base::DIR_USER_DESKTOP) { 38 fake_user_desktop_(base::DIR_USER_DESKTOP) {
37 } 39 }
38 40
41 FilePath CreateProfileDirectory(const string16& profile_name) {
42 const FilePath profile_path =
43 profile_info_cache_->GetUserDataDir().Append(profile_name);
44 file_util::CreateDirectoryW(profile_path);
45 return profile_path;
46 }
47
39 virtual void SetUp() OVERRIDE { 48 virtual void SetUp() OVERRIDE {
40 CoInitialize(NULL); 49 CoInitialize(NULL);
41 distribution_ = BrowserDistribution::GetDistribution(); 50 distribution_ = BrowserDistribution::GetDistribution();
42 ASSERT_TRUE(distribution_ != NULL); 51 ASSERT_TRUE(distribution_ != NULL);
43 52
44 TestingBrowserProcess* browser_process = 53 TestingBrowserProcess* browser_process =
45 static_cast<TestingBrowserProcess*>(g_browser_process); 54 static_cast<TestingBrowserProcess*>(g_browser_process);
46 profile_manager_.reset(new TestingProfileManager(browser_process)); 55 profile_manager_.reset(new TestingProfileManager(browser_process));
47 ASSERT_TRUE(profile_manager_->SetUp()); 56 ASSERT_TRUE(profile_manager_->SetUp());
48 profile_info_cache_ = profile_manager_->profile_info_cache(); 57 profile_info_cache_ = profile_manager_->profile_info_cache();
49 profile_shortcut_manager_.reset( 58 profile_shortcut_manager_.reset(
50 ProfileShortcutManager::Create(profile_manager_->profile_manager())); 59 ProfileShortcutManager::Create(profile_manager_->profile_manager()));
51 60
52 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path_)); 61 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path_));
53 dest_path_ = profile_info_cache_->GetUserDataDir();
54 dest_path_ = dest_path_.Append(FILE_PATH_LITERAL("My profile"));
55 file_util::CreateDirectoryW(dest_path_);
56 profile_name_ = L"My profile";
57
58 ASSERT_TRUE(ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP, 62 ASSERT_TRUE(ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_DESKTOP,
59 distribution_, 63 distribution_,
60 ShellUtil::CURRENT_USER, 64 ShellUtil::CURRENT_USER,
61 &shortcuts_directory_)); 65 &shortcuts_directory_));
62 66
63 second_dest_path_ = profile_info_cache_->GetUserDataDir(); 67 profile_1_name_ = L"My profile";
64 second_dest_path_ = 68 profile_1_path_ = CreateProfileDirectory(profile_1_name_);
65 second_dest_path_.Append(FILE_PATH_LITERAL("My profile 2")); 69 profile_2_name_ = L"My profile 2";
66 file_util::CreateDirectoryW(second_dest_path_); 70 profile_2_path_ = CreateProfileDirectory(profile_2_name_);
67 second_profile_name_ = L"My profile 2";
68 } 71 }
69 72
70 virtual void TearDown() OVERRIDE { 73 virtual void TearDown() OVERRIDE {
71 message_loop_.RunUntilIdle(); 74 message_loop_.RunUntilIdle();
72 75
73 // Remove all shortcuts except the last (since it will no longer have 76 // Remove all shortcuts except the last (since it will no longer have
74 // an appended name). 77 // an appended name).
75 const int num_profiles = profile_info_cache_->GetNumberOfProfiles(); 78 const int num_profiles = profile_info_cache_->GetNumberOfProfiles();
76 for (int i = 0; i < num_profiles; ++i) { 79 for (int i = 0; i < num_profiles; ++i) {
77 const FilePath profile_path = 80 const FilePath profile_path =
78 profile_info_cache_->GetPathOfProfileAtIndex(0); 81 profile_info_cache_->GetPathOfProfileAtIndex(0);
79 string16 profile_name; 82 string16 profile_name;
80 if (i != num_profiles - 1) 83 if (i != num_profiles - 1)
81 profile_name = profile_info_cache_->GetNameOfProfileAtIndex(0); 84 profile_name = profile_info_cache_->GetNameOfProfileAtIndex(0);
82 profile_info_cache_->DeleteProfileFromCache(profile_path); 85 profile_info_cache_->DeleteProfileFromCache(profile_path);
83 RunPendingTasks(); 86 RunPendingTasks();
84 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name)); 87 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name));
85 ASSERT_FALSE(file_util::PathExists(profile_path.Append( 88 ASSERT_FALSE(file_util::PathExists(profile_path.Append(
86 FILE_PATH_LITERAL("Google Profile.ico")))); 89 FILE_PATH_LITERAL("Google Profile.ico"))));
87 } 90 }
88 } 91 }
89 92
90 void RunPendingTasks() { 93 void RunPendingTasks() {
91 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 94 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
92 MessageLoop::current()->Run(); 95 MessageLoop::current()->Run();
93 } 96 }
94 97
95 void SetupDefaultProfileShortcut() { 98 void SetupDefaultProfileShortcut(const tracked_objects::Location& location) {
96 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name_)); 99 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_));
sail 2012/11/28 05:12:31 did you want to add a "<< location.ToString()" her
Alexei Svitkine (slow) 2012/11/28 21:27:12 Done.
97 // A non-badged shortcut for chrome is automatically created with the 100 // A non-badged shortcut for chrome is automatically created with the
98 // first profile (for the case when the user deletes their only profile). 101 // first profile (for the case when the user deletes their only profile).
99 profile_info_cache_->AddProfileToCache(dest_path_, profile_name_, 102 profile_info_cache_->AddProfileToCache(profile_1_path_, profile_1_name_,
100 string16(), 0); 103 string16(), 0);
101 RunPendingTasks(); 104 RunPendingTasks();
102 // We now have 1 profile, so we expect a new shortcut with no profile 105 // We now have 1 profile, so we expect a new shortcut with no profile
103 // information. 106 // information.
104 ValidateProfileShortcut(string16()); 107 ValidateProfileShortcut(location, string16());
105 } 108 }
106 109
107 void SetupAndCreateTwoShortcuts() { 110 void SetupAndCreateTwoShortcuts(const tracked_objects::Location& location) {
108 ASSERT_EQ(0, profile_info_cache_->GetNumberOfProfiles()); 111 ASSERT_EQ(0, profile_info_cache_->GetNumberOfProfiles())
109 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name_)); 112 << location.ToString();
110 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); 113 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_))
114 << location.ToString();
111 115
112 profile_info_cache_->AddProfileToCache(dest_path_, profile_name_, 116 profile_info_cache_->AddProfileToCache(profile_1_path_, profile_1_name_,
113 string16(), 0); 117 string16(), 0);
114 profile_info_cache_->AddProfileToCache(second_dest_path_, 118 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
sail 2012/11/28 05:12:31 why pass FROM_HERE instead of location?
Alexei Svitkine (slow) 2012/11/28 21:27:12 Done.
115 second_profile_name_, string16(), 0); 119 ValidateProfileShortcut(location, profile_1_name_);
116 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_);
117 RunPendingTasks();
118 ValidateProfileShortcut(profile_name_);
119 ValidateProfileShortcut(second_profile_name_);
120 } 120 }
121 121
122 // Returns the default shortcut path for this profile. 122 // Returns the default shortcut path for this profile.
123 FilePath GetDefaultShortcutPathForProfile(const string16& profile_name) { 123 FilePath GetDefaultShortcutPathForProfile(const string16& profile_name) {
124 return shortcuts_directory_.Append( 124 return shortcuts_directory_.Append(
125 profiles::internal::GetShortcutFilenameForProfile(profile_name, 125 profiles::internal::GetShortcutFilenameForProfile(profile_name,
126 distribution_)); 126 distribution_));
127 } 127 }
128 128
129 // Returns true if the shortcut for this profile exists. 129 // Returns true if the shortcut for this profile exists.
130 bool ProfileShortcutExistsAtDefaultPath(const string16& profile_name) { 130 bool ProfileShortcutExistsAtDefaultPath(const string16& profile_name) {
131 return file_util::PathExists( 131 return file_util::PathExists(
132 GetDefaultShortcutPathForProfile(profile_name)); 132 GetDefaultShortcutPathForProfile(profile_name));
133 } 133 }
134 134
135 // Calls base::win::ValidateShortcut() with expected properties for 135 // Calls base::win::ValidateShortcut() with expected properties for
136 // |profile_name|'s shortcut. 136 // |profile_name|'s shortcut.
137 void ValidateProfileShortcut(const string16& profile_name) { 137 void ValidateProfileShortcut(const tracked_objects::Location& location,
138 EXPECT_TRUE(ProfileShortcutExistsAtDefaultPath(profile_name)); 138 const string16& profile_name) {
139
140 FilePath shortcut_path = GetDefaultShortcutPathForProfile(profile_name); 139 FilePath shortcut_path = GetDefaultShortcutPathForProfile(profile_name);
140 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString();
141 141
142 // TODO(asvitkine): With this new struct method for VerifyShortcut you can 142 // TODO(asvitkine): With this new struct method for VerifyShortcut you can
143 // now test more properties like: arguments, icon, icon_index, and app_id. 143 // now test more properties like: arguments, icon, icon_index, and app_id.
144 base::win::ShortcutProperties expected_properties; 144 base::win::ShortcutProperties expected_properties;
145 expected_properties.set_target(exe_path_); 145 expected_properties.set_target(exe_path_);
146 expected_properties.set_description(distribution_->GetAppDescription()); 146 expected_properties.set_description(distribution_->GetAppDescription());
147 expected_properties.set_dual_mode(false); 147 expected_properties.set_dual_mode(false);
148 base::win::ValidateShortcut(shortcut_path, expected_properties); 148 base::win::ValidateShortcut(shortcut_path, expected_properties);
149 } 149 }
150 150
151 void CreateProfileWithShortcut(const tracked_objects::Location& location,
152 const string16& profile_name,
153 const FilePath& profile_path) {
154 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name))
155 << location.ToString();
156 profile_info_cache_->AddProfileToCache(profile_path, profile_name,
157 string16(), 0);
158 profile_shortcut_manager_->CreateProfileShortcut(profile_path);
159 RunPendingTasks();
160 ValidateProfileShortcut(location, profile_name);
161 }
162
163 // Creates a regular (non-profile) desktop shortcut with the given name and
164 // returns its path. Fails the test if an error occurs.
165 FilePath CreateRegularShortcutWithName(
166 const tracked_objects::Location& location,
167 const string16& shortcut_name) {
168 const FilePath shortcut_path =
169 shortcuts_directory_.Append(shortcut_name + installer::kLnkExt);
170 EXPECT_FALSE(file_util::PathExists(shortcut_path)) << location.ToString();
171
172 installer::Product product(distribution_);
173 ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER);
174 product.AddDefaultShortcutProperties(exe_path_, &properties);
175 properties.set_shortcut_name(shortcut_name);
176 EXPECT_TRUE(ShellUtil::CreateOrUpdateShortcut(
177 ShellUtil::SHORTCUT_LOCATION_DESKTOP, distribution_, properties,
178 ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS)) << location.ToString();
179 EXPECT_TRUE(file_util::PathExists(shortcut_path)) << location.ToString();
180
181 return shortcut_path;
182 }
183
151 BrowserDistribution* distribution_; 184 BrowserDistribution* distribution_;
152 MessageLoopForUI message_loop_; 185 MessageLoopForUI message_loop_;
153 content::TestBrowserThread ui_thread_; 186 content::TestBrowserThread ui_thread_;
154 content::TestBrowserThread file_thread_; 187 content::TestBrowserThread file_thread_;
155 scoped_ptr<TestingProfileManager> profile_manager_; 188 scoped_ptr<TestingProfileManager> profile_manager_;
156 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_; 189 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_;
157 ProfileInfoCache* profile_info_cache_; 190 ProfileInfoCache* profile_info_cache_;
158 base::ScopedPathOverride fake_user_desktop_; 191 base::ScopedPathOverride fake_user_desktop_;
159 FilePath exe_path_; 192 FilePath exe_path_;
160 FilePath dest_path_;
161 FilePath shortcuts_directory_; 193 FilePath shortcuts_directory_;
162 string16 profile_name_; 194 string16 profile_1_name_;
163 FilePath second_dest_path_; 195 FilePath profile_1_path_;
164 string16 second_profile_name_; 196 string16 profile_2_name_;
197 FilePath profile_2_path_;
165 }; 198 };
166 199
167 TEST_F(ProfileShortcutManagerTest, ShortcutFilename) { 200 TEST_F(ProfileShortcutManagerTest, ShortcutFilename) {
168 const string16 kProfileName = L"Harry"; 201 const string16 kProfileName = L"Harry";
169 const string16 expected_name = kProfileName + L" - " + 202 const string16 expected_name = kProfileName + L" - " +
170 distribution_->GetAppShortCutName() + installer::kLnkExt; 203 distribution_->GetAppShortCutName() + installer::kLnkExt;
171 EXPECT_EQ(expected_name, 204 EXPECT_EQ(expected_name,
172 profiles::internal::GetShortcutFilenameForProfile(kProfileName, 205 profiles::internal::GetShortcutFilenameForProfile(kProfileName,
173 distribution_)); 206 distribution_));
174 } 207 }
175 208
176 TEST_F(ProfileShortcutManagerTest, UnbadgedShortcutFilename) { 209 TEST_F(ProfileShortcutManagerTest, UnbadgedShortcutFilename) {
177 EXPECT_EQ(distribution_->GetAppShortCutName() + installer::kLnkExt, 210 EXPECT_EQ(distribution_->GetAppShortCutName() + installer::kLnkExt,
178 profiles::internal::GetShortcutFilenameForProfile(string16(), 211 profiles::internal::GetShortcutFilenameForProfile(string16(),
179 distribution_)); 212 distribution_));
180 } 213 }
181 214
182 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) { 215 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) {
183 ProfileShortcutManagerTest::SetupDefaultProfileShortcut(); 216 SetupDefaultProfileShortcut(FROM_HERE);
184 217 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
185 profile_info_cache_->AddProfileToCache(second_dest_path_,
186 second_profile_name_, string16(), 0);
187 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_);
188 RunPendingTasks();
189
190 // We now have 2 profiles, so we expect a new shortcut with profile 218 // We now have 2 profiles, so we expect a new shortcut with profile
191 // information for this 2nd profile. 219 // information for this 2nd profile.
192 ValidateProfileShortcut(second_profile_name_); 220 ASSERT_TRUE(file_util::PathExists(profile_2_path_.Append(
193 ASSERT_TRUE(file_util::PathExists(second_dest_path_.Append(
194 FILE_PATH_LITERAL("Google Profile.ico")))); 221 FILE_PATH_LITERAL("Google Profile.ico"))));
sail 2012/11/28 05:12:31 should we just get rid of all these FILE_PATH_LITE
Alexei Svitkine (slow) 2012/11/28 21:27:12 Done. I also made all of these use the constant fr
195 } 222 }
196 223
197 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsUpdate) { 224 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsUpdate) {
198 ProfileShortcutManagerTest::SetupDefaultProfileShortcut(); 225 SetupDefaultProfileShortcut(FROM_HERE);
199 226 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
200 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_));
201
202 profile_info_cache_->AddProfileToCache(second_dest_path_,
203 second_profile_name_, string16(), 0);
204 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_);
205 RunPendingTasks();
206 ValidateProfileShortcut(second_profile_name_);
207 227
208 // Cause an update in ProfileShortcutManager by modifying the profile info 228 // Cause an update in ProfileShortcutManager by modifying the profile info
209 // cache. 229 // cache.
210 const string16 new_profile_name = L"New Profile Name"; 230 const string16 new_profile_name = L"New Profile Name";
211 profile_info_cache_->SetNameOfProfileAtIndex( 231 profile_info_cache_->SetNameOfProfileAtIndex(
212 profile_info_cache_->GetIndexOfProfileWithPath(second_dest_path_), 232 profile_info_cache_->GetIndexOfProfileWithPath(profile_2_path_),
213 new_profile_name); 233 new_profile_name);
214 RunPendingTasks(); 234 RunPendingTasks();
215 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); 235 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_));
216 ValidateProfileShortcut(new_profile_name); 236 ValidateProfileShortcut(FROM_HERE, new_profile_name);
217 } 237 }
218 238
219 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsDeleteSecondToLast) { 239 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsDeleteSecondToLast) {
220 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts(); 240 SetupAndCreateTwoShortcuts(FROM_HERE);
221 241
222 // Delete one shortcut. 242 // Delete one shortcut.
223 profile_info_cache_->DeleteProfileFromCache(second_dest_path_); 243 profile_info_cache_->DeleteProfileFromCache(profile_2_path_);
224 RunPendingTasks(); 244 RunPendingTasks();
225 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); 245 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_));
226 246
227 // Verify that the profile name has been removed from the remaining shortcut. 247 // Verify that the profile name has been removed from the remaining shortcut.
228 ValidateProfileShortcut(string16()); 248 ValidateProfileShortcut(FROM_HERE, string16());
229 // Verify that an additional shortcut, with the default profile's name does 249 // Verify that an additional shortcut, with the default profile's name does
230 // not exist. 250 // not exist.
231 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name_)); 251 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_));
232 } 252 }
233 253
234 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreateSecond) { 254 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreateSecond) {
235 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts(); 255 SetupAndCreateTwoShortcuts(FROM_HERE);
236 256
237 // Delete one shortcut. 257 // Delete one shortcut.
238 profile_info_cache_->DeleteProfileFromCache(second_dest_path_); 258 profile_info_cache_->DeleteProfileFromCache(profile_2_path_);
239 RunPendingTasks(); 259 RunPendingTasks();
240 260
241 // Verify that a default shortcut exists (no profile name/avatar). 261 // Verify that a default shortcut exists (no profile name/avatar).
242 ValidateProfileShortcut(string16()); 262 ValidateProfileShortcut(FROM_HERE, string16());
243 // Verify that an additional shortcut, with the default profile's name does 263 // Verify that an additional shortcut, with the first profile's name does
244 // not exist. 264 // not exist.
245 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name_)); 265 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_));
246 266
247 // Create a second profile and shortcut. 267 // Create a second profile and shortcut.
248 profile_info_cache_->AddProfileToCache(second_dest_path_, 268 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
249 second_profile_name_, string16(), 0);
250 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_);
251 RunPendingTasks();
252 ValidateProfileShortcut(second_profile_name_);
253 269
254 // Verify that the original shortcut received the profile's name. 270 // Verify that the original shortcut received the profile's name.
255 ValidateProfileShortcut(profile_name_); 271 ValidateProfileShortcut(FROM_HERE, profile_1_name_);
256 // Verify that a default shortcut no longer exists. 272 // Verify that a default shortcut no longer exists.
257 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(string16())); 273 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(string16()));
258 } 274 }
259 275
260 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcuts) { 276 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcuts) {
261 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts(); 277 SetupAndCreateTwoShortcuts(FROM_HERE);
262 278
263 const FilePath old_shortcut_path = 279 const FilePath old_shortcut_path =
264 GetDefaultShortcutPathForProfile(second_profile_name_); 280 GetDefaultShortcutPathForProfile(profile_2_name_);
265 const FilePath new_shortcut_path = 281 const FilePath new_shortcut_path =
266 shortcuts_directory_.Append(L"MyChrome.lnk"); 282 shortcuts_directory_.Append(L"MyChrome.lnk");
267 ASSERT_TRUE(file_util::Move(old_shortcut_path, new_shortcut_path)); 283 ASSERT_TRUE(file_util::Move(old_shortcut_path, new_shortcut_path));
268 284
269 // Ensure that a new shortcut does not get made if the old one was renamed. 285 // Ensure that a new shortcut does not get made if the old one was renamed.
270 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); 286 profile_shortcut_manager_->CreateProfileShortcut(profile_2_path_);
271 RunPendingTasks(); 287 RunPendingTasks();
272 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); 288 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_));
273 EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); 289 EXPECT_TRUE(file_util::PathExists(new_shortcut_path));
274 290
275 // Delete the renamed shortcut and try to create it again, which should work. 291 // Delete the renamed shortcut and try to create it again, which should work.
276 ASSERT_TRUE(file_util::Delete(new_shortcut_path, false)); 292 ASSERT_TRUE(file_util::Delete(new_shortcut_path, false));
277 EXPECT_FALSE(file_util::PathExists(new_shortcut_path)); 293 EXPECT_FALSE(file_util::PathExists(new_shortcut_path));
278 profile_shortcut_manager_->CreateProfileShortcut(second_dest_path_); 294 profile_shortcut_manager_->CreateProfileShortcut(profile_2_path_);
279 RunPendingTasks(); 295 RunPendingTasks();
280 EXPECT_TRUE(ProfileShortcutExistsAtDefaultPath(second_profile_name_)); 296 EXPECT_TRUE(ProfileShortcutExistsAtDefaultPath(profile_2_name_));
281 } 297 }
282 298
283 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsGetDeleted) { 299 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsGetDeleted) {
284 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts(); 300 SetupAndCreateTwoShortcuts(FROM_HERE);
285 301
286 const FilePath old_shortcut_path = 302 const FilePath old_shortcut_path =
287 GetDefaultShortcutPathForProfile(second_profile_name_); 303 GetDefaultShortcutPathForProfile(profile_2_name_);
288 const FilePath new_shortcut_path = 304 const FilePath new_shortcut_path =
289 shortcuts_directory_.Append(L"MyChrome.lnk"); 305 shortcuts_directory_.Append(L"MyChrome.lnk");
290 // Make a copy of the shortcut. 306 // Make a copy of the shortcut.
291 ASSERT_TRUE(file_util::CopyFile(old_shortcut_path, new_shortcut_path)); 307 ASSERT_TRUE(file_util::CopyFile(old_shortcut_path, new_shortcut_path));
292 EXPECT_TRUE(file_util::PathExists(old_shortcut_path)); 308 EXPECT_TRUE(file_util::PathExists(old_shortcut_path));
293 EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); 309 EXPECT_TRUE(file_util::PathExists(new_shortcut_path));
294 310
295 // Also, copy the shortcut for the first user and ensure it gets preserved. 311 // Also, copy the shortcut for the first user and ensure it gets preserved.
296 const FilePath preserved_shortcut_path = 312 const FilePath preserved_shortcut_path =
297 shortcuts_directory_.Append(L"Preserved.lnk"); 313 shortcuts_directory_.Append(L"Preserved.lnk");
298 ASSERT_TRUE(file_util::CopyFile( 314 ASSERT_TRUE(file_util::CopyFile(
299 GetDefaultShortcutPathForProfile(profile_name_), 315 GetDefaultShortcutPathForProfile(profile_1_name_),
300 preserved_shortcut_path)); 316 preserved_shortcut_path));
301 EXPECT_TRUE(file_util::PathExists(preserved_shortcut_path)); 317 EXPECT_TRUE(file_util::PathExists(preserved_shortcut_path));
302 318
303 // Delete the profile and ensure both shortcuts were also deleted. 319 // Delete the profile and ensure both shortcuts were also deleted.
304 profile_info_cache_->DeleteProfileFromCache(second_dest_path_); 320 profile_info_cache_->DeleteProfileFromCache(profile_2_path_);
305 RunPendingTasks(); 321 RunPendingTasks();
306 EXPECT_FALSE(file_util::PathExists(old_shortcut_path)); 322 EXPECT_FALSE(file_util::PathExists(old_shortcut_path));
307 EXPECT_FALSE(file_util::PathExists(new_shortcut_path)); 323 EXPECT_FALSE(file_util::PathExists(new_shortcut_path));
308 EXPECT_TRUE(file_util::PathExists(preserved_shortcut_path)); 324 EXPECT_TRUE(file_util::PathExists(preserved_shortcut_path));
309 } 325 }
310 326
311 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsAfterProfileRename) { 327 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsAfterProfileRename) {
312 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts(); 328 SetupAndCreateTwoShortcuts(FROM_HERE);
313 329
314 const FilePath old_shortcut_path = 330 const FilePath old_shortcut_path =
315 GetDefaultShortcutPathForProfile(second_profile_name_); 331 GetDefaultShortcutPathForProfile(profile_2_name_);
316 const FilePath new_shortcut_path = 332 const FilePath new_shortcut_path =
317 shortcuts_directory_.Append(L"MyChrome.lnk"); 333 shortcuts_directory_.Append(L"MyChrome.lnk");
318 334
319 // Make a copy of the shortcut. 335 // Make a copy of the shortcut.
320 ASSERT_TRUE(file_util::CopyFile(old_shortcut_path, new_shortcut_path)); 336 ASSERT_TRUE(file_util::CopyFile(old_shortcut_path, new_shortcut_path));
321 EXPECT_TRUE(file_util::PathExists(old_shortcut_path)); 337 EXPECT_TRUE(file_util::PathExists(old_shortcut_path));
322 EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); 338 EXPECT_TRUE(file_util::PathExists(new_shortcut_path));
323 339
324 // Now, rename the profile. 340 // Now, rename the profile.
325 const string16 new_profile_name = L"New profile"; 341 const string16 new_profile_name = L"New profile";
326 ASSERT_NE(second_profile_name_, new_profile_name); 342 ASSERT_NE(profile_2_name_, new_profile_name);
327 profile_info_cache_->SetNameOfProfileAtIndex( 343 profile_info_cache_->SetNameOfProfileAtIndex(
328 profile_info_cache_->GetIndexOfProfileWithPath(second_dest_path_), 344 profile_info_cache_->GetIndexOfProfileWithPath(profile_2_path_),
329 new_profile_name); 345 new_profile_name);
330 RunPendingTasks(); 346 RunPendingTasks();
331 347
332 // The original shortcut should be renamed but the copied shortcut should 348 // The original shortcut should be renamed but the copied shortcut should
333 // keep its name. 349 // keep its name.
334 EXPECT_FALSE(file_util::PathExists(old_shortcut_path)); 350 EXPECT_FALSE(file_util::PathExists(old_shortcut_path));
335 EXPECT_TRUE(file_util::PathExists(new_shortcut_path)); 351 EXPECT_TRUE(file_util::PathExists(new_shortcut_path));
336 const FilePath updated_shortcut_path = 352 const FilePath updated_shortcut_path =
337 GetDefaultShortcutPathForProfile(new_profile_name); 353 GetDefaultShortcutPathForProfile(new_profile_name);
338 EXPECT_TRUE(file_util::PathExists(updated_shortcut_path)); 354 EXPECT_TRUE(file_util::PathExists(updated_shortcut_path));
339 } 355 }
340 356
357 TEST_F(ProfileShortcutManagerTest, UpdateShortcutWithNoFlags) {
358 SetupDefaultProfileShortcut(FROM_HERE);
359
360 // Delete the shortcut that got created for this profile and instead make
361 // a new one without any command-line flags.
362 ASSERT_TRUE(file_util::Delete(GetDefaultShortcutPathForProfile(string16()),
363 false));
364 const FilePath regular_shortcut_path =
365 CreateRegularShortcutWithName(FROM_HERE,
366 distribution_->GetAppShortCutName());
367
368 // Add another profile and check that the shortcut was renamed.
369 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
370
371 EXPECT_FALSE(file_util::PathExists(regular_shortcut_path));
372 const FilePath new_shortcut_path =
sail 2012/11/28 05:12:31 maybe new_profile_1_shortcut_path
Alexei Svitkine (slow) 2012/11/28 21:27:12 I've made ValidateProfileShortcut() check the flag
373 GetDefaultShortcutPathForProfile(profile_1_name_);
374 EXPECT_TRUE(file_util::PathExists(new_shortcut_path));
375
376 // Check that the renamed shortcut has the correct command line flags set.
377 string16 shortcut_args;
sail 2012/11/28 05:12:31 maybe profile_1_shortcut_args?
Alexei Svitkine (slow) 2012/11/28 21:27:12 This is now done in ValidateProfileShortcut().
378 ASSERT_TRUE(base::win::ResolveShortcut(new_shortcut_path, NULL,
379 &shortcut_args));
380 const string16 expected_args =
381 profiles::internal::CreateProfileShortcutFlags(profile_1_path_);
382 EXPECT_NE(string16::npos, shortcut_args.find(expected_args));
383 }
384
385 TEST_F(ProfileShortcutManagerTest, UpdateTwoShortcutsWithNoFlags) {
386 SetupDefaultProfileShortcut(FROM_HERE);
387
388 // Delete the shortcut that got created for this profile and instead make
389 // two new ones without any command-line flags.
390 ASSERT_TRUE(file_util::Delete(GetDefaultShortcutPathForProfile(string16()),
391 false));
392 const FilePath regular_shortcut_path =
393 CreateRegularShortcutWithName(FROM_HERE,
394 distribution_->GetAppShortCutName());
395 const FilePath second_shortcut_path =
sail 2012/11/28 05:12:31 I find spelling out second harder to parse. How ab
Alexei Svitkine (slow) 2012/11/28 21:27:12 Done.
396 CreateRegularShortcutWithName(FROM_HERE, L"MyChrome");
397 EXPECT_TRUE(file_util::PathExists(second_shortcut_path));
sail 2012/11/28 05:12:31 don't need this
Alexei Svitkine (slow) 2012/11/28 21:27:12 Done.
398
399 // Add another profile and check that one shortcut was renamed and that the
400 // other shortcut was updated but kept the same name.
401 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
402 EXPECT_FALSE(file_util::PathExists(regular_shortcut_path));
403 EXPECT_TRUE(file_util::PathExists(second_shortcut_path));
404
405 const FilePath new_shortcut_path =
sail 2012/11/28 05:12:31 same as above, maybe "new_profile_1_shortcut_path"
Alexei Svitkine (slow) 2012/11/28 21:27:12 Done.
406 GetDefaultShortcutPathForProfile(profile_1_name_);
407 EXPECT_TRUE(file_util::PathExists(new_shortcut_path));
408
409 // Check that both shortcuts have the correct command line flags set.
410 const string16 expected_args =
411 profiles::internal::CreateProfileShortcutFlags(profile_1_path_);
412 string16 shortcut_args;
413 ASSERT_TRUE(base::win::ResolveShortcut(new_shortcut_path, NULL,
414 &shortcut_args));
415 EXPECT_NE(string16::npos, shortcut_args.find(expected_args));
416
417 shortcut_args.clear();
418 ASSERT_TRUE(base::win::ResolveShortcut(second_shortcut_path, NULL,
419 &shortcut_args));
420 EXPECT_NE(string16::npos, shortcut_args.find(expected_args));
421 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698