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) |
@@ -8,10 +8,13 @@ |
#include "base/scoped_temp_dir.h" |
#include "base/utf_string_conversions.h" |
#include "chrome/browser/profiles/profile.h" |
+#include "chrome/test/base/testing_profile_manager.h" |
#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 "content/public/test/test_browser_thread.h" |
#include "grit/theme_resources.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -19,15 +22,51 @@ |
using content::BrowserThread; |
+namespace { |
+ |
+bool IsShortcutForProfile(const string16& profile_name) { |
sail
2012/08/24 04:32:26
maybe ProfileShortcutExists or DoesProfileShortcut
Halli
2012/08/24 17:23:56
Done.
|
+ FilePath exe_path; |
+ DCHECK(PathService::Get(base::FILE_EXE, &exe_path)); |
+ |
+ BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
+ |
+ // Get the desktop path of the current user |
sail
2012/08/24 04:32:26
user -> user.
Halli
2012/08/24 17:23:56
Done.
|
+ 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); |
+ |
+ if (ShellUtil::VERIFY_SHORTCUT_SUCCESS == |
sail
2012/08/24 04:32:26
don't need if statement
Halli
2012/08/24 17:23:56
Whoops! Done.
|
+ ShellUtil::VerifyChromeShortcut( |
+ exe_path.value(), shortcut_path.value(), dist->GetAppDescription(), |
+ 0)) |
+ return true; |
+ return false; |
+} |
+ |
+} // 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_) { |
sail
2012/08/24 04:32:26
also need to initialize cache_ and profile_shortcu
Halli
2012/08/24 17:23:56
Done.
|
} |
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); |
+ TestingProfileManager profile_manager(browser_process); |
sail
2012/08/24 04:32:26
this needs to be class scope
Halli
2012/08/24 17:23:56
Done.
|
+ ASSERT_TRUE(profile_manager.SetUp()); |
+ cache_ = profile_manager.profile_info_cache(); |
+ // Profile shortcut manager will be NULL for non-windows platforms |
+ profile_shortcut_manager_ = ProfileShortcutManager::Create(*cache_); |
} |
virtual void TearDown() { |
@@ -38,68 +77,78 @@ |
ScopedTempDir temp_dir_; |
MessageLoopForUI message_loop_; |
+ content::TestBrowserThread ui_thread_; |
content::TestBrowserThread file_thread_; |
+ ProfileInfoCache* cache_; |
+ 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_) |
return; |
- |
FilePath dest_path = temp_dir_.path(); |
- string16 profile_name = ASCIIToUTF16("My Profile"); |
+ string16 profile_name = ASCIIToUTF16("My profile"); |
+ EXPECT_FALSE(IsShortcutForProfile(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(IsShortcutForProfile(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(IsShortcutForProfile(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_) |
return; |
+ string16 profile_name = ASCIIToUTF16("My profile"); |
+ EXPECT_FALSE(IsShortcutForProfile(profile_name)); |
- FilePath dest_path = temp_dir_.path(); |
+ string16 new_profile_name = ASCIIToUTF16("My New Profile Name"); |
sail
2012/08/24 04:32:26
this should move to the location of first use
Halli
2012/08/24 17:23:56
Done.
|
+ FilePath dest_path = cache_->GetUserDataDir(); |
sail
2012/08/24 04:32:26
the other test uses temp_dir.GetPath(). Is there a
Halli
2012/08/24 17:23:56
The cache requires that the profile data is in a s
sail
2012/08/24 17:32:21
Yea, I think using a separate directory in the oth
|
dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1")); |
+ 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(IsShortcutForProfile(profile_name)); |
+ EXPECT_FALSE(IsShortcutForProfile(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 |
+ cache_->SetNameOfProfileAtIndex( |
+ cache_->GetIndexOfProfileWithPath(dest_path), new_profile_name); |
+ MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
+ MessageLoop::current()->Run(); |
+ EXPECT_FALSE(IsShortcutForProfile(profile_name)); |
+ EXPECT_TRUE(IsShortcutForProfile(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(IsShortcutForProfile(profile_name)); |
+ EXPECT_FALSE(IsShortcutForProfile(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); |
-} |