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

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

Issue 1242793005: Refactor most c/b/profiles calls to ProfileInfoCache. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Windows unit test and ChromeOS build Created 5 years, 5 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 <objbase.h> // For CoInitialize(). 5 #include <objbase.h> // For CoInitialize().
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/test/scoped_path_override.h" 13 #include "base/test/scoped_path_override.h"
14 #include "base/test/test_shortcut_win.h" 14 #include "base/test/test_shortcut_win.h"
15 #include "base/win/shortcut.h" 15 #include "base/win/shortcut.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/profiles/profile_attributes_entry.h"
18 #include "chrome/browser/profiles/profile_attributes_storage.h"
17 #include "chrome/browser/profiles/profile_manager.h" 19 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/profiles/profile_shortcut_manager.h" 20 #include "chrome/browser/profiles/profile_shortcut_manager.h"
19 #include "chrome/browser/profiles/profile_shortcut_manager_win.h" 21 #include "chrome/browser/profiles/profile_shortcut_manager_win.h"
20 #include "chrome/browser/shell_integration.h" 22 #include "chrome/browser/shell_integration.h"
21 #include "chrome/grit/chromium_strings.h" 23 #include "chrome/grit/chromium_strings.h"
22 #include "chrome/installer/util/browser_distribution.h" 24 #include "chrome/installer/util/browser_distribution.h"
23 #include "chrome/installer/util/product.h" 25 #include "chrome/installer/util/product.h"
24 #include "chrome/installer/util/shell_util.h" 26 #include "chrome/installer/util/shell_util.h"
25 #include "chrome/test/base/testing_browser_process.h" 27 #include "chrome/test/base/testing_browser_process.h"
26 #include "chrome/test/base/testing_profile.h" 28 #include "chrome/test/base/testing_profile.h"
27 #include "chrome/test/base/testing_profile_manager.h" 29 #include "chrome/test/base/testing_profile_manager.h"
28 #include "content/public/test/test_browser_thread.h" 30 #include "content/public/test/test_browser_thread.h"
29 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
30 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
31 33
32 using content::BrowserThread; 34 using content::BrowserThread;
33 35
34 class ProfileShortcutManagerTest : public testing::Test { 36 class ProfileShortcutManagerTest : public testing::Test {
35 protected: 37 protected:
36 ProfileShortcutManagerTest() 38 ProfileShortcutManagerTest()
37 : ui_thread_(BrowserThread::UI, &message_loop_), 39 : ui_thread_(BrowserThread::UI, &message_loop_),
38 file_thread_(BrowserThread::FILE, &message_loop_), 40 file_thread_(BrowserThread::FILE, &message_loop_),
39 profile_info_cache_(NULL), 41 profile_attributes_storage_(NULL),
40 fake_user_desktop_(base::DIR_USER_DESKTOP), 42 fake_user_desktop_(base::DIR_USER_DESKTOP),
41 fake_system_desktop_(base::DIR_COMMON_DESKTOP) { 43 fake_system_desktop_(base::DIR_COMMON_DESKTOP) {
42 } 44 }
43 45
44 void SetUp() override { 46 void SetUp() override {
45 CoInitialize(NULL); 47 CoInitialize(NULL);
46 48
47 TestingBrowserProcess* browser_process = 49 TestingBrowserProcess* browser_process =
48 TestingBrowserProcess::GetGlobal(); 50 TestingBrowserProcess::GetGlobal();
49 profile_manager_.reset(new TestingProfileManager(browser_process)); 51 profile_manager_.reset(new TestingProfileManager(browser_process));
50 ASSERT_TRUE(profile_manager_->SetUp()); 52 ASSERT_TRUE(profile_manager_->SetUp());
51 profile_info_cache_ = profile_manager_->profile_info_cache(); 53 profile_attributes_storage_ =
54 profile_manager_->profile_attributes_storage();
52 profile_shortcut_manager_.reset( 55 profile_shortcut_manager_.reset(
53 ProfileShortcutManager::Create(profile_manager_->profile_manager())); 56 ProfileShortcutManager::Create(profile_manager_->profile_manager()));
54 profile_1_name_ = L"My profile"; 57 profile_1_name_ = L"My profile";
55 profile_1_path_ = CreateProfileDirectory(profile_1_name_); 58 profile_1_path_ = CreateProfileDirectory(profile_1_name_);
56 profile_2_name_ = L"My profile 2"; 59 profile_2_name_ = L"My profile 2";
57 profile_2_path_ = CreateProfileDirectory(profile_2_name_); 60 profile_2_path_ = CreateProfileDirectory(profile_2_name_);
58 profile_3_name_ = L"My profile 3"; 61 profile_3_name_ = L"My profile 3";
59 profile_3_path_ = CreateProfileDirectory(profile_3_name_); 62 profile_3_path_ = CreateProfileDirectory(profile_3_name_);
60 } 63 }
61 64
62 void TearDown() override { 65 void TearDown() override {
63 message_loop_.RunUntilIdle(); 66 message_loop_.RunUntilIdle();
64 67
65 // Delete all profiles and ensure their shortcuts got removed. 68 // Delete all profiles and ensure their shortcuts got removed.
66 const int num_profiles = profile_info_cache_->GetNumberOfProfiles(); 69 const int num_profiles = profile_attributes_storage_->GetNumberOfProfiles();
67 for (int i = 0; i < num_profiles; ++i) { 70 for (int i = 0; i < num_profiles; ++i) {
68 const base::FilePath profile_path = 71 std::vector<ProfileAttributesEntry*> entries =
69 profile_info_cache_->GetPathOfProfileAtIndex(0); 72 profile_attributes_storage_->GetAllProfilesAttributes();
70 base::string16 profile_name = 73 const base::FilePath profile_path = entries[0]->GetPath();
71 profile_info_cache_->GetNameOfProfileAtIndex(0); 74 base::string16 profile_name = entries[0]->GetName();
72 profile_info_cache_->DeleteProfileFromCache(profile_path); 75 profile_attributes_storage_->RemoveProfile(profile_path);
73 RunPendingTasks(); 76 RunPendingTasks();
74 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name)); 77 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name));
75 // The icon file is not deleted until the profile directory is deleted. 78 // The icon file is not deleted until the profile directory is deleted.
76 const base::FilePath icon_path = 79 const base::FilePath icon_path =
77 profiles::internal::GetProfileIconPath(profile_path); 80 profiles::internal::GetProfileIconPath(profile_path);
78 ASSERT_TRUE(base::PathExists(icon_path)); 81 ASSERT_TRUE(base::PathExists(icon_path));
79 } 82 }
80 } 83 }
81 84
82 base::FilePath CreateProfileDirectory(const base::string16& profile_name) { 85 base::FilePath CreateProfileDirectory(const base::string16& profile_name) {
83 const base::FilePath profile_path = 86 const base::FilePath profile_path =
84 profile_info_cache_->GetUserDataDir().Append(profile_name); 87 profile_attributes_storage_->GetUserDataDir().Append(profile_name);
85 base::CreateDirectory(profile_path); 88 base::CreateDirectory(profile_path);
86 return profile_path; 89 return profile_path;
87 } 90 }
88 91
89 void RunPendingTasks() { 92 void RunPendingTasks() {
90 base::MessageLoop::current()->PostTask(FROM_HERE, 93 base::MessageLoop::current()->PostTask(FROM_HERE,
91 base::MessageLoop::QuitClosure()); 94 base::MessageLoop::QuitClosure());
92 base::MessageLoop::current()->Run(); 95 base::MessageLoop::current()->Run();
93 } 96 }
94 97
95 void SetupDefaultProfileShortcut(const tracked_objects::Location& location) { 98 void SetupDefaultProfileShortcut(const tracked_objects::Location& location) {
96 ASSERT_EQ(0, profile_info_cache_->GetNumberOfProfiles()) 99 ASSERT_EQ(0, profile_attributes_storage_->GetNumberOfProfiles())
97 << location.ToString(); 100 << location.ToString();
98 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)) 101 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_))
99 << location.ToString(); 102 << location.ToString();
100 profile_info_cache_->AddProfileToCache(profile_1_path_, profile_1_name_, 103 profile_attributes_storage_->AddProfile(profile_1_path_, profile_1_name_,
101 std::string(), base::string16(), 0, 104 std::string(), base::string16(), 0,
102 std::string()); 105 std::string());
103 // Also create a non-badged shortcut for Chrome, which is conveniently done 106 // Also create a non-badged shortcut for Chrome, which is conveniently done
104 // by |CreateProfileShortcut()| since there is only one profile. 107 // by |CreateProfileShortcut()| since there is only one profile.
105 profile_shortcut_manager_->CreateProfileShortcut(profile_1_path_); 108 profile_shortcut_manager_->CreateProfileShortcut(profile_1_path_);
106 RunPendingTasks(); 109 RunPendingTasks();
107 // Verify that there's now a shortcut with no profile information. 110 // Verify that there's now a shortcut with no profile information.
108 ValidateNonProfileShortcut(location); 111 ValidateNonProfileShortcut(location);
109 } 112 }
110 113
111 void SetupAndCreateTwoShortcuts(const tracked_objects::Location& location) { 114 void SetupAndCreateTwoShortcuts(const tracked_objects::Location& location) {
112 SetupDefaultProfileShortcut(location); 115 SetupDefaultProfileShortcut(location);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 const base::FilePath shortcut_path = 182 const base::FilePath shortcut_path =
180 GetDefaultShortcutPathForProfile(base::string16()); 183 GetDefaultShortcutPathForProfile(base::string16());
181 ValidateNonProfileShortcutAtPath(location, shortcut_path); 184 ValidateNonProfileShortcutAtPath(location, shortcut_path);
182 } 185 }
183 186
184 void CreateProfileWithShortcut(const tracked_objects::Location& location, 187 void CreateProfileWithShortcut(const tracked_objects::Location& location,
185 const base::string16& profile_name, 188 const base::string16& profile_name,
186 const base::FilePath& profile_path) { 189 const base::FilePath& profile_path) {
187 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name)) 190 ASSERT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_name))
188 << location.ToString(); 191 << location.ToString();
189 profile_info_cache_->AddProfileToCache(profile_path, profile_name, 192 profile_attributes_storage_->AddProfile(profile_path, profile_name,
190 std::string(), base::string16(), 0, 193 std::string(), base::string16(), 0,
191 std::string()); 194 std::string());
192 profile_shortcut_manager_->CreateProfileShortcut(profile_path); 195 profile_shortcut_manager_->CreateProfileShortcut(profile_path);
193 RunPendingTasks(); 196 RunPendingTasks();
194 ValidateProfileShortcut(location, profile_name, profile_path); 197 ValidateProfileShortcut(location, profile_name, profile_path);
195 } 198 }
196 199
197 // Creates a regular (non-profile) desktop shortcut with the given name and 200 // Creates a regular (non-profile) desktop shortcut with the given name and
198 // returns its path. Fails the test if an error occurs. 201 // returns its path. Fails the test if an error occurs.
199 base::FilePath CreateRegularShortcutWithName( 202 base::FilePath CreateRegularShortcutWithName(
200 const tracked_objects::Location& location, 203 const tracked_objects::Location& location,
201 const base::string16& shortcut_name) { 204 const base::string16& shortcut_name) {
(...skipping 28 matching lines...) Expand all
230 GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + 233 GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
231 installer::kLnkExt); 234 installer::kLnkExt);
232 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)) 235 EXPECT_TRUE(base::PathExists(system_level_shortcut_path))
233 << location.ToString(); 236 << location.ToString();
234 return system_level_shortcut_path; 237 return system_level_shortcut_path;
235 } 238 }
236 239
237 void RenameProfile(const tracked_objects::Location& location, 240 void RenameProfile(const tracked_objects::Location& location,
238 const base::FilePath& profile_path, 241 const base::FilePath& profile_path,
239 const base::string16& new_profile_name) { 242 const base::string16& new_profile_name) {
240 const size_t profile_index = 243 ProfileAttributesEntry* entry;
241 profile_info_cache_->GetIndexOfProfileWithPath(profile_2_path_); 244 ASSERT_TRUE(profile_attributes_storage_->GetProfileAttributesWithPath(
242 ASSERT_NE(std::string::npos, profile_index); 245 profile_2_path_, &entry));
243 ASSERT_NE(profile_info_cache_->GetNameOfProfileAtIndex(profile_index), 246 ASSERT_NE(entry->GetName(), new_profile_name);
244 new_profile_name); 247 entry->SetName(new_profile_name);
245 profile_info_cache_->SetNameOfProfileAtIndex(profile_index,
246 new_profile_name);
247 RunPendingTasks(); 248 RunPendingTasks();
248 } 249 }
249 250
250 BrowserDistribution* GetDistribution() { 251 BrowserDistribution* GetDistribution() {
251 return BrowserDistribution::GetDistribution(); 252 return BrowserDistribution::GetDistribution();
252 } 253 }
253 254
254 base::FilePath GetExePath() { 255 base::FilePath GetExePath() {
255 base::FilePath exe_path; 256 base::FilePath exe_path;
256 EXPECT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); 257 EXPECT_TRUE(PathService::Get(base::FILE_EXE, &exe_path));
(...skipping 16 matching lines...) Expand all
273 ShellUtil::SYSTEM_LEVEL, 274 ShellUtil::SYSTEM_LEVEL,
274 &system_shortcuts_directory)); 275 &system_shortcuts_directory));
275 return system_shortcuts_directory; 276 return system_shortcuts_directory;
276 } 277 }
277 278
278 base::MessageLoopForUI message_loop_; 279 base::MessageLoopForUI message_loop_;
279 content::TestBrowserThread ui_thread_; 280 content::TestBrowserThread ui_thread_;
280 content::TestBrowserThread file_thread_; 281 content::TestBrowserThread file_thread_;
281 scoped_ptr<TestingProfileManager> profile_manager_; 282 scoped_ptr<TestingProfileManager> profile_manager_;
282 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_; 283 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_;
283 ProfileInfoCache* profile_info_cache_; 284 ProfileAttributesStorage* profile_attributes_storage_;
284 base::ScopedPathOverride fake_user_desktop_; 285 base::ScopedPathOverride fake_user_desktop_;
285 base::ScopedPathOverride fake_system_desktop_; 286 base::ScopedPathOverride fake_system_desktop_;
286 base::string16 profile_1_name_; 287 base::string16 profile_1_name_;
287 base::FilePath profile_1_path_; 288 base::FilePath profile_1_path_;
288 base::string16 profile_2_name_; 289 base::string16 profile_2_name_;
289 base::FilePath profile_2_path_; 290 base::FilePath profile_2_path_;
290 base::string16 profile_3_name_; 291 base::string16 profile_3_name_;
291 base::FilePath profile_3_path_; 292 base::FilePath profile_3_path_;
292 }; 293 };
293 294
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 EXPECT_EQ( 329 EXPECT_EQ(
329 distribution->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) + 330 distribution->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME) +
330 installer::kLnkExt, 331 installer::kLnkExt,
331 profiles::internal::GetShortcutFilenameForProfile(base::string16(), 332 profiles::internal::GetShortcutFilenameForProfile(base::string16(),
332 distribution)); 333 distribution));
333 } 334 }
334 335
335 TEST_F(ProfileShortcutManagerTest, ShortcutFlags) { 336 TEST_F(ProfileShortcutManagerTest, ShortcutFlags) {
336 const base::string16 kProfileName = L"MyProfileX"; 337 const base::string16 kProfileName = L"MyProfileX";
337 const base::FilePath profile_path = 338 const base::FilePath profile_path =
338 profile_info_cache_->GetUserDataDir().Append(kProfileName); 339 profile_attributes_storage_->GetUserDataDir().Append(kProfileName);
339 EXPECT_EQ(L"--profile-directory=\"" + kProfileName + L"\"", 340 EXPECT_EQ(L"--profile-directory=\"" + kProfileName + L"\"",
340 profiles::internal::CreateProfileShortcutFlags(profile_path)); 341 profiles::internal::CreateProfileShortcutFlags(profile_path));
341 } 342 }
342 343
343 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) { 344 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) {
344 SetupDefaultProfileShortcut(FROM_HERE); 345 SetupDefaultProfileShortcut(FROM_HERE);
345 // Validation is done by |ValidateProfileShortcutAtPath()| which is called 346 // Validation is done by |ValidateProfileShortcutAtPath()| which is called
346 // by |CreateProfileWithShortcut()|. 347 // by |CreateProfileWithShortcut()|.
347 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); 348 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
348 } 349 }
349 350
350 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsUpdate) { 351 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsUpdate) {
351 SetupDefaultProfileShortcut(FROM_HERE); 352 SetupDefaultProfileShortcut(FROM_HERE);
352 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); 353 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
353 354
354 // Cause an update in ProfileShortcutManager by modifying the profile info 355 // Cause an update in ProfileShortcutManager by modifying the profile info
355 // cache. 356 // cache.
356 const base::string16 new_profile_2_name = L"New Profile Name"; 357 const base::string16 new_profile_2_name = L"New Profile Name";
357 RenameProfile(FROM_HERE, profile_2_path_, new_profile_2_name); 358 RenameProfile(FROM_HERE, profile_2_path_, new_profile_2_name);
358 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); 359 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_));
359 ValidateProfileShortcut(FROM_HERE, new_profile_2_name, profile_2_path_); 360 ValidateProfileShortcut(FROM_HERE, new_profile_2_name, profile_2_path_);
360 } 361 }
361 362
362 TEST_F(ProfileShortcutManagerTest, CreateSecondProfileBadgesFirstShortcut) { 363 TEST_F(ProfileShortcutManagerTest, CreateSecondProfileBadgesFirstShortcut) {
363 SetupDefaultProfileShortcut(FROM_HERE); 364 SetupDefaultProfileShortcut(FROM_HERE);
364 // Assert that a shortcut without a profile name exists. 365 // Assert that a shortcut without a profile name exists.
365 ASSERT_TRUE(ProfileShortcutExistsAtDefaultPath(base::string16())); 366 ASSERT_TRUE(ProfileShortcutExistsAtDefaultPath(base::string16()));
366 367
367 // Create a second profile without a shortcut. 368 // Create a second profile without a shortcut.
368 profile_info_cache_->AddProfileToCache(profile_2_path_, profile_2_name_, 369 profile_attributes_storage_->AddProfile(profile_2_path_, profile_2_name_,
369 std::string(), base::string16(), 0, 370 std::string(), base::string16(), 0,
370 std::string()); 371 std::string());
371 RunPendingTasks(); 372 RunPendingTasks();
372 373
373 // Ensure that the second profile doesn't have a shortcut and that the first 374 // Ensure that the second profile doesn't have a shortcut and that the first
374 // profile's shortcut got renamed and badged. 375 // profile's shortcut got renamed and badged.
375 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); 376 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_));
376 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(base::string16())); 377 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(base::string16()));
377 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); 378 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_);
378 } 379 }
379 380
380 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsDeleteSecondToLast) { 381 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsDeleteSecondToLast) {
381 SetupAndCreateTwoShortcuts(FROM_HERE); 382 SetupAndCreateTwoShortcuts(FROM_HERE);
382 383
383 // Delete one shortcut. 384 // Delete one shortcut.
384 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); 385 profile_attributes_storage_->RemoveProfile(profile_2_path_);
385 RunPendingTasks(); 386 RunPendingTasks();
386 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); 387 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_));
387 388
388 // Verify that the profile name has been removed from the remaining shortcut. 389 // Verify that the profile name has been removed from the remaining shortcut.
389 ValidateNonProfileShortcut(FROM_HERE); 390 ValidateNonProfileShortcut(FROM_HERE);
390 // Verify that an additional shortcut, with the default profile's name does 391 // Verify that an additional shortcut, with the default profile's name does
391 // not exist. 392 // not exist.
392 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)); 393 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_));
393 } 394 }
394 395
395 TEST_F(ProfileShortcutManagerTest, DeleteSecondToLastProfileWithoutShortcut) { 396 TEST_F(ProfileShortcutManagerTest, DeleteSecondToLastProfileWithoutShortcut) {
396 SetupAndCreateTwoShortcuts(FROM_HERE); 397 SetupAndCreateTwoShortcuts(FROM_HERE);
397 398
398 const base::FilePath profile_1_shortcut_path = 399 const base::FilePath profile_1_shortcut_path =
399 GetDefaultShortcutPathForProfile(profile_1_name_); 400 GetDefaultShortcutPathForProfile(profile_1_name_);
400 const base::FilePath profile_2_shortcut_path = 401 const base::FilePath profile_2_shortcut_path =
401 GetDefaultShortcutPathForProfile(profile_2_name_); 402 GetDefaultShortcutPathForProfile(profile_2_name_);
402 403
403 // Delete the shortcut for the first profile, but keep the one for the 2nd. 404 // Delete the shortcut for the first profile, but keep the one for the 2nd.
404 ASSERT_TRUE(base::DeleteFile(profile_1_shortcut_path, false)); 405 ASSERT_TRUE(base::DeleteFile(profile_1_shortcut_path, false));
405 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path)); 406 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path));
406 ASSERT_TRUE(base::PathExists(profile_2_shortcut_path)); 407 ASSERT_TRUE(base::PathExists(profile_2_shortcut_path));
407 408
408 // Delete the profile that doesn't have a shortcut. 409 // Delete the profile that doesn't have a shortcut.
409 profile_info_cache_->DeleteProfileFromCache(profile_1_path_); 410 profile_attributes_storage_->RemoveProfile(profile_1_path_);
410 RunPendingTasks(); 411 RunPendingTasks();
411 412
412 // Verify that the remaining shortcut does not have a profile name. 413 // Verify that the remaining shortcut does not have a profile name.
413 ValidateNonProfileShortcut(FROM_HERE); 414 ValidateNonProfileShortcut(FROM_HERE);
414 // Verify that shortcuts with profile names do not exist. 415 // Verify that shortcuts with profile names do not exist.
415 EXPECT_FALSE(base::PathExists(profile_1_shortcut_path)); 416 EXPECT_FALSE(base::PathExists(profile_1_shortcut_path));
416 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path)); 417 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path));
417 } 418 }
418 419
419 TEST_F(ProfileShortcutManagerTest, DeleteSecondToLastProfileWithShortcut) { 420 TEST_F(ProfileShortcutManagerTest, DeleteSecondToLastProfileWithShortcut) {
420 SetupAndCreateTwoShortcuts(FROM_HERE); 421 SetupAndCreateTwoShortcuts(FROM_HERE);
421 422
422 const base::FilePath profile_1_shortcut_path = 423 const base::FilePath profile_1_shortcut_path =
423 GetDefaultShortcutPathForProfile(profile_1_name_); 424 GetDefaultShortcutPathForProfile(profile_1_name_);
424 const base::FilePath profile_2_shortcut_path = 425 const base::FilePath profile_2_shortcut_path =
425 GetDefaultShortcutPathForProfile(profile_2_name_); 426 GetDefaultShortcutPathForProfile(profile_2_name_);
426 427
427 // Delete the shortcut for the first profile, but keep the one for the 2nd. 428 // Delete the shortcut for the first profile, but keep the one for the 2nd.
428 ASSERT_TRUE(base::DeleteFile(profile_1_shortcut_path, false)); 429 ASSERT_TRUE(base::DeleteFile(profile_1_shortcut_path, false));
429 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path)); 430 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path));
430 ASSERT_TRUE(base::PathExists(profile_2_shortcut_path)); 431 ASSERT_TRUE(base::PathExists(profile_2_shortcut_path));
431 432
432 // Delete the profile that has a shortcut. 433 // Delete the profile that has a shortcut.
433 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); 434 profile_attributes_storage_->RemoveProfile(profile_2_path_);
434 RunPendingTasks(); 435 RunPendingTasks();
435 436
436 // Verify that the remaining shortcut does not have a profile name. 437 // Verify that the remaining shortcut does not have a profile name.
437 ValidateNonProfileShortcut(FROM_HERE); 438 ValidateNonProfileShortcut(FROM_HERE);
438 // Verify that shortcuts with profile names do not exist. 439 // Verify that shortcuts with profile names do not exist.
439 EXPECT_FALSE(base::PathExists(profile_1_shortcut_path)); 440 EXPECT_FALSE(base::PathExists(profile_1_shortcut_path));
440 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path)); 441 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path));
441 } 442 }
442 443
443 TEST_F(ProfileShortcutManagerTest, DeleteOnlyProfileWithShortcuts) { 444 TEST_F(ProfileShortcutManagerTest, DeleteOnlyProfileWithShortcuts) {
(...skipping 14 matching lines...) Expand all
458 ASSERT_TRUE(base::DeleteFile(profile_2_shortcut_path, false)); 459 ASSERT_TRUE(base::DeleteFile(profile_2_shortcut_path, false));
459 460
460 // Only the shortcut to the third profile should exist. 461 // Only the shortcut to the third profile should exist.
461 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path)); 462 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path));
462 ASSERT_FALSE(base::PathExists(profile_2_shortcut_path)); 463 ASSERT_FALSE(base::PathExists(profile_2_shortcut_path));
463 ASSERT_FALSE(base::PathExists(non_profile_shortcut_path)); 464 ASSERT_FALSE(base::PathExists(non_profile_shortcut_path));
464 ASSERT_TRUE(base::PathExists(profile_3_shortcut_path)); 465 ASSERT_TRUE(base::PathExists(profile_3_shortcut_path));
465 466
466 // Delete the third profile and check that its shortcut is gone and no 467 // Delete the third profile and check that its shortcut is gone and no
467 // shortcuts have been re-created. 468 // shortcuts have been re-created.
468 profile_info_cache_->DeleteProfileFromCache(profile_3_path_); 469 profile_attributes_storage_->RemoveProfile(profile_3_path_);
469 RunPendingTasks(); 470 RunPendingTasks();
470 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path)); 471 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path));
471 ASSERT_FALSE(base::PathExists(profile_2_shortcut_path)); 472 ASSERT_FALSE(base::PathExists(profile_2_shortcut_path));
472 ASSERT_FALSE(base::PathExists(profile_3_shortcut_path)); 473 ASSERT_FALSE(base::PathExists(profile_3_shortcut_path));
473 ASSERT_FALSE(base::PathExists(non_profile_shortcut_path)); 474 ASSERT_FALSE(base::PathExists(non_profile_shortcut_path));
474 } 475 }
475 476
476 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreateSecond) { 477 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreateSecond) {
477 SetupAndCreateTwoShortcuts(FROM_HERE); 478 SetupAndCreateTwoShortcuts(FROM_HERE);
478 479
479 // Delete one shortcut. 480 // Delete one shortcut.
480 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); 481 profile_attributes_storage_->RemoveProfile(profile_2_path_);
481 RunPendingTasks(); 482 RunPendingTasks();
482 483
483 // Verify that a default shortcut exists (no profile name/avatar). 484 // Verify that a default shortcut exists (no profile name/avatar).
484 ValidateNonProfileShortcut(FROM_HERE); 485 ValidateNonProfileShortcut(FROM_HERE);
485 // Verify that an additional shortcut, with the first profile's name does 486 // Verify that an additional shortcut, with the first profile's name does
486 // not exist. 487 // not exist.
487 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)); 488 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_));
488 489
489 // Create a second profile and shortcut. 490 // Create a second profile and shortcut.
490 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); 491 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 538
538 // Also, copy the shortcut for the first user and ensure it gets preserved. 539 // Also, copy the shortcut for the first user and ensure it gets preserved.
539 const base::FilePath preserved_profile_1_shortcut_path = 540 const base::FilePath preserved_profile_1_shortcut_path =
540 GetUserShortcutsDirectory().Append(L"Preserved.lnk"); 541 GetUserShortcutsDirectory().Append(L"Preserved.lnk");
541 ASSERT_TRUE(base::CopyFile( 542 ASSERT_TRUE(base::CopyFile(
542 GetDefaultShortcutPathForProfile(profile_1_name_), 543 GetDefaultShortcutPathForProfile(profile_1_name_),
543 preserved_profile_1_shortcut_path)); 544 preserved_profile_1_shortcut_path));
544 EXPECT_TRUE(base::PathExists(preserved_profile_1_shortcut_path)); 545 EXPECT_TRUE(base::PathExists(preserved_profile_1_shortcut_path));
545 546
546 // Delete the profile and ensure both shortcuts were also deleted. 547 // Delete the profile and ensure both shortcuts were also deleted.
547 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); 548 profile_attributes_storage_->RemoveProfile(profile_2_path_);
548 RunPendingTasks(); 549 RunPendingTasks();
549 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path_1)); 550 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path_1));
550 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path_2)); 551 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path_2));
551 ValidateNonProfileShortcutAtPath(FROM_HERE, 552 ValidateNonProfileShortcutAtPath(FROM_HERE,
552 preserved_profile_1_shortcut_path); 553 preserved_profile_1_shortcut_path);
553 } 554 }
554 555
555 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsAfterProfileRename) { 556 TEST_F(ProfileShortcutManagerTest, RenamedDesktopShortcutsAfterProfileRename) {
556 SetupAndCreateTwoShortcuts(FROM_HERE); 557 SetupAndCreateTwoShortcuts(FROM_HERE);
557 558
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 profile_shortcut_manager_->HasProfileShortcuts(profile_2_path_, callback); 682 profile_shortcut_manager_->HasProfileShortcuts(profile_2_path_, callback);
682 RunPendingTasks(); 683 RunPendingTasks();
683 EXPECT_FALSE(result.has_shortcuts); 684 EXPECT_FALSE(result.has_shortcuts);
684 } 685 }
685 686
686 TEST_F(ProfileShortcutManagerTest, ProfileShortcutsWithSystemLevelShortcut) { 687 TEST_F(ProfileShortcutManagerTest, ProfileShortcutsWithSystemLevelShortcut) {
687 const base::FilePath system_level_shortcut_path = 688 const base::FilePath system_level_shortcut_path =
688 CreateRegularSystemLevelShortcut(FROM_HERE); 689 CreateRegularSystemLevelShortcut(FROM_HERE);
689 690
690 // Create the initial profile. 691 // Create the initial profile.
691 profile_info_cache_->AddProfileToCache(profile_1_path_, profile_1_name_, 692 profile_attributes_storage_->AddProfile(profile_1_path_, profile_1_name_,
692 std::string(), base::string16(), 0, 693 std::string(), base::string16(), 0,
693 std::string()); 694 std::string());
694 RunPendingTasks(); 695 RunPendingTasks();
695 ASSERT_EQ(1U, profile_info_cache_->GetNumberOfProfiles()); 696 ASSERT_EQ(1U, profile_attributes_storage_->GetNumberOfProfiles());
696 697
697 // Ensure system-level continues to exist and user-level was not created. 698 // Ensure system-level continues to exist and user-level was not created.
698 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)); 699 EXPECT_TRUE(base::PathExists(system_level_shortcut_path));
699 EXPECT_FALSE(base::PathExists( 700 EXPECT_FALSE(base::PathExists(
700 GetDefaultShortcutPathForProfile(base::string16()))); 701 GetDefaultShortcutPathForProfile(base::string16())));
701 702
702 // Create another profile with a shortcut and ensure both profiles receive 703 // Create another profile with a shortcut and ensure both profiles receive
703 // user-level profile shortcuts and the system-level one still exists. 704 // user-level profile shortcuts and the system-level one still exists.
704 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_); 705 CreateProfileWithShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
705 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_); 706 ValidateProfileShortcut(FROM_HERE, profile_1_name_, profile_1_path_);
706 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_); 707 ValidateProfileShortcut(FROM_HERE, profile_2_name_, profile_2_path_);
707 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)); 708 EXPECT_TRUE(base::PathExists(system_level_shortcut_path));
708 709
709 // Create a third profile without a shortcut and ensure it doesn't get one. 710 // Create a third profile without a shortcut and ensure it doesn't get one.
710 profile_info_cache_->AddProfileToCache(profile_3_path_, profile_3_name_, 711 profile_attributes_storage_->AddProfile(profile_3_path_, profile_3_name_,
711 std::string(), base::string16(), 0, 712 std::string(), base::string16(), 0,
712 std::string()); 713 std::string());
713 RunPendingTasks(); 714 RunPendingTasks();
714 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_)); 715 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_));
715 716
717 ProfileAttributesEntry* profile_3_entry;
718 ASSERT_TRUE(profile_attributes_storage_->GetProfileAttributesWithPath(
719 profile_3_path_, &profile_3_entry));
716 // Ensure that changing the avatar icon and the name does not result in a 720 // Ensure that changing the avatar icon and the name does not result in a
717 // shortcut being created. 721 // shortcut being created.
718 profile_info_cache_->SetAvatarIconOfProfileAtIndex( 722 profile_3_entry->SetAvatarIconIndex(3);
719 profile_info_cache_->GetIndexOfProfileWithPath(profile_3_path_), 3);
720 RunPendingTasks(); 723 RunPendingTasks();
721 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_)); 724 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_));
722 725
723 const base::string16 new_profile_3_name = L"New Name 3"; 726 const base::string16 new_profile_3_name = L"New Name 3";
724 profile_info_cache_->SetNameOfProfileAtIndex( 727 profile_3_entry->SetName(new_profile_3_name);
725 profile_info_cache_->GetIndexOfProfileWithPath(profile_3_path_),
726 new_profile_3_name);
727 RunPendingTasks(); 728 RunPendingTasks();
728 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_)); 729 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_3_name_));
729 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(new_profile_3_name)); 730 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(new_profile_3_name));
730 731
732 ProfileAttributesEntry* profile_2_entry;
733 ASSERT_TRUE(profile_attributes_storage_->GetProfileAttributesWithPath(
734 profile_2_path_, &profile_2_entry));
731 // Rename the second profile and ensure its shortcut got renamed. 735 // Rename the second profile and ensure its shortcut got renamed.
732 const base::string16 new_profile_2_name = L"New Name 2"; 736 const base::string16 new_profile_2_name = L"New Name 2";
733 profile_info_cache_->SetNameOfProfileAtIndex( 737 profile_2_entry->SetName(new_profile_2_name);
734 profile_info_cache_->GetIndexOfProfileWithPath(profile_2_path_),
735 new_profile_2_name);
736 RunPendingTasks(); 738 RunPendingTasks();
737 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); 739 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_));
738 ValidateProfileShortcut(FROM_HERE, new_profile_2_name, profile_2_path_); 740 ValidateProfileShortcut(FROM_HERE, new_profile_2_name, profile_2_path_);
739 } 741 }
740 742
741 TEST_F(ProfileShortcutManagerTest, 743 TEST_F(ProfileShortcutManagerTest,
742 DeleteSecondToLastProfileWithSystemLevelShortcut) { 744 DeleteSecondToLastProfileWithSystemLevelShortcut) {
743 SetupAndCreateTwoShortcuts(FROM_HERE); 745 SetupAndCreateTwoShortcuts(FROM_HERE);
744 746
745 const base::FilePath system_level_shortcut_path = 747 const base::FilePath system_level_shortcut_path =
746 CreateRegularSystemLevelShortcut(FROM_HERE); 748 CreateRegularSystemLevelShortcut(FROM_HERE);
747 749
748 // Delete a profile and verify that only the system-level shortcut still 750 // Delete a profile and verify that only the system-level shortcut still
749 // exists. 751 // exists.
750 profile_info_cache_->DeleteProfileFromCache(profile_1_path_); 752 profile_attributes_storage_->RemoveProfile(profile_1_path_);
751 RunPendingTasks(); 753 RunPendingTasks();
752 754
753 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)); 755 EXPECT_TRUE(base::PathExists(system_level_shortcut_path));
754 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(base::string16())); 756 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(base::string16()));
755 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_)); 757 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_1_name_));
756 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_)); 758 EXPECT_FALSE(ProfileShortcutExistsAtDefaultPath(profile_2_name_));
757 } 759 }
758 760
759 TEST_F(ProfileShortcutManagerTest, 761 TEST_F(ProfileShortcutManagerTest,
760 DeleteSecondToLastProfileWithShortcutWhenSystemLevelShortcutExists) { 762 DeleteSecondToLastProfileWithShortcutWhenSystemLevelShortcutExists) {
761 SetupAndCreateTwoShortcuts(FROM_HERE); 763 SetupAndCreateTwoShortcuts(FROM_HERE);
762 764
763 const base::FilePath profile_1_shortcut_path = 765 const base::FilePath profile_1_shortcut_path =
764 GetDefaultShortcutPathForProfile(profile_1_name_); 766 GetDefaultShortcutPathForProfile(profile_1_name_);
765 const base::FilePath profile_2_shortcut_path = 767 const base::FilePath profile_2_shortcut_path =
766 GetDefaultShortcutPathForProfile(profile_2_name_); 768 GetDefaultShortcutPathForProfile(profile_2_name_);
767 769
768 // Delete the shortcut for the first profile, but keep the one for the 2nd. 770 // Delete the shortcut for the first profile, but keep the one for the 2nd.
769 ASSERT_TRUE(base::DeleteFile(profile_1_shortcut_path, false)); 771 ASSERT_TRUE(base::DeleteFile(profile_1_shortcut_path, false));
770 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path)); 772 ASSERT_FALSE(base::PathExists(profile_1_shortcut_path));
771 ASSERT_TRUE(base::PathExists(profile_2_shortcut_path)); 773 ASSERT_TRUE(base::PathExists(profile_2_shortcut_path));
772 774
773 const base::FilePath system_level_shortcut_path = 775 const base::FilePath system_level_shortcut_path =
774 CreateRegularSystemLevelShortcut(FROM_HERE); 776 CreateRegularSystemLevelShortcut(FROM_HERE);
775 777
776 // Delete the profile that has a shortcut, which will exercise the non-profile 778 // Delete the profile that has a shortcut, which will exercise the non-profile
777 // shortcut creation path in |DeleteDesktopShortcuts()|, which is 779 // shortcut creation path in |DeleteDesktopShortcuts()|, which is
778 // not covered by the |DeleteSecondToLastProfileWithSystemLevelShortcut| test. 780 // not covered by the |DeleteSecondToLastProfileWithSystemLevelShortcut| test.
779 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); 781 profile_attributes_storage_->RemoveProfile(profile_2_path_);
780 RunPendingTasks(); 782 RunPendingTasks();
781 783
782 // Verify that only the system-level shortcut still exists. 784 // Verify that only the system-level shortcut still exists.
783 EXPECT_TRUE(base::PathExists(system_level_shortcut_path)); 785 EXPECT_TRUE(base::PathExists(system_level_shortcut_path));
784 EXPECT_FALSE(base::PathExists( 786 EXPECT_FALSE(base::PathExists(
785 GetDefaultShortcutPathForProfile(base::string16()))); 787 GetDefaultShortcutPathForProfile(base::string16())));
786 EXPECT_FALSE(base::PathExists(profile_1_shortcut_path)); 788 EXPECT_FALSE(base::PathExists(profile_1_shortcut_path));
787 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path)); 789 EXPECT_FALSE(base::PathExists(profile_2_shortcut_path));
788 } 790 }
789 791
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 std::string badged_icon_1; 823 std::string badged_icon_1;
822 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &badged_icon_1)); 824 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &badged_icon_1));
823 std::string badged_icon_2; 825 std::string badged_icon_2;
824 EXPECT_TRUE(base::ReadFileToString(icon_path_2, &badged_icon_2)); 826 EXPECT_TRUE(base::ReadFileToString(icon_path_2, &badged_icon_2));
825 827
826 EXPECT_NE(badged_icon_1, unbadged_icon_1); 828 EXPECT_NE(badged_icon_1, unbadged_icon_1);
827 EXPECT_EQ(badged_icon_1, badged_icon_2); 829 EXPECT_EQ(badged_icon_1, badged_icon_2);
828 830
829 // Deleting the default profile will unbadge the new profile's icon and should 831 // Deleting the default profile will unbadge the new profile's icon and should
830 // result in an icon that is identical to the unbadged default profile icon. 832 // result in an icon that is identical to the unbadged default profile icon.
831 profile_info_cache_->DeleteProfileFromCache(profile_1_path_); 833 profile_attributes_storage_->RemoveProfile(profile_1_path_);
832 RunPendingTasks(); 834 RunPendingTasks();
833 835
834 std::string unbadged_icon_2; 836 std::string unbadged_icon_2;
835 EXPECT_TRUE(base::ReadFileToString(icon_path_2, &unbadged_icon_2)); 837 EXPECT_TRUE(base::ReadFileToString(icon_path_2, &unbadged_icon_2));
836 EXPECT_EQ(unbadged_icon_1, unbadged_icon_2); 838 EXPECT_EQ(unbadged_icon_1, unbadged_icon_2);
837 } 839 }
838 840
839 TEST_F(ProfileShortcutManagerTest, ProfileIconOnAvatarChange) { 841 TEST_F(ProfileShortcutManagerTest, ProfileIconOnAvatarChange) {
840 SetupAndCreateTwoShortcuts(FROM_HERE); 842 SetupAndCreateTwoShortcuts(FROM_HERE);
841 const base::FilePath icon_path_1 = 843 const base::FilePath icon_path_1 =
842 profiles::internal::GetProfileIconPath(profile_1_path_); 844 profiles::internal::GetProfileIconPath(profile_1_path_);
843 const base::FilePath icon_path_2 = 845 const base::FilePath icon_path_2 =
844 profiles::internal::GetProfileIconPath(profile_2_path_); 846 profiles::internal::GetProfileIconPath(profile_2_path_);
845 const size_t profile_index_1 =
846 profile_info_cache_->GetIndexOfProfileWithPath(profile_1_path_);
847 847
848 std::string badged_icon_1; 848 std::string badged_icon_1;
849 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &badged_icon_1)); 849 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &badged_icon_1));
850 std::string badged_icon_2; 850 std::string badged_icon_2;
851 EXPECT_TRUE(base::ReadFileToString(icon_path_2, &badged_icon_2)); 851 EXPECT_TRUE(base::ReadFileToString(icon_path_2, &badged_icon_2));
852 852
853 // Profile 1 and 2 are created with the same icon. 853 // Profile 1 and 2 are created with the same icon.
854 EXPECT_EQ(badged_icon_1, badged_icon_2); 854 EXPECT_EQ(badged_icon_1, badged_icon_2);
855 855
856 ProfileAttributesEntry* entry;
857 ASSERT_TRUE(profile_attributes_storage_->GetProfileAttributesWithPath(
858 profile_1_path_, &entry));
856 // Change profile 1's icon. 859 // Change profile 1's icon.
857 profile_info_cache_->SetAvatarIconOfProfileAtIndex(profile_index_1, 1); 860 entry->SetAvatarIconIndex(1);
858 RunPendingTasks(); 861 RunPendingTasks();
859 862
860 std::string new_badged_icon_1; 863 std::string new_badged_icon_1;
861 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &new_badged_icon_1)); 864 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &new_badged_icon_1));
862 EXPECT_NE(new_badged_icon_1, badged_icon_1); 865 EXPECT_NE(new_badged_icon_1, badged_icon_1);
863 866
864 // Ensure the new icon is not the unbadged icon. 867 // Ensure the new icon is not the unbadged icon.
865 profile_info_cache_->DeleteProfileFromCache(profile_2_path_); 868 profile_attributes_storage_->RemoveProfile(profile_2_path_);
866 RunPendingTasks(); 869 RunPendingTasks();
867 870
868 std::string unbadged_icon_1; 871 std::string unbadged_icon_1;
869 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &unbadged_icon_1)); 872 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &unbadged_icon_1));
870 EXPECT_NE(unbadged_icon_1, new_badged_icon_1); 873 EXPECT_NE(unbadged_icon_1, new_badged_icon_1);
871 874
872 // Ensure the icon doesn't change on avatar change without 2 profiles. 875 // Ensure the icon doesn't change on avatar change without 2 profiles.
873 profile_info_cache_->SetAvatarIconOfProfileAtIndex(profile_index_1, 1); 876 entry->SetAvatarIconIndex(1);
874 RunPendingTasks(); 877 RunPendingTasks();
875 878
876 std::string unbadged_icon_1_a; 879 std::string unbadged_icon_1_a;
877 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &unbadged_icon_1_a)); 880 EXPECT_TRUE(base::ReadFileToString(icon_path_1, &unbadged_icon_1_a));
878 EXPECT_EQ(unbadged_icon_1, unbadged_icon_1_a); 881 EXPECT_EQ(unbadged_icon_1, unbadged_icon_1_a);
879 } 882 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698