Chromium Code Reviews| Index: chrome/browser/profiles/profile_manager_unittest.cc |
| =================================================================== |
| --- chrome/browser/profiles/profile_manager_unittest.cc (revision 150342) |
| +++ chrome/browser/profiles/profile_manager_unittest.cc (working copy) |
| @@ -23,12 +23,15 @@ |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/profiles/profile_info_cache.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| +#include "chrome/browser/profiles/profile_shortcut_manager.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/common/chrome_constants.h" |
| #include "chrome/common/chrome_notification_types.h" |
| #include "chrome/common/chrome_paths.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/pref_names.h" |
| +#include "chrome/installer/util/browser_distribution.h" |
| +#include "chrome/installer/util/shell_util.h" |
| #include "chrome/test/base/test_browser_window.h" |
| #include "chrome/test/base/testing_browser_process.h" |
| #include "chrome/test/base/testing_pref_service.h" |
| @@ -37,6 +40,7 @@ |
| #include "content/public/test/test_browser_thread.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| #if defined(OS_CHROMEOS) |
| #include "chrome/browser/chromeos/cros/cros_library.h" |
| @@ -50,6 +54,9 @@ |
| // observers is the same. |
| Profile* g_created_profile; |
| +// Profile shortcut manager for desktop shortcuts |
| +ProfileShortcutManager* profile_shortcut_manager; |
|
sail
2012/08/13 22:09:36
you don't need a global for this, this can just be
Halli
2012/08/14 18:25:57
Kept as a global in the new test class profile_sho
|
| + |
| } // namespace |
| namespace testing { |
| @@ -77,13 +84,6 @@ |
| return new TestingProfile(path, this); |
| } |
| - |
| -#if defined(OS_WIN) |
| - virtual ProfileShortcutManagerWin* CreateShortcutManager() OVERRIDE { |
| - // We should avoid creating shortcuts in these tests. |
| - return NULL; |
| - } |
| -#endif |
| }; |
| } // namespace testing |
| @@ -117,8 +117,12 @@ |
| ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| static_cast<TestingBrowserProcess*>(g_browser_process)->SetProfileManager( |
| new testing::ProfileManager(temp_dir_.path())); |
| + |
| + // Profile shortcut manager will be NULL for non-windows platforms |
| + profile_shortcut_manager = ProfileShortcutManager::Create(); |
| + |
| #if defined(OS_CHROMEOS) |
| - CommandLine *cl = CommandLine::ForCurrentProcess(); |
| + CommandLine* cl = CommandLine::ForCurrentProcess(); |
| cl->AppendSwitch(switches::kTestType); |
| #endif |
| } |
| @@ -287,13 +291,16 @@ |
| profile_manager->CreateProfileAsync(dest_path, |
| base::Bind(&MockObserver::OnProfileCreated, |
| - base::Unretained(&mock_observer1)), string16(), string16()); |
| + base::Unretained(&mock_observer1)), |
| + string16(), string16()); |
| profile_manager->CreateProfileAsync(dest_path, |
| base::Bind(&MockObserver::OnProfileCreated, |
| - base::Unretained(&mock_observer2)), string16(), string16()); |
| + base::Unretained(&mock_observer2)), |
| + string16(), string16()); |
| profile_manager->CreateProfileAsync(dest_path, |
| base::Bind(&MockObserver::OnProfileCreated, |
| - base::Unretained(&mock_observer3)), string16(), string16()); |
| + base::Unretained(&mock_observer3)), |
| + string16(), string16()); |
| message_loop_.RunAllPending(); |
| } |
| @@ -569,3 +576,70 @@ |
| ASSERT_EQ(0U, last_opened_profiles.size()); |
| } |
| #endif // !defined(OS_ANDROID) |
| + |
| +TEST_F(ProfileManagerTest, WinDesktopShortcutsIconExists) { |
|
sail
2012/08/13 22:09:36
This isn't related to profile manager so it should
Halli
2012/08/14 18:25:57
Done.
|
| + if (!profile_shortcut_manager) |
| + return; |
| + |
| + FilePath dest_path = temp_dir_.path(); |
| + string16 profile_name = ASCIIToUTF16("My Profile"); |
| + |
| + ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| + |
| + gfx::Image& avatar = ResourceBundle::GetSharedInstance(). |
| + GetNativeImageNamed(profile_manager->GetProfileInfoCache(). |
| + GetDefaultAvatarIconResourceIDAtIndex(0)); |
| + |
| + profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path, |
| + profile_name, avatar); |
| + |
| + ASSERT_TRUE(file_util::ContainsPath(temp_dir_.path(), dest_path.Append( |
|
sail
2012/08/13 22:14:35
maybe file_util::PathExists() instead of ContainsP
Halli
2012/08/14 18:25:57
Done.
|
| + (FILE_PATH_LITERAL("Google Profile.ico"))))); |
| + |
| + profile_shortcut_manager->DeleteChromeDesktopShortcut(dest_path); |
|
sail
2012/08/13 22:14:35
maybe test that the file no longer exists?
Halli
2012/08/14 18:25:57
TODO in separate CL
|
| +} |
| + |
| +TEST_F(ProfileManagerTest, WinDesktopShortcutsLnk) { |
| + if (!profile_shortcut_manager) |
| + return; |
| + |
| + FilePath dest_path = temp_dir_.path(); |
| + dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1")); |
| + |
| + ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| + |
| + // Successfully create the profile. |
| + TestingProfile* profile = |
| + static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path)); |
| + ASSERT_TRUE(profile); |
| + |
| + profile->SetName(ASCIIToWide("My Profile")); |
| + |
| + gfx::Image& avatar = ResourceBundle::GetSharedInstance(). |
| + GetNativeImageNamed(profile_manager->GetProfileInfoCache(). |
| + GetDefaultAvatarIconResourceIDAtIndex(0)); |
| + |
| + profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path, |
| + profile->GetName(), avatar); |
| + |
| + FilePath exe_path; |
| + ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); |
| + |
| + FilePath shortcut; |
| + string16 shortcut_name; |
| + BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| + |
| + // Get the desktop path of the current user |
| + ShellUtil::GetDesktopPath(false, &shortcut); |
| + // Get the name of the shortcut with profile attached |
| + ShellUtil::GetChromeShortcutName(dist, false, profile->GetName(), |
| + &shortcut_name); |
| + shortcut = shortcut.Append(shortcut_name); |
| + |
| + EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, |
| + ShellUtil::VerifyChromeShortcut(exe_path.value(), |
| + shortcut.value(), dist->GetAppDescription(), 0)); |
| + |
| + profile_shortcut_manager->DeleteChromeDesktopShortcut(dest_path); |
| +} |
| + |