| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/prefs/testing_pref_service.h" | 11 #include "base/prefs/testing_pref_service.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | |
| 17 #include "chrome/browser/prefs/pref_service_syncable.h" | 16 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 18 #include "chrome/browser/profiles/profile_avatar_downloader.h" | 17 #include "chrome/browser/profiles/profile_avatar_downloader.h" |
| 19 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 18 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 20 #include "chrome/browser/profiles/profile_info_cache.h" | 19 #include "chrome/browser/profiles/profile_info_cache.h" |
| 21 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| 22 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/test/base/testing_browser_process.h" | 22 #include "chrome/test/base/testing_browser_process.h" |
| 24 #include "components/signin/core/common/profile_management_switches.h" | 23 #include "components/signin/core/common/profile_management_switches.h" |
| 25 #include "content/public/browser/notification_observer.h" | |
| 26 #include "content/public/browser/notification_registrar.h" | |
| 27 #include "content/public/browser/notification_service.h" | |
| 28 #include "content/public/test/test_browser_thread_bundle.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
| 29 #include "content/public/test/test_utils.h" | 25 #include "content/public/test/test_utils.h" |
| 30 #include "third_party/skia/include/core/SkBitmap.h" | 26 #include "third_party/skia/include/core/SkBitmap.h" |
| 31 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 32 #include "ui/gfx/image/image.h" | 28 #include "ui/gfx/image/image.h" |
| 33 #include "ui/gfx/image/image_unittest_util.h" | 29 #include "ui/gfx/image/image_unittest_util.h" |
| 34 | 30 |
| 35 using base::ASCIIToUTF16; | 31 using base::ASCIIToUTF16; |
| 36 using base::UTF8ToUTF16; | 32 using base::UTF8ToUTF16; |
| 37 using content::BrowserThread; | 33 using content::BrowserThread; |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 EXPECT_TRUE(gfx::test::IsEqual( | 409 EXPECT_TRUE(gfx::test::IsEqual( |
| 414 other_avatar_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); | 410 other_avatar_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 415 } | 411 } |
| 416 | 412 |
| 417 TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) { | 413 TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) { |
| 418 GetCache()->AddProfileToCache( | 414 GetCache()->AddProfileToCache( |
| 419 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), | 415 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), |
| 420 base::string16(), 0, std::string()); | 416 base::string16(), 0, std::string()); |
| 421 gfx::Image gaia_image(gfx::test::CreateImage()); | 417 gfx::Image gaia_image(gfx::test::CreateImage()); |
| 422 | 418 |
| 423 content::WindowedNotificationObserver save_observer( | |
| 424 chrome::NOTIFICATION_PROFILE_CACHE_PICTURE_SAVED, | |
| 425 content::NotificationService::AllSources()); | |
| 426 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_image); | 419 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_image); |
| 420 |
| 421 // Make sure everything has completed, and the file has been written to disk. |
| 422 base::RunLoop().RunUntilIdle(); |
| 423 |
| 427 EXPECT_TRUE(gfx::test::IsEqual( | 424 EXPECT_TRUE(gfx::test::IsEqual( |
| 428 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); | 425 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
| 429 | 426 |
| 430 // Wait for the file to be written to disk then reset the cache. | |
| 431 save_observer.Wait(); | |
| 432 ResetCache(); | 427 ResetCache(); |
| 433 | |
| 434 // Try to get the GAIA picture. This should return NULL until the read from | 428 // Try to get the GAIA picture. This should return NULL until the read from |
| 435 // disk is done. | 429 // disk is done. |
| 436 content::WindowedNotificationObserver read_observer( | |
| 437 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | |
| 438 content::NotificationService::AllSources()); | |
| 439 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); | 430 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
| 440 read_observer.Wait(); | 431 base::RunLoop().RunUntilIdle(); |
| 432 |
| 441 EXPECT_TRUE(gfx::test::IsEqual( | 433 EXPECT_TRUE(gfx::test::IsEqual( |
| 442 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); | 434 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
| 443 } | 435 } |
| 444 | 436 |
| 445 TEST_F(ProfileInfoCacheTest, SetSupervisedUserId) { | 437 TEST_F(ProfileInfoCacheTest, SetSupervisedUserId) { |
| 446 GetCache()->AddProfileToCache( | 438 GetCache()->AddProfileToCache( |
| 447 GetProfilePath("test"), ASCIIToUTF16("Test"), | 439 GetProfilePath("test"), ASCIIToUTF16("Test"), |
| 448 base::string16(), 0, std::string()); | 440 base::string16(), 0, std::string()); |
| 449 EXPECT_FALSE(GetCache()->ProfileIsSupervisedAtIndex(0)); | 441 EXPECT_FALSE(GetCache()->ProfileIsSupervisedAtIndex(0)); |
| 450 | 442 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 // Profile names should have been preserved. | 664 // Profile names should have been preserved. |
| 673 EXPECT_EQ(name_1, GetCache()->GetNameOfProfileAtIndex( | 665 EXPECT_EQ(name_1, GetCache()->GetNameOfProfileAtIndex( |
| 674 GetCache()->GetIndexOfProfileWithPath(path_1))); | 666 GetCache()->GetIndexOfProfileWithPath(path_1))); |
| 675 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex( | 667 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex( |
| 676 GetCache()->GetIndexOfProfileWithPath(path_2))); | 668 GetCache()->GetIndexOfProfileWithPath(path_2))); |
| 677 EXPECT_EQ(name_3, GetCache()->GetNameOfProfileAtIndex( | 669 EXPECT_EQ(name_3, GetCache()->GetNameOfProfileAtIndex( |
| 678 GetCache()->GetIndexOfProfileWithPath(path_3))); | 670 GetCache()->GetIndexOfProfileWithPath(path_3))); |
| 679 EXPECT_EQ(name_4, GetCache()->GetNameOfProfileAtIndex( | 671 EXPECT_EQ(name_4, GetCache()->GetNameOfProfileAtIndex( |
| 680 GetCache()->GetIndexOfProfileWithPath(path_4))); | 672 GetCache()->GetIndexOfProfileWithPath(path_4))); |
| 681 } | 673 } |
| OLD | NEW |