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() { |
| 26 } |
| 27 |
| 28 ProfileNameVerifierObserver::~ProfileNameVerifierObserver() { |
| 29 } |
| 30 |
| 31 void ProfileNameVerifierObserver::OnProfileAdded( |
| 32 const string16& profile_name, |
| 33 const string16& profile_base_dir, |
| 34 const FilePath& profile_path, |
| 35 const gfx::Image* avatar_image) { |
| 36 EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end()); |
| 37 profile_names_.insert(profile_name); |
| 38 } |
| 39 |
| 40 void ProfileNameVerifierObserver::OnProfileRemoved( |
| 41 const string16& profile_name) { |
| 42 EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end()); |
| 43 profile_names_.erase(profile_name); |
| 44 } |
| 45 |
| 46 void ProfileNameVerifierObserver::OnProfileNameChanged( |
| 47 const string16& old_profile_name, |
| 48 const string16& new_profile_name) { |
| 49 EXPECT_TRUE(profile_names_.find(old_profile_name) != profile_names_.end()); |
| 50 EXPECT_TRUE(profile_names_.find(new_profile_name) == profile_names_.end()); |
| 51 profile_names_.erase(old_profile_name); |
| 52 profile_names_.insert(new_profile_name); |
| 53 } |
| 54 |
| 55 void ProfileNameVerifierObserver::OnProfileAvatarChanged( |
| 56 const string16& profile_name, |
| 57 const string16& profile_base_dir, |
| 58 const FilePath& profile_path, |
| 59 const gfx::Image* avatar_image) { |
| 60 EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end()); |
| 61 } |
| 62 |
25 ProfileInfoCacheTest::ProfileInfoCacheTest() | 63 ProfileInfoCacheTest::ProfileInfoCacheTest() |
26 : testing_profile_manager_( | 64 : testing_profile_manager_( |
27 static_cast<TestingBrowserProcess*>(g_browser_process)), | 65 static_cast<TestingBrowserProcess*>(g_browser_process)), |
28 ui_thread_(BrowserThread::UI, &ui_loop_), | 66 ui_thread_(BrowserThread::UI, &ui_loop_), |
29 file_thread_(BrowserThread::FILE, &ui_loop_) { | 67 file_thread_(BrowserThread::FILE, &ui_loop_) { |
30 } | 68 } |
31 | 69 |
32 ProfileInfoCacheTest::~ProfileInfoCacheTest() { | 70 ProfileInfoCacheTest::~ProfileInfoCacheTest() { |
33 } | 71 } |
34 | 72 |
35 void ProfileInfoCacheTest::SetUp() { | 73 void ProfileInfoCacheTest::SetUp() { |
36 ASSERT_TRUE(testing_profile_manager_.SetUp()); | 74 ASSERT_TRUE(testing_profile_manager_.SetUp()); |
| 75 testing_profile_manager_.profile_info_cache()->AddObserver(&name_observer_); |
37 } | 76 } |
38 | 77 |
39 void ProfileInfoCacheTest::TearDown() { | 78 void ProfileInfoCacheTest::TearDown() { |
40 // Drain the UI thread to make sure all tasks are completed. This prevents | 79 // Drain the UI thread to make sure all tasks are completed. This prevents |
41 // memory leaks. | 80 // memory leaks. |
42 ui_loop_.RunAllPending(); | 81 ui_loop_.RunAllPending(); |
43 } | 82 } |
44 | 83 |
45 ProfileInfoCache* ProfileInfoCacheTest::GetCache() { | 84 ProfileInfoCache* ProfileInfoCacheTest::GetCache() { |
46 return testing_profile_manager_.profile_info_cache(); | 85 return testing_profile_manager_.profile_info_cache(); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(0, true); | 386 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(0, true); |
348 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true); | 387 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true); |
349 | 388 |
350 // Verify that the profile name and picture are not empty. | 389 // Verify that the profile name and picture are not empty. |
351 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0)); | 390 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0)); |
352 EXPECT_TRUE(gfx::test::IsEqual( | 391 EXPECT_TRUE(gfx::test::IsEqual( |
353 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0))); | 392 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0))); |
354 } | 393 } |
355 | 394 |
356 } // namespace | 395 } // namespace |
OLD | NEW |