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/browser_task_environment.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   ProfileNameVerifierObserver(const ProfileNameVerifierObserver&) = delete;
28   ProfileNameVerifierObserver& operator=(const ProfileNameVerifierObserver&) =
29       delete;
30   ~ProfileNameVerifierObserver() override;
31 
32   // ProfileInfoCacheObserver overrides:
33   void OnProfileAdded(const base::FilePath& profile_path) override;
34   void OnProfileWillBeRemoved(const base::FilePath& profile_path) override;
35   void OnProfileWasRemoved(const base::FilePath& profile_path,
36                            const base::string16& profile_name) override;
37   void OnProfileNameChanged(const base::FilePath& profile_path,
38                             const base::string16& old_profile_name) override;
39   void OnProfileAvatarChanged(const base::FilePath& profile_path) override;
40 
41  private:
42   ProfileInfoCache* GetCache();
43   std::map<base::FilePath, base::string16> profile_names_;
44   TestingProfileManager* testing_profile_manager_;
45 };
46 
47 class ProfileInfoCacheTest : public testing::Test {
48  protected:
49   ProfileInfoCacheTest();
50   ~ProfileInfoCacheTest() override;
51 
52   void SetUp() override;
53   void TearDown() override;
54 
55   ProfileInfoCache* GetCache();
56   base::FilePath GetProfilePath(const std::string& base_name);
57   void ResetCache();
58   void RemoveObserver();
59   base::string16 GetConcatenation(const base::string16& gaia_name,
60                                   const base::string16 profile_name);
61 
62  private:
63   // BrowserTaskEnvironment needs to be up through the destruction of the
64   // TestingProfileManager below.
65   content::BrowserTaskEnvironment task_environment_;
66 
67  protected:
68   TestingProfileManager testing_profile_manager_;
69 
70  private:
71   ProfileNameVerifierObserver name_observer_;
72 };
73 
74 #endif  // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_UNITTEST_H_
75