| 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/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/test/base/testing_browser_process.h" | 23 #include "chrome/test/base/testing_browser_process.h" |
| 25 #include "components/signin/core/common/profile_management_switches.h" | 24 #include "components/signin/core/common/profile_management_switches.h" |
| 26 #include "content/public/browser/notification_observer.h" | |
| 27 #include "content/public/browser/notification_registrar.h" | |
| 28 #include "content/public/browser/notification_service.h" | |
| 29 #include "content/public/test/test_browser_thread_bundle.h" | 25 #include "content/public/test/test_browser_thread_bundle.h" |
| 30 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
| 31 #include "third_party/skia/include/core/SkBitmap.h" | 27 #include "third_party/skia/include/core/SkBitmap.h" |
| 32 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 33 #include "ui/gfx/image/image.h" | 29 #include "ui/gfx/image/image.h" |
| 34 #include "ui/gfx/image/image_unittest_util.h" | 30 #include "ui/gfx/image/image_unittest_util.h" |
| 35 | 31 |
| 36 using base::ASCIIToUTF16; | 32 using base::ASCIIToUTF16; |
| 37 using base::UTF8ToUTF16; | 33 using base::UTF8ToUTF16; |
| 38 using content::BrowserThread; | 34 using content::BrowserThread; |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 EXPECT_TRUE(gfx::test::IsEqual( | 410 EXPECT_TRUE(gfx::test::IsEqual( |
| 415 other_avatar_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); | 411 other_avatar_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 416 } | 412 } |
| 417 | 413 |
| 418 TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) { | 414 TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) { |
| 419 GetCache()->AddProfileToCache( | 415 GetCache()->AddProfileToCache( |
| 420 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), | 416 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), |
| 421 base::string16(), 0, std::string()); | 417 base::string16(), 0, std::string()); |
| 422 gfx::Image gaia_image(gfx::test::CreateImage()); | 418 gfx::Image gaia_image(gfx::test::CreateImage()); |
| 423 | 419 |
| 424 content::WindowedNotificationObserver save_observer( | |
| 425 chrome::NOTIFICATION_PROFILE_CACHE_PICTURE_SAVED, | |
| 426 content::NotificationService::AllSources()); | |
| 427 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_image); | 420 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_image); |
| 421 |
| 422 // Make sure everything has completed, and the file has been written to disk. |
| 423 base::RunLoop().RunUntilIdle(); |
| 424 |
| 428 EXPECT_TRUE(gfx::test::IsEqual( | 425 EXPECT_TRUE(gfx::test::IsEqual( |
| 429 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); | 426 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
| 430 | 427 |
| 431 // Wait for the file to be written to disk then reset the cache. | |
| 432 save_observer.Wait(); | |
| 433 ResetCache(); | 428 ResetCache(); |
| 434 | |
| 435 // Try to get the GAIA picture. This should return NULL until the read from | 429 // Try to get the GAIA picture. This should return NULL until the read from |
| 436 // disk is done. | 430 // disk is done. |
| 437 content::WindowedNotificationObserver read_observer( | |
| 438 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | |
| 439 content::NotificationService::AllSources()); | |
| 440 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); | 431 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
| 441 read_observer.Wait(); | 432 base::RunLoop().RunUntilIdle(); |
| 433 |
| 442 EXPECT_TRUE(gfx::test::IsEqual( | 434 EXPECT_TRUE(gfx::test::IsEqual( |
| 443 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); | 435 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
| 444 } | 436 } |
| 445 | 437 |
| 446 TEST_F(ProfileInfoCacheTest, SetSupervisedUserId) { | 438 TEST_F(ProfileInfoCacheTest, SetSupervisedUserId) { |
| 447 GetCache()->AddProfileToCache( | 439 GetCache()->AddProfileToCache( |
| 448 GetProfilePath("test"), ASCIIToUTF16("Test"), | 440 GetProfilePath("test"), ASCIIToUTF16("Test"), |
| 449 base::string16(), 0, std::string()); | 441 base::string16(), 0, std::string()); |
| 450 EXPECT_FALSE(GetCache()->ProfileIsSupervisedAtIndex(0)); | 442 EXPECT_FALSE(GetCache()->ProfileIsSupervisedAtIndex(0)); |
| 451 | 443 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 // Profile names should have been preserved. | 677 // Profile names should have been preserved. |
| 686 EXPECT_EQ(name_1, GetCache()->GetNameOfProfileAtIndex( | 678 EXPECT_EQ(name_1, GetCache()->GetNameOfProfileAtIndex( |
| 687 GetCache()->GetIndexOfProfileWithPath(path_1))); | 679 GetCache()->GetIndexOfProfileWithPath(path_1))); |
| 688 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex( | 680 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex( |
| 689 GetCache()->GetIndexOfProfileWithPath(path_2))); | 681 GetCache()->GetIndexOfProfileWithPath(path_2))); |
| 690 EXPECT_EQ(name_3, GetCache()->GetNameOfProfileAtIndex( | 682 EXPECT_EQ(name_3, GetCache()->GetNameOfProfileAtIndex( |
| 691 GetCache()->GetIndexOfProfileWithPath(path_3))); | 683 GetCache()->GetIndexOfProfileWithPath(path_3))); |
| 692 EXPECT_EQ(name_4, GetCache()->GetNameOfProfileAtIndex( | 684 EXPECT_EQ(name_4, GetCache()->GetNameOfProfileAtIndex( |
| 693 GetCache()->GetIndexOfProfileWithPath(path_4))); | 685 GetCache()->GetIndexOfProfileWithPath(path_4))); |
| 694 } | 686 } |
| OLD | NEW |