| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/profiles/profile_info_cache_unittest.h" | 5 #include "chrome/browser/profiles/profile_info_cache_unittest.h" |
| 6 | 6 |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/profiles/profile_info_cache.h" | 10 #include "chrome/browser/profiles/profile_info_cache.h" |
| 11 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
| 13 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
| 14 #include "chrome/test/base/testing_pref_service.h" | 14 #include "chrome/test/base/testing_pref_service.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 18 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
| 21 #include "ui/gfx/image/image_unittest_util.h" | 21 #include "ui/gfx/image/image_unittest_util.h" |
| 22 | 22 |
| 23 using content::BrowserThread; | 23 using content::BrowserThread; |
| 24 | 24 |
| 25 ProfileNameVerifierObserver::ProfileNameVerifierObserver() { | 25 ProfileNameVerifierObserver::ProfileNameVerifierObserver( |
| 26 TestingProfileManager* testing_profile_manager) |
| 27 : testing_profile_manager_(testing_profile_manager) { |
| 28 DCHECK(testing_profile_manager_); |
| 26 } | 29 } |
| 27 | 30 |
| 28 ProfileNameVerifierObserver::~ProfileNameVerifierObserver() { | 31 ProfileNameVerifierObserver::~ProfileNameVerifierObserver() { |
| 29 } | 32 } |
| 30 | 33 |
| 31 void ProfileNameVerifierObserver::OnProfileAdded( | 34 void ProfileNameVerifierObserver::OnProfileAdded( |
| 32 const string16& profile_name, | 35 const FilePath& profile_path) { |
| 33 const string16& profile_base_dir, | 36 string16 profile_name = GetCache()->GetNameOfProfileAtIndex( |
| 34 const FilePath& profile_path, | 37 GetCache()->GetIndexOfProfileWithPath(profile_path)); |
| 35 const gfx::Image* avatar_image) { | |
| 36 EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end()); | 38 EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end()); |
| 37 profile_names_.insert(profile_name); | 39 profile_names_.insert(profile_name); |
| 38 } | 40 } |
| 39 | 41 |
| 40 void ProfileNameVerifierObserver::OnProfileWillBeRemoved( | 42 void ProfileNameVerifierObserver::OnProfileWillBeRemoved( |
| 41 const string16& profile_name) { | 43 const FilePath& profile_path) { |
| 44 string16 profile_name = GetCache()->GetNameOfProfileAtIndex( |
| 45 GetCache()->GetIndexOfProfileWithPath(profile_path)); |
| 42 EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end()); | 46 EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end()); |
| 43 profile_names_.erase(profile_name); | 47 profile_names_.erase(profile_name); |
| 44 } | 48 } |
| 45 | 49 |
| 46 void ProfileNameVerifierObserver::OnProfileWasRemoved( | 50 void ProfileNameVerifierObserver::OnProfileWasRemoved( |
| 51 const FilePath& profile_path, |
| 47 const string16& profile_name) { | 52 const string16& profile_name) { |
| 48 EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end()); | 53 EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end()); |
| 49 } | 54 } |
| 50 | 55 |
| 51 void ProfileNameVerifierObserver::OnProfileNameChanged( | 56 void ProfileNameVerifierObserver::OnProfileNameChanged( |
| 52 const string16& old_profile_name, | 57 const FilePath& profile_path, |
| 53 const string16& new_profile_name) { | 58 const string16& old_profile_name) { |
| 59 string16 new_profile_name = GetCache()->GetNameOfProfileAtIndex( |
| 60 GetCache()->GetIndexOfProfileWithPath(profile_path)); |
| 54 EXPECT_TRUE(profile_names_.find(old_profile_name) != profile_names_.end()); | 61 EXPECT_TRUE(profile_names_.find(old_profile_name) != profile_names_.end()); |
| 55 EXPECT_TRUE(profile_names_.find(new_profile_name) == profile_names_.end()); | 62 EXPECT_TRUE(profile_names_.find(new_profile_name) == profile_names_.end()); |
| 56 profile_names_.erase(old_profile_name); | 63 profile_names_.erase(old_profile_name); |
| 57 profile_names_.insert(new_profile_name); | 64 profile_names_.insert(new_profile_name); |
| 58 } | 65 } |
| 59 | 66 |
| 60 void ProfileNameVerifierObserver::OnProfileAvatarChanged( | 67 void ProfileNameVerifierObserver::OnProfileAvatarChanged( |
| 61 const string16& profile_name, | 68 const FilePath& profile_path) { |
| 62 const string16& profile_base_dir, | 69 string16 profile_name = GetCache()->GetNameOfProfileAtIndex( |
| 63 const FilePath& profile_path, | 70 GetCache()->GetIndexOfProfileWithPath(profile_path)); |
| 64 const gfx::Image* avatar_image) { | |
| 65 EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end()); | 71 EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end()); |
| 66 } | 72 } |
| 67 | 73 |
| 74 ProfileInfoCache* ProfileNameVerifierObserver::GetCache() { |
| 75 return testing_profile_manager_->profile_info_cache(); |
| 76 } |
| 77 |
| 68 ProfileInfoCacheTest::ProfileInfoCacheTest() | 78 ProfileInfoCacheTest::ProfileInfoCacheTest() |
| 69 : testing_profile_manager_( | 79 : testing_profile_manager_( |
| 70 static_cast<TestingBrowserProcess*>(g_browser_process)), | 80 static_cast<TestingBrowserProcess*>(g_browser_process)), |
| 71 ui_thread_(BrowserThread::UI, &ui_loop_), | 81 ui_thread_(BrowserThread::UI, &ui_loop_), |
| 72 file_thread_(BrowserThread::FILE, &ui_loop_) { | 82 file_thread_(BrowserThread::FILE, &ui_loop_), |
| 83 name_observer_(&testing_profile_manager_) { |
| 73 } | 84 } |
| 74 | 85 |
| 75 ProfileInfoCacheTest::~ProfileInfoCacheTest() { | 86 ProfileInfoCacheTest::~ProfileInfoCacheTest() { |
| 76 } | 87 } |
| 77 | 88 |
| 78 void ProfileInfoCacheTest::SetUp() { | 89 void ProfileInfoCacheTest::SetUp() { |
| 79 ASSERT_TRUE(testing_profile_manager_.SetUp()); | 90 ASSERT_TRUE(testing_profile_manager_.SetUp()); |
| 80 testing_profile_manager_.profile_info_cache()->AddObserver(&name_observer_); | 91 testing_profile_manager_.profile_info_cache()->AddObserver(&name_observer_); |
| 81 } | 92 } |
| 82 | 93 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(0, true); | 402 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(0, true); |
| 392 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true); | 403 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true); |
| 393 | 404 |
| 394 // Verify that the profile name and picture are not empty. | 405 // Verify that the profile name and picture are not empty. |
| 395 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0)); | 406 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0)); |
| 396 EXPECT_TRUE(gfx::test::IsEqual( | 407 EXPECT_TRUE(gfx::test::IsEqual( |
| 397 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0))); | 408 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0))); |
| 398 } | 409 } |
| 399 | 410 |
| 400 } // namespace | 411 } // namespace |
| OLD | NEW |