Add correction for wrong avatar indexes stored in preferences.

Synchronizing  data between browsers with different versions
will lead to crash if number of default avatars have changed
between versions.

For excluding possibility of crash in such situation, we can
select another avatar with smaller index.

Review-Url: https://codereview.chromium.org/2653753005
Cr-Commit-Position: refs/heads/master@{#447238}
diff --git a/chrome/browser/profiles/profile_info_cache_unittest.cc b/chrome/browser/profiles/profile_info_cache_unittest.cc
index fb3e87b3..6cb72ec 100644
--- a/chrome/browser/profiles/profile_info_cache_unittest.cc
+++ b/chrome/browser/profiles/profile_info_cache_unittest.cc
@@ -221,10 +221,17 @@
   EXPECT_EQ(new_gaia_id, GetCache()->GetGAIAIdOfProfileAtIndex(1));
   EXPECT_NE(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(0));
 
-  size_t new_icon_index = 3;
+  const size_t new_icon_index = 3;
   GetCache()->SetAvatarIconOfProfileAtIndex(1, new_icon_index);
+  EXPECT_EQ(new_icon_index, GetCache()->GetAvatarIconIndexOfProfileAtIndex(1));
   // Not much to test.
   GetCache()->GetAvatarIconOfProfileAtIndex(1);
+
+  const size_t wrong_icon_index = profiles::GetDefaultAvatarIconCount() + 1;
+  const size_t generic_icon_index = 0;
+  GetCache()->SetAvatarIconOfProfileAtIndex(1, wrong_icon_index);
+  EXPECT_EQ(generic_icon_index,
+            GetCache()->GetAvatarIconIndexOfProfileAtIndex(1));
 }
 
 TEST_F(ProfileInfoCacheTest, Sort) {