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

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

Issue 10837352: Update profile desktop shortcuts (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/scoped_temp_dir.h" 8 #include "base/scoped_temp_dir.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_shortcut_manager.h" 11 #include "chrome/browser/profiles/profile_shortcut_manager.h"
12 #include "chrome/installer/util/browser_distribution.h" 12 #include "chrome/installer/util/browser_distribution.h"
13 #include "chrome/installer/util/shell_util.h" 13 #include "chrome/installer/util/shell_util.h"
14 #include "chrome/test/base/testing_browser_process.h"
14 #include "chrome/test/base/testing_pref_service.h" 15 #include "chrome/test/base/testing_pref_service.h"
16 #include "chrome/test/base/testing_profile.h"
17 #include "chrome/test/base/testing_profile_manager.h"
15 #include "content/public/test/test_browser_thread.h" 18 #include "content/public/test/test_browser_thread.h"
16 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
17 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
19 22
20 using content::BrowserThread; 23 using content::BrowserThread;
21 24
25 namespace {
26
27 bool ProfileShortcutExists(const string16& profile_name) {
28 FilePath exe_path;
29 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
30
31 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
32
33 // Get the desktop path of the current user.
34 FilePath shortcut_path;
35 ShellUtil::GetDesktopPath(false, &shortcut_path);
36 // Get the name of the shortcut with profile attached
37 string16 shortcut_name;
38 ShellUtil::GetChromeShortcutName(dist, false, profile_name,
39 &shortcut_name);
40 shortcut_path = shortcut_path.Append(shortcut_name);
41
42 return ShellUtil::VERIFY_SHORTCUT_SUCCESS ==
43 ShellUtil::VerifyChromeShortcut(
44 exe_path.value(), shortcut_path.value(), dist->GetAppDescription(),
45 0);
46
47 }
48
49 } // namespace
50
22 class ProfileShortcutManagerTest : public testing::Test { 51 class ProfileShortcutManagerTest : public testing::Test {
23 protected: 52 protected:
24 ProfileShortcutManagerTest() 53 ProfileShortcutManagerTest()
25 : file_thread_(BrowserThread::FILE, &message_loop_) { 54 : ui_thread_(BrowserThread::UI, &message_loop_),
55 file_thread_(BrowserThread::FILE, &message_loop_),
56 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.
57 profile_shortcut_manager_(NULL) {
26 } 58 }
27 59
28 virtual void SetUp() { 60 virtual void SetUp() {
29 // Create a new temporary directory, and store the path 61 // Create a new temporary directory, and store the path
30 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 62 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
63
64 TestingBrowserProcess* browser_process =
65 static_cast<TestingBrowserProcess*>(g_browser_process);
66 profile_manager_.reset(new TestingProfileManager(browser_process));
67 ASSERT_TRUE(profile_manager_->SetUp());
68 ProfileInfoCache* cache = profile_manager_->profile_info_cache();
69 // Profile shortcut manager will be NULL for non-windows platforms
70 profile_shortcut_manager_.reset(ProfileShortcutManager::Create(*cache));
31 } 71 }
32 72
33 virtual void TearDown() { 73 virtual void TearDown() {
34 message_loop_.RunAllPending(); 74 message_loop_.RunAllPending();
35 } 75 }
36 76
37 // The path to temporary directory used to contain the test operations. 77 // The path to temporary directory used to contain the test operations.
38 ScopedTempDir temp_dir_; 78 ScopedTempDir temp_dir_;
39 79
40 MessageLoopForUI message_loop_; 80 MessageLoopForUI message_loop_;
81 content::TestBrowserThread ui_thread_;
41 content::TestBrowserThread file_thread_; 82 content::TestBrowserThread file_thread_;
83 scoped_ptr<TestingProfileManager> profile_manager_;
84 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_;
42 }; 85 };
43 86
44 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsIconExists) { 87 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) {
45 // Profile shortcut manager will be NULL for non-windows platforms 88 if (!profile_shortcut_manager_.get())
46 ProfileShortcutManager* profile_shortcut_manager = 89 return;
47 ProfileShortcutManager::Create(); 90 FilePath dest_path = temp_dir_.path();
91 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1"));
92 file_util::CreateDirectoryW(dest_path);
93 string16 profile_name = ASCIIToUTF16("My profile");
48 94
49 if (!profile_shortcut_manager) 95 EXPECT_FALSE(ProfileShortcutExists(profile_name));
50 return; 96 ASSERT_FALSE(file_util::PathExists(dest_path.Append(
51 97 FILE_PATH_LITERAL("Google Profile.ico"))));
52 FilePath dest_path = temp_dir_.path();
53 string16 profile_name = ASCIIToUTF16("My Profile");
54 98
55 gfx::Image& avatar = ResourceBundle::GetSharedInstance(). 99 gfx::Image& avatar = ResourceBundle::GetSharedInstance().
56 GetNativeImageNamed(IDR_PROFILE_AVATAR_0); 100 GetNativeImageNamed(IDR_PROFILE_AVATAR_0);
57 101
58 profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path, 102 profile_shortcut_manager_->StartProfileDesktopShortcutCreation(
59 profile_name, avatar); 103 dest_path, profile_name, avatar);
104 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
105 MessageLoop::current()->Run();
60 106
107 EXPECT_TRUE(ProfileShortcutExists(profile_name));
61 ASSERT_TRUE(file_util::PathExists(dest_path.Append( 108 ASSERT_TRUE(file_util::PathExists(dest_path.Append(
62 (FILE_PATH_LITERAL("Google Profile.ico"))))); 109 (FILE_PATH_LITERAL("Google Profile.ico")))));
63 110
64 profile_shortcut_manager->DeleteChromeDesktopShortcut(dest_path); 111 profile_shortcut_manager_->DeleteProfileDesktopShortcut(
65 112 dest_path, profile_name);
66 // TODO(hallielaine): Verify shortcut deletion 113 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
114 MessageLoop::current()->Run();
115 EXPECT_FALSE(ProfileShortcutExists(profile_name));
116 ASSERT_FALSE(file_util::PathExists(dest_path.Append(
117 (FILE_PATH_LITERAL("Google Profile.ico")))));
67 } 118 }
68 119
69 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsLnk) { 120 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsUpdate) {
70 // Profile shortcut manager will be NULL for non-windows platforms 121 if (!profile_shortcut_manager_.get())
71 ProfileShortcutManager* profile_shortcut_manager = 122 return;
72 ProfileShortcutManager::Create(); 123 string16 profile_name = ASCIIToUTF16("My profile");
124 EXPECT_FALSE(ProfileShortcutExists(profile_name));
73 125
74 if (!profile_shortcut_manager) 126 FilePath dest_path = profile_manager_->profile_info_cache()->GetUserDataDir();
75 return; 127 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1"));
128 file_util::CreateDirectoryW(dest_path);
76 129
77 FilePath dest_path = temp_dir_.path(); 130 profile_manager_->profile_info_cache()->AddProfileToCache(
78 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1")); 131 dest_path, profile_name, string16(), 0);
79
80 gfx::Image& avatar = ResourceBundle::GetSharedInstance(). 132 gfx::Image& avatar = ResourceBundle::GetSharedInstance().
81 GetNativeImageNamed(IDR_PROFILE_AVATAR_0); 133 GetNativeImageNamed(IDR_PROFILE_AVATAR_0);
82 134
83 profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path, 135 profile_shortcut_manager_->StartProfileDesktopShortcutCreation(
84 ASCIIToUTF16("My Profile"), avatar); 136 dest_path, profile_name, avatar);
137 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
138 MessageLoop::current()->Run();
139 EXPECT_TRUE(ProfileShortcutExists(profile_name));
140 string16 new_profile_name = ASCIIToUTF16("My New Profile Name");
141 EXPECT_FALSE(ProfileShortcutExists(new_profile_name));
85 142
86 FilePath exe_path; 143 // Cause an update in ProfileShortcutManager by modifying the profile info
87 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); 144 // cache
145 profile_manager_->profile_info_cache()->SetNameOfProfileAtIndex(
146 profile_manager_->profile_info_cache()->GetIndexOfProfileWithPath(
147 dest_path), new_profile_name);
148 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
149 MessageLoop::current()->Run();
150 EXPECT_FALSE(ProfileShortcutExists(profile_name));
151 EXPECT_TRUE(ProfileShortcutExists(new_profile_name));
88 152
89 FilePath shortcut; 153 profile_shortcut_manager_->DeleteProfileDesktopShortcut(
90 string16 shortcut_name; 154 dest_path, new_profile_name);
91 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 155 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
156 MessageLoop::current()->Run();
157 EXPECT_FALSE(ProfileShortcutExists(profile_name));
158 EXPECT_FALSE(ProfileShortcutExists(new_profile_name));
159 }
92 160
93 // Get the desktop path of the current user
94 ShellUtil::GetDesktopPath(false, &shortcut);
95 // Get the name of the shortcut with profile attached
96 ShellUtil::GetChromeShortcutName(dist, false, ASCIIToUTF16("My Profile"),
97 &shortcut_name);
98 shortcut = shortcut.Append(shortcut_name);
99
100 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
101 ShellUtil::VerifyChromeShortcut(exe_path.value(),
102 shortcut.value(), dist->GetAppDescription(), 0));
103
104 profile_shortcut_manager->DeleteChromeDesktopShortcut(dest_path);
105 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_shortcut_manager.h ('k') | chrome/browser/profiles/profile_shortcut_manager_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698