Chromium Code Reviews| 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/file_util.h" | |
| 9 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| 10 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/prefs/pref_service_syncable.h" | 16 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 17 #include "chrome/browser/profiles/profile_avatar_downloader.h" | |
| 16 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 18 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 17 #include "chrome/browser/profiles/profile_info_cache.h" | 19 #include "chrome/browser/profiles/profile_info_cache.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| 19 #include "chrome/test/base/testing_browser_process.h" | 21 #include "chrome/test/base/testing_browser_process.h" |
| 20 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
| 21 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
| 22 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/test/test_browser_thread_bundle.h" | 25 #include "content/public/test/test_browser_thread_bundle.h" |
| 24 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
| 25 #include "third_party/skia/include/core/SkBitmap.h" | 27 #include "third_party/skia/include/core/SkBitmap.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 base::FilePath ProfileInfoCacheTest::GetProfilePath( | 112 base::FilePath ProfileInfoCacheTest::GetProfilePath( |
| 111 const std::string& base_name) { | 113 const std::string& base_name) { |
| 112 return testing_profile_manager_.profile_manager()->user_data_dir(). | 114 return testing_profile_manager_.profile_manager()->user_data_dir(). |
| 113 AppendASCII(base_name); | 115 AppendASCII(base_name); |
| 114 } | 116 } |
| 115 | 117 |
| 116 void ProfileInfoCacheTest::ResetCache() { | 118 void ProfileInfoCacheTest::ResetCache() { |
| 117 testing_profile_manager_.DeleteProfileInfoCache(); | 119 testing_profile_manager_.DeleteProfileInfoCache(); |
| 118 } | 120 } |
| 119 | 121 |
| 120 namespace { | |
| 121 | |
| 122 TEST_F(ProfileInfoCacheTest, AddProfiles) { | 122 TEST_F(ProfileInfoCacheTest, AddProfiles) { |
| 123 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); | 123 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
| 124 | 124 |
| 125 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 125 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 126 for (uint32 i = 0; i < 4; ++i) { | 126 for (uint32 i = 0; i < 4; ++i) { |
| 127 base::FilePath profile_path = | 127 base::FilePath profile_path = |
| 128 GetProfilePath(base::StringPrintf("path_%ud", i)); | 128 GetProfilePath(base::StringPrintf("path_%ud", i)); |
| 129 base::string16 profile_name = | 129 base::string16 profile_name = |
| 130 ASCIIToUTF16(base::StringPrintf("name_%ud", i)); | 130 ASCIIToUTF16(base::StringPrintf("name_%ud", i)); |
| 131 const SkBitmap* icon = rb.GetImageNamed( | 131 const SkBitmap* icon = rb.GetImageNamed( |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 } | 495 } |
| 496 | 496 |
| 497 ASSERT_EQ(4U, GetCache()->GetNumberOfProfiles()); | 497 ASSERT_EQ(4U, GetCache()->GetNumberOfProfiles()); |
| 498 | 498 |
| 499 // Check that the profiles can be extracted from the local state. | 499 // Check that the profiles can be extracted from the local state. |
| 500 std::vector<base::string16> names = ProfileInfoCache::GetProfileNames(); | 500 std::vector<base::string16> names = ProfileInfoCache::GetProfileNames(); |
| 501 for (size_t i = 0; i < 4; i++) | 501 for (size_t i = 0; i < 4; i++) |
| 502 ASSERT_FALSE(names[i].empty()); | 502 ASSERT_FALSE(names[i].empty()); |
| 503 } | 503 } |
| 504 | 504 |
| 505 } // namespace | 505 TEST_F(ProfileInfoCacheTest, DownloadHighResAvatarTest) { |
| 506 EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles()); | |
| 507 base::FilePath path_1 = GetProfilePath("path_1"); | |
| 508 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), | |
| 509 base::string16(), 0, std::string()); | |
| 510 EXPECT_EQ(1U, GetCache()->GetNumberOfProfiles()); | |
| 511 | |
| 512 // We haven't downloaded any high-res avatars yet. | |
| 513 EXPECT_EQ(0U, GetCache()->cached_avatar_images_.size()); | |
| 514 EXPECT_EQ(0U, GetCache()->avatar_images_downloads_in_progress_.size()); | |
| 515 EXPECT_FALSE(GetCache()->GetHighResAvatarOfProfileAtIndex(0)); | |
| 516 | |
| 517 // Simulate downloading a high-res avatar. | |
| 518 const size_t kIconIndex = 0; | |
| 519 ProfileAvatarDownloader avatar_downloader(kIconIndex, GetCache()); | |
| 520 | |
| 521 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. | |
| 522 SkBitmap bitmap; | |
| 523 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); | |
| 524 bitmap.allocPixels(); | |
| 525 bitmap.eraseColor(SK_ColorGREEN); | |
| 526 | |
| 527 avatar_downloader.OnFetchComplete( | |
| 528 GURL("http://www.google.com/avatar.png"), &bitmap); | |
| 529 | |
| 530 std::string file_name = | |
| 531 profiles::GetDefaultAvatarIconFileNameAtIndex(kIconIndex); | |
| 532 | |
| 533 // The file should have been cached and saved. | |
| 534 EXPECT_EQ(0U, GetCache()->avatar_images_downloads_in_progress_.size()); | |
| 535 EXPECT_EQ(1U, GetCache()->cached_avatar_images_.size()); | |
| 536 EXPECT_TRUE(GetCache()->GetHighResAvatarOfProfileAtIndex(0)); | |
| 537 EXPECT_EQ(GetCache()->cached_avatar_images_[file_name], | |
| 538 GetCache()->GetHighResAvatarOfProfileAtIndex(0)); | |
| 539 | |
| 540 // Make sure everything has completed, and the file has been written to disk. | |
| 541 base::RunLoop().RunUntilIdle(); | |
| 542 | |
| 543 // Clean up. | |
| 544 base::FilePath icon_path = | |
| 545 profiles::GetPathOfHighResAvatarAtIndex(kIconIndex); | |
|
msw
2014/04/30 19:46:21
nit: do you want to test the return value here at
noms (inactive)
2014/04/30 20:02:19
Done. I've checked whether the filename matches.
O
| |
| 546 EXPECT_TRUE(base::PathExists(icon_path)); | |
| 547 EXPECT_TRUE(base::DeleteFile(icon_path, true)); | |
| 548 EXPECT_FALSE(base::PathExists(icon_path)); | |
| 549 } | |
| OLD | NEW |