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

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

Issue 9020013: Refactor ProfileInfoCacheObserver interface and usage thereof. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: init Created 9 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) 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 "content/public/browser/notification_service.h" 18 #include "content/public/browser/notification_service.h"
19 #include "third_party/skia/include/core/SkBitmap.h" 19 #include "third_party/skia/include/core/SkBitmap.h"
20 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/image/image.h" 21 #include "ui/gfx/image/image.h"
22 #include "ui/gfx/image/image_unittest_util.h" 22 #include "ui/gfx/image/image_unittest_util.h"
23 23
24 using content::BrowserThread; 24 using content::BrowserThread;
25 25
26 ProfileNameVerifierObserver::ProfileNameVerifierObserver() { 26 ProfileNameVerifierObserver::ProfileNameVerifierObserver(
27 ProfileInfoCache* cache) : cache_(cache) {
28 DCHECK(cache_);
27 } 29 }
28 30
29 ProfileNameVerifierObserver::~ProfileNameVerifierObserver() { 31 ProfileNameVerifierObserver::~ProfileNameVerifierObserver() {
30 } 32 }
31 33
32 void ProfileNameVerifierObserver::OnProfileAdded( 34 void ProfileNameVerifierObserver::OnProfileAdded(
33 const string16& profile_name,
34 const string16& profile_base_dir,
35 const FilePath& profile_path, 35 const FilePath& profile_path,
36 const gfx::Image* avatar_image) { 36 const string16& profile_base_dir) {
37 size_t index = cache_->GetIndexOfProfileWithPath(profile_path);
38 string16 profile_name = cache_->GetNameOfProfileAtIndex(index);
37 EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end()); 39 EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end());
38 profile_names_.insert(profile_name); 40 profile_names_.insert(profile_name);
39 } 41 }
40 42
41 void ProfileNameVerifierObserver::OnProfileWillBeRemoved( 43 void ProfileNameVerifierObserver::OnProfileWillBeRemoved(
42 const string16& profile_name) { 44 const string16& profile_name) {
43 EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end()); 45 EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end());
44 profile_names_.erase(profile_name); 46 profile_names_.erase(profile_name);
45 } 47 }
46 48
47 void ProfileNameVerifierObserver::OnProfileWasRemoved( 49 void ProfileNameVerifierObserver::OnProfileWasRemoved(
48 const string16& profile_name) { 50 const string16& profile_name) {
49 EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end()); 51 EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end());
50 } 52 }
51 53
52 void ProfileNameVerifierObserver::OnProfileNameChanged( 54 void ProfileNameVerifierObserver::OnProfileNameChanged(
53 const string16& old_profile_name, 55 const string16& old_profile_name,
54 const string16& new_profile_name) { 56 const string16& new_profile_name) {
55 EXPECT_TRUE(profile_names_.find(old_profile_name) != profile_names_.end()); 57 EXPECT_TRUE(profile_names_.find(old_profile_name) != profile_names_.end());
56 EXPECT_TRUE(profile_names_.find(new_profile_name) == profile_names_.end()); 58 EXPECT_TRUE(profile_names_.find(new_profile_name) == profile_names_.end());
57 profile_names_.erase(old_profile_name); 59 profile_names_.erase(old_profile_name);
58 profile_names_.insert(new_profile_name); 60 profile_names_.insert(new_profile_name);
59 } 61 }
60 62
61 void ProfileNameVerifierObserver::OnProfileAvatarChanged( 63 void ProfileNameVerifierObserver::OnProfileAvatarChanged(
62 const string16& profile_name,
63 const string16& profile_base_dir,
64 const FilePath& profile_path, 64 const FilePath& profile_path,
65 const gfx::Image* avatar_image) { 65 const string16& profile_base_dir) {
66 size_t index = cache_->GetIndexOfProfileWithPath(profile_path);
67 string16 profile_name = cache_->GetNameOfProfileAtIndex(index);
66 EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end()); 68 EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end());
67 } 69 }
68 70
69 ProfileInfoCacheTest::ProfileInfoCacheTest() 71 ProfileInfoCacheTest::ProfileInfoCacheTest()
70 : testing_profile_manager_( 72 : testing_profile_manager_(
71 static_cast<TestingBrowserProcess*>(g_browser_process)), 73 static_cast<TestingBrowserProcess*>(g_browser_process)),
72 ui_thread_(BrowserThread::UI, &ui_loop_), 74 ui_thread_(BrowserThread::UI, &ui_loop_),
73 file_thread_(BrowserThread::FILE, &ui_loop_) { 75 file_thread_(BrowserThread::FILE, &ui_loop_),
76 name_observer_(GetCache()) {
74 } 77 }
75 78
76 ProfileInfoCacheTest::~ProfileInfoCacheTest() { 79 ProfileInfoCacheTest::~ProfileInfoCacheTest() {
77 } 80 }
78 81
79 void ProfileInfoCacheTest::SetUp() { 82 void ProfileInfoCacheTest::SetUp() {
80 ASSERT_TRUE(testing_profile_manager_.SetUp()); 83 ASSERT_TRUE(testing_profile_manager_.SetUp());
81 testing_profile_manager_.profile_info_cache()->AddObserver(&name_observer_); 84 testing_profile_manager_.profile_info_cache()->AddObserver(&name_observer_);
82 } 85 }
83 86
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(0, true); 395 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(0, true);
393 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true); 396 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true);
394 397
395 // Verify that the profile name and picture are not empty. 398 // Verify that the profile name and picture are not empty.
396 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0)); 399 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0));
397 EXPECT_TRUE(gfx::test::IsEqual( 400 EXPECT_TRUE(gfx::test::IsEqual(
398 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0))); 401 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0)));
399 } 402 }
400 403
401 } // namespace 404 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698