Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: chrome/browser/profiles/profile_info_cache_unittest.cc

Issue 380643002: Profile picture doesn't display correctly after new profile has been created (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated patch Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/profiles/profile_info_cache.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/file_util.h" 10 #include "base/file_util.h"
10 #include "base/prefs/testing_pref_service.h" 11 #include "base/prefs/testing_pref_service.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/prefs/pref_service_syncable.h" 17 #include "chrome/browser/prefs/pref_service_syncable.h"
17 #include "chrome/browser/profiles/profile_avatar_downloader.h" 18 #include "chrome/browser/profiles/profile_avatar_downloader.h"
18 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 19 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
19 #include "chrome/browser/profiles/profile_info_cache.h" 20 #include "chrome/browser/profiles/profile_info_cache.h"
20 #include "chrome/browser/profiles/profile_manager.h" 21 #include "chrome/browser/profiles/profile_manager.h"
22 #include "chrome/common/chrome_switches.h"
21 #include "chrome/test/base/testing_browser_process.h" 23 #include "chrome/test/base/testing_browser_process.h"
24 #include "components/signin/core/common/profile_management_switches.h"
22 #include "content/public/browser/notification_observer.h" 25 #include "content/public/browser/notification_observer.h"
23 #include "content/public/browser/notification_registrar.h" 26 #include "content/public/browser/notification_registrar.h"
24 #include "content/public/browser/notification_service.h" 27 #include "content/public/browser/notification_service.h"
25 #include "content/public/test/test_browser_thread_bundle.h" 28 #include "content/public/test/test_browser_thread_bundle.h"
26 #include "content/public/test/test_utils.h" 29 #include "content/public/test/test_utils.h"
27 #include "third_party/skia/include/core/SkBitmap.h" 30 #include "third_party/skia/include/core/SkBitmap.h"
28 #include "ui/base/resource/resource_bundle.h" 31 #include "ui/base/resource/resource_bundle.h"
29 #include "ui/gfx/image/image.h" 32 #include "ui/gfx/image/image.h"
30 #include "ui/gfx/image/image_unittest_util.h" 33 #include "ui/gfx/image/image_unittest_util.h"
31 34
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 501
499 ASSERT_EQ(4U, GetCache()->GetNumberOfProfiles()); 502 ASSERT_EQ(4U, GetCache()->GetNumberOfProfiles());
500 503
501 // Check that the profiles can be extracted from the local state. 504 // Check that the profiles can be extracted from the local state.
502 std::vector<base::string16> names = ProfileInfoCache::GetProfileNames(); 505 std::vector<base::string16> names = ProfileInfoCache::GetProfileNames();
503 for (size_t i = 0; i < 4; i++) 506 for (size_t i = 0; i < 4; i++)
504 ASSERT_FALSE(names[i].empty()); 507 ASSERT_FALSE(names[i].empty());
505 } 508 }
506 509
507 TEST_F(ProfileInfoCacheTest, DownloadHighResAvatarTest) { 510 TEST_F(ProfileInfoCacheTest, DownloadHighResAvatarTest) {
511 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kNewAvatarMenu);
512
508 EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles()); 513 EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles());
509 base::FilePath path_1 = GetProfilePath("path_1"); 514 base::FilePath path_1 = GetProfilePath("path_1");
510 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), 515 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"),
511 base::string16(), 0, std::string()); 516 base::string16(), 0, std::string());
512 EXPECT_EQ(1U, GetCache()->GetNumberOfProfiles()); 517 EXPECT_EQ(1U, GetCache()->GetNumberOfProfiles());
513 518
514 // We haven't downloaded any high-res avatars yet. 519 // We haven't downloaded any high-res avatars yet.
515 EXPECT_EQ(0U, GetCache()->cached_avatar_images_.size()); 520 EXPECT_EQ(0U, GetCache()->cached_avatar_images_.size());
516 EXPECT_EQ(0U, GetCache()->avatar_images_downloads_in_progress_.size()); 521
522 // After adding a new profile, the download of high-res avatar will be
523 // triggered if the flag kNewAvatarMenu has been set. But the downloader
524 // won't ever call OnFetchComplete in the test.
525 EXPECT_EQ(1U, GetCache()->avatar_images_downloads_in_progress_.size());
526
517 EXPECT_FALSE(GetCache()->GetHighResAvatarOfProfileAtIndex(0)); 527 EXPECT_FALSE(GetCache()->GetHighResAvatarOfProfileAtIndex(0));
518 528
519 // Simulate downloading a high-res avatar. 529 // Simulate downloading a high-res avatar.
520 const size_t kIconIndex = 0; 530 const size_t kIconIndex = 0;
521 ProfileAvatarDownloader avatar_downloader( 531 ProfileAvatarDownloader avatar_downloader(
522 kIconIndex, GetCache()->GetPathOfProfileAtIndex(0), GetCache()); 532 kIconIndex, GetCache()->GetPathOfProfileAtIndex(0), GetCache());
523 533
524 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. 534 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels.
525 SkBitmap bitmap; 535 SkBitmap bitmap;
526 bitmap.allocN32Pixels(2, 2); 536 bitmap.allocN32Pixels(2, 2);
527 bitmap.eraseColor(SK_ColorGREEN); 537 bitmap.eraseColor(SK_ColorGREEN);
528 538
529 avatar_downloader.OnFetchComplete( 539 avatar_downloader.OnFetchComplete(
530 GURL("http://www.google.com/avatar.png"), &bitmap); 540 GURL("http://www.google.com/avatar.png"), &bitmap);
531 541
532 std::string file_name = 542 std::string file_name =
533 profiles::GetDefaultAvatarIconFileNameAtIndex(kIconIndex); 543 profiles::GetDefaultAvatarIconFileNameAtIndex(kIconIndex);
534 544
535 // The file should have been cached and saved. 545 // The file should have been cached and saved.
536 EXPECT_EQ(0U, GetCache()->avatar_images_downloads_in_progress_.size()); 546 EXPECT_EQ(1U, GetCache()->avatar_images_downloads_in_progress_.size());
537 EXPECT_EQ(1U, GetCache()->cached_avatar_images_.size()); 547 EXPECT_EQ(1U, GetCache()->cached_avatar_images_.size());
538 EXPECT_TRUE(GetCache()->GetHighResAvatarOfProfileAtIndex(0)); 548 EXPECT_TRUE(GetCache()->GetHighResAvatarOfProfileAtIndex(0));
539 EXPECT_EQ(GetCache()->cached_avatar_images_[file_name], 549 EXPECT_EQ(GetCache()->cached_avatar_images_[file_name],
540 GetCache()->GetHighResAvatarOfProfileAtIndex(0)); 550 GetCache()->GetHighResAvatarOfProfileAtIndex(0));
541 551
542 // Make sure everything has completed, and the file has been written to disk. 552 // Make sure everything has completed, and the file has been written to disk.
543 base::RunLoop().RunUntilIdle(); 553 base::RunLoop().RunUntilIdle();
544 554
545 // Clean up. 555 // Clean up.
546 base::FilePath icon_path = 556 base::FilePath icon_path =
547 profiles::GetPathOfHighResAvatarAtIndex(kIconIndex); 557 profiles::GetPathOfHighResAvatarAtIndex(kIconIndex);
548 EXPECT_NE(std::string::npos, icon_path.MaybeAsASCII().find(file_name)); 558 EXPECT_NE(std::string::npos, icon_path.MaybeAsASCII().find(file_name));
549 EXPECT_TRUE(base::PathExists(icon_path)); 559 EXPECT_TRUE(base::PathExists(icon_path));
550 EXPECT_TRUE(base::DeleteFile(icon_path, true)); 560 EXPECT_TRUE(base::DeleteFile(icon_path, true));
551 EXPECT_FALSE(base::PathExists(icon_path)); 561 EXPECT_FALSE(base::PathExists(icon_path));
552 } 562 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_info_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698