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

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

Issue 1038423004: Reland of: Change default code flag to NewAvatarMenu. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove unneeded code from ProfileInfoCacheTest Created 5 years, 8 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
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/command_line.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 for (size_t i = 0; i < 4; i++) 539 for (size_t i = 0; i < 4; i++)
540 ASSERT_FALSE(names[i].empty()); 540 ASSERT_FALSE(names[i].empty());
541 } 541 }
542 542
543 // High res avatar downloading is only supported on desktop. 543 // High res avatar downloading is only supported on desktop.
544 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS) 544 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS)
545 TEST_F(ProfileInfoCacheTest, DownloadHighResAvatarTest) { 545 TEST_F(ProfileInfoCacheTest, DownloadHighResAvatarTest) {
546 switches::EnableNewAvatarMenuForTesting( 546 switches::EnableNewAvatarMenuForTesting(
547 base::CommandLine::ForCurrentProcess()); 547 base::CommandLine::ForCurrentProcess());
548 548
549 EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles()); 549 // The TestingProfileManager's ProfileInfoCache doesn't download avatars.
550 ProfileInfoCache profile_info_cache(g_browser_process->local_state(),
551 testing_profile_manager_.profile_manager()->user_data_dir());
552
553 // // Make sure there are no avatars already on disk.
554 const size_t kIconIndex = 0;
555 base::FilePath icon_path =
556 profiles::GetPathOfHighResAvatarAtIndex(kIconIndex);
557 EXPECT_FALSE(base::PathExists(icon_path));
558
559 EXPECT_EQ(0U, profile_info_cache.GetNumberOfProfiles());
550 base::FilePath path_1 = GetProfilePath("path_1"); 560 base::FilePath path_1 = GetProfilePath("path_1");
551 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), 561 profile_info_cache.AddProfileToCache(path_1, ASCIIToUTF16("name_1"),
552 base::string16(), 0, std::string()); 562 base::string16(), kIconIndex, std::string());
553 EXPECT_EQ(1U, GetCache()->GetNumberOfProfiles()); 563 EXPECT_EQ(1U, profile_info_cache.GetNumberOfProfiles());
554 base::RunLoop().RunUntilIdle(); 564 base::RunLoop().RunUntilIdle();
555 565
556 // We haven't downloaded any high-res avatars yet. 566 // We haven't downloaded any high-res avatars yet.
557 EXPECT_EQ(0U, GetCache()->cached_avatar_images_.size()); 567 EXPECT_EQ(0U, profile_info_cache.cached_avatar_images_.size());
558 568
559 // After adding a new profile, the download of high-res avatar will be 569 // After adding a new profile, the download of high-res avatar will be
560 // triggered if the flag kNewAvatarMenu has been set. But the downloader 570 // triggered if the flag kNewAvatarMenu has been set. But the downloader
561 // won't ever call OnFetchComplete in the test. 571 // won't ever call OnFetchComplete in the test.
562 EXPECT_EQ(1U, GetCache()->avatar_images_downloads_in_progress_.size()); 572 EXPECT_EQ(1U, profile_info_cache.avatar_images_downloads_in_progress_.size());
563 573
564 EXPECT_FALSE(GetCache()->GetHighResAvatarOfProfileAtIndex(0)); 574 EXPECT_FALSE(profile_info_cache.GetHighResAvatarOfProfileAtIndex(0));
565 575
566 // Simulate downloading a high-res avatar. 576 // Simulate downloading a high-res avatar.
567 const size_t kIconIndex = 0;
568 ProfileAvatarDownloader avatar_downloader( 577 ProfileAvatarDownloader avatar_downloader(
569 kIconIndex, GetCache()->GetPathOfProfileAtIndex(0), GetCache()); 578 kIconIndex, profile_info_cache.GetPathOfProfileAtIndex(0),
579 &profile_info_cache);
570 580
571 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. 581 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels.
572 SkBitmap bitmap; 582 SkBitmap bitmap;
573 bitmap.allocN32Pixels(2, 2); 583 bitmap.allocN32Pixels(2, 2);
574 bitmap.eraseColor(SK_ColorGREEN); 584 bitmap.eraseColor(SK_ColorGREEN);
575 585
576 avatar_downloader.OnFetchComplete( 586 avatar_downloader.OnFetchComplete(
577 GURL("http://www.google.com/avatar.png"), &bitmap); 587 GURL("http://www.google.com/avatar.png"), &bitmap);
578 588
579 // Now the download should not be in progress anymore. 589 // Now the download should not be in progress anymore.
580 EXPECT_EQ(0U, GetCache()->avatar_images_downloads_in_progress_.size()); 590 EXPECT_EQ(0U, profile_info_cache.avatar_images_downloads_in_progress_.size());
581 591
582 std::string file_name = 592 std::string file_name =
583 profiles::GetDefaultAvatarIconFileNameAtIndex(kIconIndex); 593 profiles::GetDefaultAvatarIconFileNameAtIndex(kIconIndex);
584 594
585 // The file should have been cached and saved. 595 // The file should have been cached and saved.
586 EXPECT_EQ(1U, GetCache()->cached_avatar_images_.size()); 596 EXPECT_EQ(1U, profile_info_cache.cached_avatar_images_.size());
587 EXPECT_TRUE(GetCache()->GetHighResAvatarOfProfileAtIndex(0)); 597 EXPECT_TRUE(profile_info_cache.GetHighResAvatarOfProfileAtIndex(0));
588 EXPECT_EQ(GetCache()->cached_avatar_images_[file_name], 598 EXPECT_EQ(profile_info_cache.cached_avatar_images_[file_name],
589 GetCache()->GetHighResAvatarOfProfileAtIndex(0)); 599 profile_info_cache.GetHighResAvatarOfProfileAtIndex(0));
590 600
591 // Make sure everything has completed, and the file has been written to disk. 601 // Make sure everything has completed, and the file has been written to disk.
592 base::RunLoop().RunUntilIdle(); 602 base::RunLoop().RunUntilIdle();
593 603
594 // Clean up. 604 // Clean up.
595 base::FilePath icon_path =
596 profiles::GetPathOfHighResAvatarAtIndex(kIconIndex);
597 EXPECT_NE(std::string::npos, icon_path.MaybeAsASCII().find(file_name)); 605 EXPECT_NE(std::string::npos, icon_path.MaybeAsASCII().find(file_name));
598 EXPECT_TRUE(base::PathExists(icon_path)); 606 EXPECT_TRUE(base::PathExists(icon_path));
599 EXPECT_TRUE(base::DeleteFile(icon_path, true)); 607 EXPECT_TRUE(base::DeleteFile(icon_path, true));
600 EXPECT_FALSE(base::PathExists(icon_path)); 608 EXPECT_FALSE(base::PathExists(icon_path));
601 } 609 }
602 610
603 TEST_F(ProfileInfoCacheTest, MigrateLegacyProfileNamesWithNewAvatarMenu) { 611 TEST_F(ProfileInfoCacheTest, MigrateLegacyProfileNamesWithNewAvatarMenu) {
604 switches::EnableNewAvatarMenuForTesting( 612 switches::EnableNewAvatarMenuForTesting(
605 base::CommandLine::ForCurrentProcess()); 613 base::CommandLine::ForCurrentProcess());
606 EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles()); 614 EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles());
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 // Profile names should have been preserved. 685 // Profile names should have been preserved.
678 EXPECT_EQ(name_1, GetCache()->GetNameOfProfileAtIndex( 686 EXPECT_EQ(name_1, GetCache()->GetNameOfProfileAtIndex(
679 GetCache()->GetIndexOfProfileWithPath(path_1))); 687 GetCache()->GetIndexOfProfileWithPath(path_1)));
680 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex( 688 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex(
681 GetCache()->GetIndexOfProfileWithPath(path_2))); 689 GetCache()->GetIndexOfProfileWithPath(path_2)));
682 EXPECT_EQ(name_3, GetCache()->GetNameOfProfileAtIndex( 690 EXPECT_EQ(name_3, GetCache()->GetNameOfProfileAtIndex(
683 GetCache()->GetIndexOfProfileWithPath(path_3))); 691 GetCache()->GetIndexOfProfileWithPath(path_3)));
684 EXPECT_EQ(name_4, GetCache()->GetNameOfProfileAtIndex( 692 EXPECT_EQ(name_4, GetCache()->GetNameOfProfileAtIndex(
685 GetCache()->GetIndexOfProfileWithPath(path_4))); 693 GetCache()->GetIndexOfProfileWithPath(path_4)));
686 } 694 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_info_cache.cc ('k') | chrome/browser/profiles/profile_info_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698