OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/prefs/testing_pref_service.h" | 9 #include "base/prefs/testing_pref_service.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 before -= base::TimeDelta::FromSeconds(1); | 322 before -= base::TimeDelta::FromSeconds(1); |
323 GetCache()->SetProfileActiveTimeAtIndex(0); | 323 GetCache()->SetProfileActiveTimeAtIndex(0); |
324 base::Time after = base::Time::Now(); | 324 base::Time after = base::Time::Now(); |
325 after += base::TimeDelta::FromSeconds(1); | 325 after += base::TimeDelta::FromSeconds(1); |
326 EXPECT_LE(before, GetCache()->GetProfileActiveTimeAtIndex(0)); | 326 EXPECT_LE(before, GetCache()->GetProfileActiveTimeAtIndex(0)); |
327 EXPECT_GE(after, GetCache()->GetProfileActiveTimeAtIndex(0)); | 327 EXPECT_GE(after, GetCache()->GetProfileActiveTimeAtIndex(0)); |
328 } | 328 } |
329 | 329 |
330 TEST_F(ProfileInfoCacheTest, GAIAName) { | 330 TEST_F(ProfileInfoCacheTest, GAIAName) { |
331 GetCache()->AddProfileToCache( | 331 GetCache()->AddProfileToCache( |
332 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), | 332 GetProfilePath("path_1"), ASCIIToUTF16("Person 1"), |
333 base::string16(), 0, std::string()); | 333 base::string16(), 0, std::string()); |
334 base::string16 profile_name(ASCIIToUTF16("profile name 2")); | 334 base::string16 profile_name(ASCIIToUTF16("Person 2")); |
335 GetCache()->AddProfileToCache( | 335 GetCache()->AddProfileToCache( |
336 GetProfilePath("path_2"), profile_name, base::string16(), 0, | 336 GetProfilePath("path_2"), profile_name, base::string16(), 0, |
337 std::string()); | 337 std::string()); |
338 | 338 |
| 339 int index1 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_1")); |
| 340 int index2 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_2")); |
| 341 |
339 // Sanity check. | 342 // Sanity check. |
340 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); | 343 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index1).empty()); |
341 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(1).empty()); | 344 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index2).empty()); |
342 EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(0)); | 345 EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(index1)); |
343 EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(1)); | 346 EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(index2)); |
344 | 347 |
345 // Set GAIA name. | 348 // Set GAIA name. |
346 base::string16 gaia_name(ASCIIToUTF16("Pat Smith")); | 349 base::string16 gaia_name(ASCIIToUTF16("Pat Smith")); |
347 GetCache()->SetGAIANameOfProfileAtIndex(1, gaia_name); | 350 GetCache()->SetGAIANameOfProfileAtIndex(index2, gaia_name); |
348 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); | 351 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(index1).empty()); |
349 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); | 352 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(index2)); |
350 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(1)); | 353 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(index2)); |
351 | 354 |
352 // Use GAIA name as profile name. | 355 // Use GAIA name as profile name. This re-sorts the cache. |
353 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(1, true); | 356 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(index2, true); |
| 357 index1 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_1")); |
| 358 index2 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_2")); |
354 | 359 |
355 EXPECT_EQ(gaia_name, GetCache()->GetNameOfProfileAtIndex(1)); | 360 EXPECT_EQ(GetCache()->IsUsingGAIANameOfProfileAtIndex(index2), true); |
356 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); | 361 EXPECT_EQ(gaia_name, GetCache()->GetNameOfProfileAtIndex(index2)); |
| 362 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(index2)); |
357 | 363 |
358 // Don't use GAIA name as profile name. | 364 // Don't use GAIA name as profile name. This re-sorts the cache. |
359 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(1, false); | 365 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(index2, false); |
360 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(1)); | 366 index1 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_1")); |
361 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); | 367 index2 = GetCache()->GetIndexOfProfileWithPath(GetProfilePath("path_2")); |
| 368 |
| 369 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(index2)); |
| 370 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(index2)); |
362 } | 371 } |
363 | 372 |
364 TEST_F(ProfileInfoCacheTest, GAIAPicture) { | 373 TEST_F(ProfileInfoCacheTest, GAIAPicture) { |
365 GetCache()->AddProfileToCache( | 374 GetCache()->AddProfileToCache( |
366 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), | 375 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), |
367 base::string16(), 0, std::string()); | 376 base::string16(), 0, std::string()); |
368 GetCache()->AddProfileToCache( | 377 GetCache()->AddProfileToCache( |
369 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), | 378 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), |
370 base::string16(), 0, std::string()); | 379 base::string16(), 0, std::string()); |
371 | 380 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 | 530 |
522 ASSERT_EQ(4U, GetCache()->GetNumberOfProfiles()); | 531 ASSERT_EQ(4U, GetCache()->GetNumberOfProfiles()); |
523 | 532 |
524 // Check that the profiles can be extracted from the local state. | 533 // Check that the profiles can be extracted from the local state. |
525 std::vector<base::string16> names = ProfileInfoCache::GetProfileNames(); | 534 std::vector<base::string16> names = ProfileInfoCache::GetProfileNames(); |
526 for (size_t i = 0; i < 4; i++) | 535 for (size_t i = 0; i < 4; i++) |
527 ASSERT_FALSE(names[i].empty()); | 536 ASSERT_FALSE(names[i].empty()); |
528 } | 537 } |
529 | 538 |
530 } // namespace | 539 } // namespace |
OLD | NEW |