Commit 590e189b authored by stevet@chromium.org's avatar stevet@chromium.org

Ensure that use of GAIA names are considered when handling desktop shortcut...

Ensure that use of GAIA names are considered when handling desktop shortcut changes. Beefed up ProfileInfoCacheTest with a verifier class to ensure this.

BUG=106261
TEST=On Windows, create a new user and sign him into sync with a GAIA account. Ensure that the desktop shortcut changes with the synced GAIA name. Ensure that changing the profile's name or avatar updates the shortcut. Ensure that deleting the profile deletes the shortcut.

Review URL: http://codereview.chromium.org/8894005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114282 0039d316-1c4b-4281-b951-d872f2087c98
parent 778ad81a
...@@ -131,8 +131,14 @@ void GAIAInfoUpdateService::OnDownloadComplete(ProfileDownloader* downloader, ...@@ -131,8 +131,14 @@ void GAIAInfoUpdateService::OnDownloadComplete(ProfileDownloader* downloader,
// preference guards against clobbering the user's custom settings. // preference guards against clobbering the user's custom settings.
if (!cache.GetHasMigratedToGAIAInfoOfProfileAtIndex(profile_index)) { if (!cache.GetHasMigratedToGAIAInfoOfProfileAtIndex(profile_index)) {
cache.SetHasMigratedToGAIAInfoOfProfileAtIndex(profile_index, true); cache.SetHasMigratedToGAIAInfoOfProfileAtIndex(profile_index, true);
cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true); // Order matters here for shortcut management, like in
// ProfileShortcutManagerWin::OnProfileAdded, as the picture update does not
// allow us to change the target, so we have to apply any renaming first. We
// also need to re-fetch the index, as SetIsUsingGAIANameOfProfileAtIndex
// may alter it.
cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, true); cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, true);
profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true);
} }
} }
......
...@@ -229,19 +229,16 @@ void ProfileInfoCache::RemoveObserver(ProfileInfoCacheObserver* obs) { ...@@ -229,19 +229,16 @@ void ProfileInfoCache::RemoveObserver(ProfileInfoCacheObserver* obs) {
} }
void ProfileInfoCache::DeleteProfileFromCache(const FilePath& profile_path) { void ProfileInfoCache::DeleteProfileFromCache(const FilePath& profile_path) {
DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); string16 name = GetNameOfProfileAtIndex(
DictionaryValue* cache = update.Get(); GetIndexOfProfileWithPath(profile_path));
std::string key = CacheKeyFromProfilePath(profile_path);
DictionaryValue* info = NULL;
cache->GetDictionary(key, &info);
string16 name;
info->GetString(kNameKey, &name);
FOR_EACH_OBSERVER(ProfileInfoCacheObserver, FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_, observer_list_,
OnProfileRemoved(name)); OnProfileRemoved(name));
DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache);
DictionaryValue* cache = update.Get();
std::string key = CacheKeyFromProfilePath(profile_path);
cache->Remove(key, NULL); cache->Remove(key, NULL);
sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key)); sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key));
...@@ -404,8 +401,7 @@ void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index, ...@@ -404,8 +401,7 @@ void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index,
return; return;
scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
string16 old_name; string16 old_name = GetNameOfProfileAtIndex(index);
info->GetString(kNameKey, &old_name);
info->SetString(kNameKey, name); info->SetString(kNameKey, name);
// This takes ownership of |info|. // This takes ownership of |info|.
SetInfoForProfileAtIndex(index, info.release()); SetInfoForProfileAtIndex(index, info.release());
...@@ -430,12 +426,11 @@ void ProfileInfoCache::SetUserNameOfProfileAtIndex(size_t index, ...@@ -430,12 +426,11 @@ void ProfileInfoCache::SetUserNameOfProfileAtIndex(size_t index,
void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index,
size_t icon_index) { size_t icon_index) {
scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
string16 name;
info->GetString(kNameKey, &name);
info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index)); info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index));
// This takes ownership of |info|. // This takes ownership of |info|.
SetInfoForProfileAtIndex(index, info.release()); SetInfoForProfileAtIndex(index, info.release());
string16 name = GetNameOfProfileAtIndex(index);
FilePath profile_path = GetPathOfProfileAtIndex(index); FilePath profile_path = GetPathOfProfileAtIndex(index);
std::string key = CacheKeyFromProfilePath(profile_path); std::string key = CacheKeyFromProfilePath(profile_path);
gfx::Image& avatar_img = gfx::Image& avatar_img =
...@@ -477,10 +472,19 @@ void ProfileInfoCache::SetIsUsingGAIANameOfProfileAtIndex(size_t index, ...@@ -477,10 +472,19 @@ void ProfileInfoCache::SetIsUsingGAIANameOfProfileAtIndex(size_t index,
return; return;
scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
string16 old_name;
info->GetString(kNameKey, &old_name);
info->SetBoolean(kUseGAIANameKey, value); info->SetBoolean(kUseGAIANameKey, value);
// This takes ownership of |info|. // This takes ownership of |info|.
SetInfoForProfileAtIndex(index, info.release()); SetInfoForProfileAtIndex(index, info.release());
string16 new_name = GetGAIANameOfProfileAtIndex(index);
UpdateSortForProfileIndex(index); UpdateSortForProfileIndex(index);
if (value) {
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
OnProfileNameChanged(old_name, new_name));
}
} }
void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index, void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index,
...@@ -534,8 +538,7 @@ void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index, ...@@ -534,8 +538,7 @@ void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index,
void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index,
bool value) { bool value) {
scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
string16 name; string16 name = GetNameOfProfileAtIndex(index);
info->GetString(kNameKey, &name);
info->SetBoolean(kUseGAIAPictureKey, value); info->SetBoolean(kUseGAIAPictureKey, value);
// This takes ownership of |info|. // This takes ownership of |info|.
SetInfoForProfileAtIndex(index, info.release()); SetInfoForProfileAtIndex(index, info.release());
......
...@@ -22,6 +22,44 @@ ...@@ -22,6 +22,44 @@
using content::BrowserThread; using content::BrowserThread;
ProfileNameVerifierObserver::ProfileNameVerifierObserver() {
}
ProfileNameVerifierObserver::~ProfileNameVerifierObserver() {
}
void ProfileNameVerifierObserver::OnProfileAdded(
const string16& profile_name,
const string16& profile_base_dir,
const FilePath& profile_path,
const gfx::Image* avatar_image) {
EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end());
profile_names_.insert(profile_name);
}
void ProfileNameVerifierObserver::OnProfileRemoved(
const string16& profile_name) {
EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end());
profile_names_.erase(profile_name);
}
void ProfileNameVerifierObserver::OnProfileNameChanged(
const string16& old_profile_name,
const string16& new_profile_name) {
EXPECT_TRUE(profile_names_.find(old_profile_name) != profile_names_.end());
EXPECT_TRUE(profile_names_.find(new_profile_name) == profile_names_.end());
profile_names_.erase(old_profile_name);
profile_names_.insert(new_profile_name);
}
void ProfileNameVerifierObserver::OnProfileAvatarChanged(
const string16& profile_name,
const string16& profile_base_dir,
const FilePath& profile_path,
const gfx::Image* avatar_image) {
EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end());
}
ProfileInfoCacheTest::ProfileInfoCacheTest() ProfileInfoCacheTest::ProfileInfoCacheTest()
: testing_profile_manager_( : testing_profile_manager_(
static_cast<TestingBrowserProcess*>(g_browser_process)), static_cast<TestingBrowserProcess*>(g_browser_process)),
...@@ -34,6 +72,7 @@ ProfileInfoCacheTest::~ProfileInfoCacheTest() { ...@@ -34,6 +72,7 @@ ProfileInfoCacheTest::~ProfileInfoCacheTest() {
void ProfileInfoCacheTest::SetUp() { void ProfileInfoCacheTest::SetUp() {
ASSERT_TRUE(testing_profile_manager_.SetUp()); ASSERT_TRUE(testing_profile_manager_.SetUp());
testing_profile_manager_.profile_info_cache()->AddObserver(&name_observer_);
} }
void ProfileInfoCacheTest::TearDown() { void ProfileInfoCacheTest::TearDown() {
......
...@@ -6,7 +6,10 @@ ...@@ -6,7 +6,10 @@
#define CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_UNITTEST_H_ #define CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_UNITTEST_H_
#pragma once #pragma once
#include <set>
#include "base/message_loop.h" #include "base/message_loop.h"
#include "chrome/browser/profiles/profile_info_cache_observer.h"
#include "chrome/test/base/testing_profile_manager.h" #include "chrome/test/base/testing_profile_manager.h"
#include "content/test/test_browser_thread.h" #include "content/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -14,6 +17,35 @@ ...@@ -14,6 +17,35 @@
class FilePath; class FilePath;
class ProfileInfoCache; class ProfileInfoCache;
// Class used to test that ProfileInfoCache does not try to access any
// unexpected profile names.
class ProfileNameVerifierObserver : public ProfileInfoCacheObserver {
public:
ProfileNameVerifierObserver();
virtual ~ProfileNameVerifierObserver();
// ProfileInfoCacheObserver overrides:
virtual void OnProfileAdded(
const string16& profile_name,
const string16& profile_base_dir,
const FilePath& profile_path,
const gfx::Image* avatar_image) OVERRIDE;
virtual void OnProfileRemoved(
const string16& profile_name) OVERRIDE;
virtual void OnProfileNameChanged(
const string16& old_profile_name,
const string16& new_profile_name) OVERRIDE;
virtual void OnProfileAvatarChanged(
const string16& profile_name,
const string16& profile_base_dir,
const FilePath& profile_path,
const gfx::Image* avatar_image) OVERRIDE;
private:
std::set<string16> profile_names_;
DISALLOW_COPY_AND_ASSIGN(ProfileNameVerifierObserver);
};
class ProfileInfoCacheTest : public testing::Test { class ProfileInfoCacheTest : public testing::Test {
protected: protected:
ProfileInfoCacheTest(); ProfileInfoCacheTest();
...@@ -33,6 +65,7 @@ class ProfileInfoCacheTest : public testing::Test { ...@@ -33,6 +65,7 @@ class ProfileInfoCacheTest : public testing::Test {
MessageLoopForUI ui_loop_; MessageLoopForUI ui_loop_;
content::TestBrowserThread ui_thread_; content::TestBrowserThread ui_thread_;
content::TestBrowserThread file_thread_; content::TestBrowserThread file_thread_;
ProfileNameVerifierObserver name_observer_;
}; };
#endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_UNITTEST_H_ #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_UNITTEST_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment