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

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

Issue 10914109: Refactoring and tests for the highly undertested file_util::CreateOrUpdateShortcutLink() method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
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 "base/test/test_file_util.h"
10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_shortcut_manager.h" 12 #include "chrome/browser/profiles/profile_shortcut_manager.h"
12 #include "chrome/installer/util/browser_distribution.h" 13 #include "chrome/installer/util/browser_distribution.h"
13 #include "chrome/installer/util/shell_util.h" 14 #include "chrome/installer/util/shell_util.h"
14 #include "chrome/test/base/testing_browser_process.h" 15 #include "chrome/test/base/testing_browser_process.h"
15 #include "chrome/test/base/testing_pref_service.h" 16 #include "chrome/test/base/testing_pref_service.h"
16 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
17 #include "chrome/test/base/testing_profile_manager.h" 18 #include "chrome/test/base/testing_profile_manager.h"
18 #include "content/public/test/test_browser_thread.h" 19 #include "content/public/test/test_browser_thread.h"
19 #include "grit/theme_resources.h" 20 #include "grit/theme_resources.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
22 23
23 using content::BrowserThread; 24 using content::BrowserThread;
24 25
25 namespace { 26 namespace {
26 27
27 ShellUtil::VerifyShortcutStatus VerifyProfileShortcut( 28 file_util::VerifyShortcutStatus VerifyProfileShortcut(
28 const string16& profile_name) { 29 const string16& profile_name) {
29 FilePath exe_path; 30 FilePath exe_path;
30 CHECK(PathService::Get(base::FILE_EXE, &exe_path)); 31 EXPECT_TRUE(PathService::Get(base::FILE_EXE, &exe_path));
31 32
32 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 33 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
33 34
34 // Get the desktop path of the current user. 35 // Get the desktop path of the current user.
35 FilePath shortcut_path; 36 FilePath shortcut_path;
36 ShellUtil::GetDesktopPath(false, &shortcut_path); 37 ShellUtil::GetDesktopPath(false, &shortcut_path);
37 // Get the name of the shortcut with profile attached 38 // Get the name of the shortcut with profile attached
38 string16 shortcut_name; 39 string16 shortcut_name;
39 ShellUtil::GetChromeShortcutName(dist, false, profile_name, 40 ShellUtil::GetChromeShortcutName(dist, false, profile_name,
40 &shortcut_name); 41 &shortcut_name);
41 shortcut_path = shortcut_path.Append(shortcut_name); 42 shortcut_path = shortcut_path.Append(shortcut_name);
42 43
43 return ShellUtil::VerifyChromeShortcut( 44 // TODO(hallielaine): With this new struct method for VerifyShortcut you can
44 exe_path.value(), shortcut_path.value(), dist->GetAppDescription(), 45 // now test more properties like: arguments, icon, icon_index, and app_id.
45 0); 46 file_util::ShortcutProperties expected_properties;
47 expected_properties.set_target(exe_path.value());
48 expected_properties.set_description(dist->GetAppDescription());
49 expected_properties.set_dual_mode(false);
50 return file_util::VerifyShortcut(shortcut_path.value(), expected_properties);
46 } 51 }
47 52
48 } // namespace 53 } // namespace
49 54
50 class ProfileShortcutManagerTest : public testing::Test { 55 class ProfileShortcutManagerTest : public testing::Test {
51 protected: 56 protected:
52 ProfileShortcutManagerTest() 57 ProfileShortcutManagerTest()
53 : ui_thread_(BrowserThread::UI, &message_loop_), 58 : ui_thread_(BrowserThread::UI, &message_loop_),
54 file_thread_(BrowserThread::FILE, &message_loop_) { 59 file_thread_(BrowserThread::FILE, &message_loop_) {
55 } 60 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 profile_manager_->profile_info_cache()->GetPathOfProfileAtIndex(0); 94 profile_manager_->profile_info_cache()->GetPathOfProfileAtIndex(0);
90 string16 profile_name; 95 string16 profile_name;
91 if (i != num_profiles - 1) { 96 if (i != num_profiles - 1) {
92 profile_name = 97 profile_name =
93 profile_manager_->profile_info_cache()->GetNameOfProfileAtIndex(0); 98 profile_manager_->profile_info_cache()->GetNameOfProfileAtIndex(0);
94 } 99 }
95 profile_manager_->profile_info_cache()->DeleteProfileFromCache( 100 profile_manager_->profile_info_cache()->DeleteProfileFromCache(
96 profile_path); 101 profile_path);
97 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 102 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
98 MessageLoop::current()->Run(); 103 MessageLoop::current()->Run();
99 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_FAILURE_UNEXPECTED, 104 EXPECT_EQ(file_util::VERIFY_SHORTCUT_FAILURE_FILE_NOT_FOUND,
100 VerifyProfileShortcut(profile_name)); 105 VerifyProfileShortcut(profile_name));
101 ASSERT_FALSE(file_util::PathExists(profile_path.Append( 106 ASSERT_FALSE(file_util::PathExists(profile_path.Append(
102 FILE_PATH_LITERAL("Google Profile.ico")))); 107 FILE_PATH_LITERAL("Google Profile.ico"))));
103 } 108 }
104 } 109 }
105 110
106 void SetupDefaultProfileShortcut() { 111 void SetupDefaultProfileShortcut() {
107 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_FAILURE_UNEXPECTED, 112 EXPECT_EQ(file_util::VERIFY_SHORTCUT_FAILURE_FILE_NOT_FOUND,
108 VerifyProfileShortcut(profile_name_)); 113 VerifyProfileShortcut(profile_name_));
109 114
110 profile_manager_->profile_info_cache()->AddProfileToCache( 115 profile_manager_->profile_info_cache()->AddProfileToCache(
111 dest_path_, profile_name_, string16(), 0); 116 dest_path_, profile_name_, string16(), 0);
112 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 117 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
113 MessageLoop::current()->Run(); 118 MessageLoop::current()->Run();
114 // We now have 1 profile, so we expect a new shortcut with no profile 119 // We now have 1 profile, so we expect a new shortcut with no profile
115 // information. 120 // information.
116 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, 121 EXPECT_EQ(file_util::VERIFY_SHORTCUT_SUCCESS,
117 VerifyProfileShortcut(string16())); 122 VerifyProfileShortcut(string16()));
118 } 123 }
119 124
120 void SetupAndCreateTwoShortcuts() { 125 void SetupAndCreateTwoShortcuts() {
121 ASSERT_EQ(0, profile_manager_->profile_info_cache()->GetNumberOfProfiles()); 126 ASSERT_EQ(0, profile_manager_->profile_info_cache()->GetNumberOfProfiles());
122 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_FAILURE_UNEXPECTED, 127 EXPECT_EQ(file_util::VERIFY_SHORTCUT_FAILURE_FILE_NOT_FOUND,
123 VerifyProfileShortcut(profile_name_)); 128 VerifyProfileShortcut(profile_name_));
124 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_FAILURE_UNEXPECTED, 129 EXPECT_EQ(file_util::VERIFY_SHORTCUT_FAILURE_FILE_NOT_FOUND,
125 VerifyProfileShortcut(second_profile_name_)); 130 VerifyProfileShortcut(second_profile_name_));
126 131
127 profile_manager_->profile_info_cache()->AddProfileToCache( 132 profile_manager_->profile_info_cache()->AddProfileToCache(
128 dest_path_, profile_name_, string16(), 0); 133 dest_path_, profile_name_, string16(), 0);
129 profile_manager_->profile_info_cache()->AddProfileToCache( 134 profile_manager_->profile_info_cache()->AddProfileToCache(
130 second_dest_path_, second_profile_name_, string16(), 0); 135 second_dest_path_, second_profile_name_, string16(), 0);
131 136
132 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 137 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
133 MessageLoop::current()->Run(); 138 MessageLoop::current()->Run();
134 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, 139 EXPECT_EQ(file_util::VERIFY_SHORTCUT_SUCCESS,
135 VerifyProfileShortcut(profile_name_)); 140 VerifyProfileShortcut(profile_name_));
136 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, 141 EXPECT_EQ(file_util::VERIFY_SHORTCUT_SUCCESS,
137 VerifyProfileShortcut(second_profile_name_)); 142 VerifyProfileShortcut(second_profile_name_));
138 } 143 }
139 144
140 MessageLoopForUI message_loop_; 145 MessageLoopForUI message_loop_;
141 content::TestBrowserThread ui_thread_; 146 content::TestBrowserThread ui_thread_;
142 content::TestBrowserThread file_thread_; 147 content::TestBrowserThread file_thread_;
143 scoped_ptr<TestingProfileManager> profile_manager_; 148 scoped_ptr<TestingProfileManager> profile_manager_;
144 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_; 149 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_;
145 FilePath dest_path_; 150 FilePath dest_path_;
146 string16 profile_name_; 151 string16 profile_name_;
147 FilePath second_dest_path_; 152 FilePath second_dest_path_;
148 string16 second_profile_name_; 153 string16 second_profile_name_;
149 }; 154 };
150 155
151 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) { 156 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) {
152 if (!profile_shortcut_manager_.get()) 157 if (!profile_shortcut_manager_.get())
153 return; 158 return;
154 ProfileShortcutManagerTest::SetupDefaultProfileShortcut(); 159 ProfileShortcutManagerTest::SetupDefaultProfileShortcut();
155 160
156 profile_manager_->profile_info_cache()->AddProfileToCache( 161 profile_manager_->profile_info_cache()->AddProfileToCache(
157 second_dest_path_, second_profile_name_, string16(), 0); 162 second_dest_path_, second_profile_name_, string16(), 0);
158 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 163 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
159 MessageLoop::current()->Run(); 164 MessageLoop::current()->Run();
160 165
161 // We now have 2 profiles, so we expect a new shortcut with profile 166 // We now have 2 profiles, so we expect a new shortcut with profile
162 // information for this 2nd profile. 167 // information for this 2nd profile.
163 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, 168 EXPECT_EQ(file_util::VERIFY_SHORTCUT_SUCCESS,
164 VerifyProfileShortcut(second_profile_name_)); 169 VerifyProfileShortcut(second_profile_name_));
165 ASSERT_TRUE(file_util::PathExists(second_dest_path_.Append( 170 ASSERT_TRUE(file_util::PathExists(second_dest_path_.Append(
166 FILE_PATH_LITERAL("Google Profile.ico")))); 171 FILE_PATH_LITERAL("Google Profile.ico"))));
167 } 172 }
168 173
169 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsUpdate) { 174 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsUpdate) {
170 if (!profile_shortcut_manager_.get()) 175 if (!profile_shortcut_manager_.get())
171 return; 176 return;
172 ProfileShortcutManagerTest::SetupDefaultProfileShortcut(); 177 ProfileShortcutManagerTest::SetupDefaultProfileShortcut();
173 178
174 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_FAILURE_UNEXPECTED, 179 EXPECT_EQ(file_util::VERIFY_SHORTCUT_FAILURE_FILE_NOT_FOUND,
175 VerifyProfileShortcut(second_profile_name_)); 180 VerifyProfileShortcut(second_profile_name_));
176 181
177 profile_manager_->profile_info_cache()->AddProfileToCache( 182 profile_manager_->profile_info_cache()->AddProfileToCache(
178 second_dest_path_, second_profile_name_, string16(), 0); 183 second_dest_path_, second_profile_name_, string16(), 0);
179 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 184 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
180 MessageLoop::current()->Run(); 185 MessageLoop::current()->Run();
181 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, 186 EXPECT_EQ(file_util::VERIFY_SHORTCUT_SUCCESS,
182 VerifyProfileShortcut(second_profile_name_)); 187 VerifyProfileShortcut(second_profile_name_));
183 188
184 // Cause an update in ProfileShortcutManager by modifying the profile info 189 // Cause an update in ProfileShortcutManager by modifying the profile info
185 // cache. 190 // cache.
186 string16 new_profile_name = ASCIIToUTF16("New Profile Name"); 191 string16 new_profile_name = ASCIIToUTF16("New Profile Name");
187 profile_manager_->profile_info_cache()->SetNameOfProfileAtIndex( 192 profile_manager_->profile_info_cache()->SetNameOfProfileAtIndex(
188 profile_manager_->profile_info_cache()->GetIndexOfProfileWithPath( 193 profile_manager_->profile_info_cache()->GetIndexOfProfileWithPath(
189 second_dest_path_), 194 second_dest_path_),
190 new_profile_name); 195 new_profile_name);
191 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 196 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
192 MessageLoop::current()->Run(); 197 MessageLoop::current()->Run();
193 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_FAILURE_UNEXPECTED, 198 EXPECT_EQ(file_util::VERIFY_SHORTCUT_FAILURE_FILE_NOT_FOUND,
194 VerifyProfileShortcut(second_profile_name_)); 199 VerifyProfileShortcut(second_profile_name_));
195 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, 200 EXPECT_EQ(file_util::VERIFY_SHORTCUT_SUCCESS,
196 VerifyProfileShortcut(new_profile_name)); 201 VerifyProfileShortcut(new_profile_name));
197 } 202 }
198 203
199 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsDeleteSecondToLast) { 204 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsDeleteSecondToLast) {
200 if (!profile_shortcut_manager_.get()) 205 if (!profile_shortcut_manager_.get())
201 return; 206 return;
202 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts(); 207 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts();
203 208
204 // Delete one shortcut 209 // Delete one shortcut
205 profile_manager_->profile_info_cache()->DeleteProfileFromCache( 210 profile_manager_->profile_info_cache()->DeleteProfileFromCache(
206 second_dest_path_); 211 second_dest_path_);
207 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 212 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
208 MessageLoop::current()->Run(); 213 MessageLoop::current()->Run();
209 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_FAILURE_UNEXPECTED, 214 EXPECT_EQ(file_util::VERIFY_SHORTCUT_FAILURE_FILE_NOT_FOUND,
210 VerifyProfileShortcut(second_profile_name_)); 215 VerifyProfileShortcut(second_profile_name_));
211 216
212 // Verify that the profile name has been removed from the remaining shortcut 217 // Verify that the profile name has been removed from the remaining shortcut
213 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, 218 EXPECT_EQ(file_util::VERIFY_SHORTCUT_SUCCESS,
214 VerifyProfileShortcut(string16())); 219 VerifyProfileShortcut(string16()));
215 // Verify that an additional shortcut, with the default profile's name does 220 // Verify that an additional shortcut, with the default profile's name does
216 // not exist 221 // not exist
217 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_FAILURE_UNEXPECTED, 222 EXPECT_EQ(file_util::VERIFY_SHORTCUT_FAILURE_FILE_NOT_FOUND,
218 VerifyProfileShortcut(profile_name_)); 223 VerifyProfileShortcut(profile_name_));
219 } 224 }
220 225
221 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreateSecond) { 226 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreateSecond) {
222 if (!profile_shortcut_manager_.get()) 227 if (!profile_shortcut_manager_.get())
223 return; 228 return;
224 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts(); 229 ProfileShortcutManagerTest::SetupAndCreateTwoShortcuts();
225 230
226 // Delete one shortcut 231 // Delete one shortcut
227 profile_manager_->profile_info_cache()->DeleteProfileFromCache( 232 profile_manager_->profile_info_cache()->DeleteProfileFromCache(
228 second_dest_path_); 233 second_dest_path_);
229 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 234 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
230 MessageLoop::current()->Run(); 235 MessageLoop::current()->Run();
231 236
232 // Verify that a default shortcut exists (no profile name/avatar) 237 // Verify that a default shortcut exists (no profile name/avatar)
233 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, 238 EXPECT_EQ(file_util::VERIFY_SHORTCUT_SUCCESS,
234 VerifyProfileShortcut(string16())); 239 VerifyProfileShortcut(string16()));
235 // Verify that an additional shortcut, with the default profile's name does 240 // Verify that an additional shortcut, with the default profile's name does
236 // not exist 241 // not exist
237 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_FAILURE_UNEXPECTED, 242 EXPECT_EQ(file_util::VERIFY_SHORTCUT_FAILURE_FILE_NOT_FOUND,
238 VerifyProfileShortcut(profile_name_)); 243 VerifyProfileShortcut(profile_name_));
239 244
240 // Create a second profile and shortcut 245 // Create a second profile and shortcut
241 profile_manager_->profile_info_cache()->AddProfileToCache( 246 profile_manager_->profile_info_cache()->AddProfileToCache(
242 second_dest_path_, second_profile_name_, string16(), 0); 247 second_dest_path_, second_profile_name_, string16(), 0);
243 248
244 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 249 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
245 MessageLoop::current()->Run(); 250 MessageLoop::current()->Run();
246 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, 251 EXPECT_EQ(file_util::VERIFY_SHORTCUT_SUCCESS,
247 VerifyProfileShortcut(second_profile_name_)); 252 VerifyProfileShortcut(second_profile_name_));
248 253
249 // Verify that the original shortcut received the profile's name 254 // Verify that the original shortcut received the profile's name
250 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, 255 EXPECT_EQ(file_util::VERIFY_SHORTCUT_SUCCESS,
251 VerifyProfileShortcut(profile_name_)); 256 VerifyProfileShortcut(profile_name_));
252 // Verify that a default shortcut no longer exists 257 // Verify that a default shortcut no longer exists
253 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_FAILURE_UNEXPECTED, 258 EXPECT_EQ(file_util::VERIFY_SHORTCUT_FAILURE_FILE_NOT_FOUND,
254 VerifyProfileShortcut(string16())); 259 VerifyProfileShortcut(string16()));
255 } 260 }
256 261
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698