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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_UNITTEST_H_ 6 #define CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_UNITTEST_H_ 7 8 #include <set> 9 10 #include "chrome/browser/profiles/profile_info_cache_observer.h" 11 #include "chrome/test/base/testing_profile_manager.h" 12 #include "content/public/test/test_browser_thread_bundle.h" 13 #include "testing/gtest/include/gtest/gtest.h" 14 15 class ProfileInfoCache; 16 17 namespace base { 18 class FilePath; 19 } 20 21 // Class used to test that ProfileInfoCache does not try to access any 22 // unexpected profile names. 23 class ProfileNameVerifierObserver : public ProfileInfoCacheObserver { 24 public: 25 explicit ProfileNameVerifierObserver( 26 TestingProfileManager* testing_profile_manager); 27 virtual ~ProfileNameVerifierObserver(); 28 29 // ProfileInfoCacheObserver overrides: 30 virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE; 31 virtual void OnProfileWillBeRemoved( 32 const base::FilePath& profile_path) OVERRIDE; 33 virtual void OnProfileWasRemoved( 34 const base::FilePath& profile_path, 35 const base::string16& profile_name) OVERRIDE; 36 virtual void OnProfileNameChanged( 37 const base::FilePath& profile_path, 38 const base::string16& old_profile_name) OVERRIDE; 39 virtual void OnProfileAvatarChanged(const base::FilePath& profile_path) OVERRIDE; 40 41 private: 42 ProfileInfoCache* GetCache(); 43 std::set<base::string16> profile_names_; 44 TestingProfileManager* testing_profile_manager_; 45 DISALLOW_COPY_AND_ASSIGN(ProfileNameVerifierObserver); 46 }; 47 48 class ProfileInfoCacheTest : public testing::Test { 49 protected: 50 ProfileInfoCacheTest(); 51 virtual ~ProfileInfoCacheTest(); 52 53 virtual void SetUp() OVERRIDE; 54 virtual void TearDown() OVERRIDE; 55 56 ProfileInfoCache* GetCache(); 57 base::FilePath GetProfilePath(const std::string& base_name); 58 void ResetCache(); 59 60 protected: 61 TestingProfileManager testing_profile_manager_; 62 63 private: 64 content::TestBrowserThreadBundle thread_bundle_; 65 ProfileNameVerifierObserver name_observer_; 66 }; 67 68 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_UNITTEST_H_ 69