Index: chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc |
=================================================================== |
--- chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc (revision 152316) |
+++ chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc (working copy) |
@@ -11,7 +11,10 @@ |
#include "chrome/browser/profiles/profile_shortcut_manager.h" |
#include "chrome/installer/util/browser_distribution.h" |
#include "chrome/installer/util/shell_util.h" |
+#include "chrome/test/base/testing_browser_process.h" |
#include "chrome/test/base/testing_pref_service.h" |
+#include "chrome/test/base/testing_profile.h" |
+#include "chrome/test/base/testing_profile_manager.h" |
#include "content/public/test/test_browser_thread.h" |
#include "grit/theme_resources.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -19,15 +22,52 @@ |
using content::BrowserThread; |
+namespace { |
+ |
+bool ProfileShortcutExists(const string16& profile_name) { |
+ FilePath exe_path; |
+ DCHECK(PathService::Get(base::FILE_EXE, &exe_path)); |
sail
2012/08/24 17:32:21
ASSERT_TRUE instead?
Halli
2012/08/24 17:42:40
Gives me- browser\profiles\profile_shortcut_manage
gab
2012/08/24 19:17:32
Hmmm... it doesn't make any sense to me that you c
|
+ |
+ BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
+ |
+ // Get the desktop path of the current user. |
+ FilePath shortcut_path; |
+ ShellUtil::GetDesktopPath(false, &shortcut_path); |
+ // Get the name of the shortcut with profile attached |
+ string16 shortcut_name; |
+ ShellUtil::GetChromeShortcutName(dist, false, profile_name, |
+ &shortcut_name); |
+ shortcut_path = shortcut_path.Append(shortcut_name); |
+ |
+ return ShellUtil::VERIFY_SHORTCUT_SUCCESS == |
+ ShellUtil::VerifyChromeShortcut( |
+ exe_path.value(), shortcut_path.value(), dist->GetAppDescription(), |
+ 0); |
+ |
+} |
+ |
+} // namespace |
+ |
class ProfileShortcutManagerTest : public testing::Test { |
protected: |
ProfileShortcutManagerTest() |
- : file_thread_(BrowserThread::FILE, &message_loop_) { |
+ : ui_thread_(BrowserThread::UI, &message_loop_), |
+ file_thread_(BrowserThread::FILE, &message_loop_), |
+ profile_manager_(NULL), |
sail
2012/08/24 17:32:21
don't need this and the next
Halli
2012/08/24 17:42:40
Done.
|
+ profile_shortcut_manager_(NULL) { |
} |
virtual void SetUp() { |
// Create a new temporary directory, and store the path |
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
+ |
+ TestingBrowserProcess* browser_process = |
+ static_cast<TestingBrowserProcess*>(g_browser_process); |
+ profile_manager_.reset(new TestingProfileManager(browser_process)); |
+ ASSERT_TRUE(profile_manager_->SetUp()); |
+ ProfileInfoCache* cache = profile_manager_->profile_info_cache(); |
+ // Profile shortcut manager will be NULL for non-windows platforms |
+ profile_shortcut_manager_.reset(ProfileShortcutManager::Create(*cache)); |
} |
virtual void TearDown() { |
@@ -38,68 +78,83 @@ |
ScopedTempDir temp_dir_; |
MessageLoopForUI message_loop_; |
+ content::TestBrowserThread ui_thread_; |
content::TestBrowserThread file_thread_; |
+ scoped_ptr<TestingProfileManager> profile_manager_; |
+ scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_; |
}; |
-TEST_F(ProfileShortcutManagerTest, DesktopShortcutsIconExists) { |
- // Profile shortcut manager will be NULL for non-windows platforms |
- ProfileShortcutManager* profile_shortcut_manager = |
- ProfileShortcutManager::Create(); |
- |
- if (!profile_shortcut_manager) |
+TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) { |
+ if (!profile_shortcut_manager_.get()) |
return; |
- |
FilePath dest_path = temp_dir_.path(); |
- string16 profile_name = ASCIIToUTF16("My Profile"); |
+ dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1")); |
+ file_util::CreateDirectoryW(dest_path); |
+ string16 profile_name = ASCIIToUTF16("My profile"); |
+ EXPECT_FALSE(ProfileShortcutExists(profile_name)); |
+ ASSERT_FALSE(file_util::PathExists(dest_path.Append( |
+ FILE_PATH_LITERAL("Google Profile.ico")))); |
+ |
gfx::Image& avatar = ResourceBundle::GetSharedInstance(). |
GetNativeImageNamed(IDR_PROFILE_AVATAR_0); |
- profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path, |
- profile_name, avatar); |
+ profile_shortcut_manager_->StartProfileDesktopShortcutCreation( |
+ dest_path, profile_name, avatar); |
+ MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
+ MessageLoop::current()->Run(); |
+ EXPECT_TRUE(ProfileShortcutExists(profile_name)); |
ASSERT_TRUE(file_util::PathExists(dest_path.Append( |
(FILE_PATH_LITERAL("Google Profile.ico"))))); |
- profile_shortcut_manager->DeleteChromeDesktopShortcut(dest_path); |
- |
- // TODO(hallielaine): Verify shortcut deletion |
+ profile_shortcut_manager_->DeleteProfileDesktopShortcut( |
+ dest_path, profile_name); |
+ MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
+ MessageLoop::current()->Run(); |
+ EXPECT_FALSE(ProfileShortcutExists(profile_name)); |
+ ASSERT_FALSE(file_util::PathExists(dest_path.Append( |
+ (FILE_PATH_LITERAL("Google Profile.ico"))))); |
} |
-TEST_F(ProfileShortcutManagerTest, DesktopShortcutsLnk) { |
- // Profile shortcut manager will be NULL for non-windows platforms |
- ProfileShortcutManager* profile_shortcut_manager = |
- ProfileShortcutManager::Create(); |
- |
- if (!profile_shortcut_manager) |
+TEST_F(ProfileShortcutManagerTest, DesktopShortcutsUpdate) { |
+ if (!profile_shortcut_manager_.get()) |
return; |
+ string16 profile_name = ASCIIToUTF16("My profile"); |
+ EXPECT_FALSE(ProfileShortcutExists(profile_name)); |
- FilePath dest_path = temp_dir_.path(); |
+ FilePath dest_path = profile_manager_->profile_info_cache()->GetUserDataDir(); |
dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1")); |
+ file_util::CreateDirectoryW(dest_path); |
+ profile_manager_->profile_info_cache()->AddProfileToCache( |
+ dest_path, profile_name, string16(), 0); |
gfx::Image& avatar = ResourceBundle::GetSharedInstance(). |
GetNativeImageNamed(IDR_PROFILE_AVATAR_0); |
- profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path, |
- ASCIIToUTF16("My Profile"), avatar); |
+ profile_shortcut_manager_->StartProfileDesktopShortcutCreation( |
+ dest_path, profile_name, avatar); |
+ MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
+ MessageLoop::current()->Run(); |
+ EXPECT_TRUE(ProfileShortcutExists(profile_name)); |
+ string16 new_profile_name = ASCIIToUTF16("My New Profile Name"); |
+ EXPECT_FALSE(ProfileShortcutExists(new_profile_name)); |
- FilePath exe_path; |
- ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); |
+ // Cause an update in ProfileShortcutManager by modifying the profile info |
+ // cache |
+ profile_manager_->profile_info_cache()->SetNameOfProfileAtIndex( |
+ profile_manager_->profile_info_cache()->GetIndexOfProfileWithPath( |
+ dest_path), new_profile_name); |
+ MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
+ MessageLoop::current()->Run(); |
+ EXPECT_FALSE(ProfileShortcutExists(profile_name)); |
+ EXPECT_TRUE(ProfileShortcutExists(new_profile_name)); |
- FilePath shortcut; |
- string16 shortcut_name; |
- BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
+ profile_shortcut_manager_->DeleteProfileDesktopShortcut( |
+ dest_path, new_profile_name); |
+ MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
+ MessageLoop::current()->Run(); |
+ EXPECT_FALSE(ProfileShortcutExists(profile_name)); |
+ EXPECT_FALSE(ProfileShortcutExists(new_profile_name)); |
+} |
- // 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, ASCIIToUTF16("My Profile"), |
- &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); |
-} |