| 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 "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/profiles/profile_info_cache.h" | 10 #include "chrome/browser/profiles/profile_info_cache.h" |
| 11 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
| 13 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
| 14 #include "chrome/test/base/testing_pref_service.h" | 14 #include "chrome/test/base/testing_pref_service.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | |
| 16 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/test/test_utils.h" |
| 19 #include "third_party/skia/include/core/SkBitmap.h" | 19 #include "third_party/skia/include/core/SkBitmap.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
| 22 #include "ui/gfx/image/image_unittest_util.h" | 22 #include "ui/gfx/image/image_unittest_util.h" |
| 23 | 23 |
| 24 using content::BrowserThread; | 24 using content::BrowserThread; |
| 25 | 25 |
| 26 ProfileNameVerifierObserver::ProfileNameVerifierObserver( | 26 ProfileNameVerifierObserver::ProfileNameVerifierObserver( |
| 27 TestingProfileManager* testing_profile_manager) | 27 TestingProfileManager* testing_profile_manager) |
| 28 : testing_profile_manager_(testing_profile_manager) { | 28 : testing_profile_manager_(testing_profile_manager) { |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); | 362 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); |
| 363 EXPECT_TRUE(gfx::test::IsEqual( | 363 EXPECT_TRUE(gfx::test::IsEqual( |
| 364 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); | 364 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 365 } | 365 } |
| 366 | 366 |
| 367 TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) { | 367 TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) { |
| 368 GetCache()->AddProfileToCache( | 368 GetCache()->AddProfileToCache( |
| 369 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); | 369 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); |
| 370 gfx::Image gaia_image(gfx::test::CreateImage()); | 370 gfx::Image gaia_image(gfx::test::CreateImage()); |
| 371 | 371 |
| 372 ui_test_utils::WindowedNotificationObserver save_observer( | 372 content::WindowedNotificationObserver save_observer( |
| 373 chrome::NOTIFICATION_PROFILE_CACHE_PICTURE_SAVED, | 373 chrome::NOTIFICATION_PROFILE_CACHE_PICTURE_SAVED, |
| 374 content::NotificationService::AllSources()); | 374 content::NotificationService::AllSources()); |
| 375 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_image); | 375 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_image); |
| 376 EXPECT_TRUE(gfx::test::IsEqual( | 376 EXPECT_TRUE(gfx::test::IsEqual( |
| 377 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); | 377 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
| 378 | 378 |
| 379 // Wait for the file to be written to disk then reset the cache. | 379 // Wait for the file to be written to disk then reset the cache. |
| 380 save_observer.Wait(); | 380 save_observer.Wait(); |
| 381 ResetCache(); | 381 ResetCache(); |
| 382 | 382 |
| 383 // Try to get the GAIA picture. This should return NULL until the read from | 383 // Try to get the GAIA picture. This should return NULL until the read from |
| 384 // disk is done. | 384 // disk is done. |
| 385 ui_test_utils::WindowedNotificationObserver read_observer( | 385 content::WindowedNotificationObserver read_observer( |
| 386 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 386 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 387 content::NotificationService::AllSources()); | 387 content::NotificationService::AllSources()); |
| 388 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); | 388 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
| 389 read_observer.Wait(); | 389 read_observer.Wait(); |
| 390 EXPECT_TRUE(gfx::test::IsEqual( | 390 EXPECT_TRUE(gfx::test::IsEqual( |
| 391 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); | 391 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
| 392 } | 392 } |
| 393 | 393 |
| 394 TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) { | 394 TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) { |
| 395 string16 profile_name = ASCIIToUTF16("name_1"); | 395 string16 profile_name = ASCIIToUTF16("name_1"); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 406 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(0, true); | 406 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(0, true); |
| 407 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true); | 407 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true); |
| 408 | 408 |
| 409 // Verify that the profile name and picture are not empty. | 409 // Verify that the profile name and picture are not empty. |
| 410 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0)); | 410 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0)); |
| 411 EXPECT_TRUE(gfx::test::IsEqual( | 411 EXPECT_TRUE(gfx::test::IsEqual( |
| 412 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0))); | 412 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0))); |
| 413 } | 413 } |
| 414 | 414 |
| 415 } // namespace | 415 } // namespace |
| OLD | NEW |