OLD | NEW |
---|---|
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/test/base/testing_profile_manager.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_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_browser_process.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 |
22 class ProfileShortcutManagerTest : public testing::Test { | 25 class ProfileShortcutManagerTest : public testing::Test { |
23 protected: | 26 protected: |
24 ProfileShortcutManagerTest() | 27 ProfileShortcutManagerTest() |
25 : file_thread_(BrowserThread::FILE, &message_loop_) { | 28 : ui_thread_(BrowserThread::UI, &message_loop_), |
29 file_thread_(BrowserThread::FILE, &message_loop_) { | |
26 } | 30 } |
27 | 31 |
28 virtual void SetUp() { | 32 virtual void SetUp() { |
29 // Create a new temporary directory, and store the path | 33 // Create a new temporary directory, and store the path |
30 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 34 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
31 } | 35 } |
32 | 36 |
33 virtual void TearDown() { | 37 virtual void TearDown() { |
34 message_loop_.RunAllPending(); | 38 message_loop_.RunAllPending(); |
35 } | 39 } |
36 | 40 |
37 // The path to temporary directory used to contain the test operations. | 41 // The path to temporary directory used to contain the test operations. |
38 ScopedTempDir temp_dir_; | 42 ScopedTempDir temp_dir_; |
39 | 43 |
40 MessageLoopForUI message_loop_; | 44 MessageLoopForUI message_loop_; |
45 content::TestBrowserThread ui_thread_; | |
41 content::TestBrowserThread file_thread_; | 46 content::TestBrowserThread file_thread_; |
42 }; | 47 }; |
43 | 48 |
44 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsIconExists) { | 49 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsIconExists) { |
50 TestingBrowserProcess* browser_process = | |
51 static_cast<TestingBrowserProcess*>(g_browser_process); | |
52 TestingProfileManager profile_manager(browser_process); | |
53 ASSERT_TRUE(profile_manager.SetUp()); | |
54 ProfileInfoCache* cache = profile_manager.profile_info_cache(); | |
55 | |
45 // Profile shortcut manager will be NULL for non-windows platforms | 56 // Profile shortcut manager will be NULL for non-windows platforms |
46 ProfileShortcutManager* profile_shortcut_manager = | 57 ProfileShortcutManager* profile_shortcut_manager = |
47 ProfileShortcutManager::Create(); | 58 ProfileShortcutManager::Create(*cache); |
48 | 59 |
49 if (!profile_shortcut_manager) | 60 if (!profile_shortcut_manager) |
50 return; | 61 return; |
51 | 62 |
52 FilePath dest_path = temp_dir_.path(); | 63 FilePath dest_path = temp_dir_.path(); |
53 string16 profile_name = ASCIIToUTF16("My Profile"); | 64 string16 profile_name = ASCIIToUTF16("My Profile"); |
54 | 65 |
55 gfx::Image& avatar = ResourceBundle::GetSharedInstance(). | 66 gfx::Image& avatar = ResourceBundle::GetSharedInstance(). |
56 GetNativeImageNamed(IDR_PROFILE_AVATAR_0); | 67 GetNativeImageNamed(IDR_PROFILE_AVATAR_0); |
57 | 68 |
58 profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path, | 69 profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path, |
59 profile_name, avatar); | 70 profile_name, avatar); |
60 | 71 |
72 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | |
73 MessageLoop::current()->Run(); | |
74 | |
61 ASSERT_TRUE(file_util::PathExists(dest_path.Append( | 75 ASSERT_TRUE(file_util::PathExists(dest_path.Append( |
62 (FILE_PATH_LITERAL("Google Profile.ico"))))); | 76 (FILE_PATH_LITERAL("Google Profile.ico"))))); |
63 | 77 |
64 profile_shortcut_manager->DeleteChromeDesktopShortcut(dest_path); | 78 profile_shortcut_manager->DeleteChromeDesktopShortcut( |
sail
2012/08/23 18:46:44
how about moving everything from this line and bel
Halli
2012/08/24 02:56:49
Done.
| |
79 dest_path, profile_name); | |
65 | 80 |
66 // TODO(hallielaine): Verify shortcut deletion | 81 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
82 MessageLoop::current()->Run(); | |
83 | |
84 FilePath exe_path; | |
85 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); | |
86 | |
87 FilePath shortcut; | |
88 string16 shortcut_name; | |
89 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
90 | |
91 // Get the desktop path of the current user | |
92 ShellUtil::GetDesktopPath(false, &shortcut); | |
93 // Get the name of the shortcut with profile attached | |
94 ShellUtil::GetChromeShortcutName(dist, false, profile_name, | |
95 &shortcut_name); | |
96 shortcut = shortcut.Append(shortcut_name); | |
97 // Verify that the shortcut cannot be found on the desktop | |
98 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_FAILURE_UNEXPECTED, | |
sail
2012/08/23 18:46:44
after creating the shortcut you check that the .ic
Halli
2012/08/24 02:56:49
Done.
| |
99 ShellUtil::VerifyChromeShortcut(exe_path.value(), | |
100 shortcut.value(), dist->GetAppDescription(), 0)); | |
67 } | 101 } |
68 | 102 |
69 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsLnk) { | 103 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsLnk) { |
104 TestingBrowserProcess* browser_process = | |
105 static_cast<TestingBrowserProcess*>(g_browser_process); | |
106 TestingProfileManager profile_manager(browser_process); | |
107 ASSERT_TRUE(profile_manager.SetUp()); | |
108 ProfileInfoCache* cache = profile_manager.profile_info_cache(); | |
109 | |
70 // Profile shortcut manager will be NULL for non-windows platforms | 110 // Profile shortcut manager will be NULL for non-windows platforms |
71 ProfileShortcutManager* profile_shortcut_manager = | 111 ProfileShortcutManager* profile_shortcut_manager = |
72 ProfileShortcutManager::Create(); | 112 ProfileShortcutManager::Create(*cache); |
73 | 113 |
74 if (!profile_shortcut_manager) | 114 if (!profile_shortcut_manager) |
75 return; | 115 return; |
76 | 116 |
117 string16 profile_name = ASCIIToUTF16("My Profile"); | |
118 | |
77 FilePath dest_path = temp_dir_.path(); | 119 FilePath dest_path = temp_dir_.path(); |
78 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1")); | 120 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1")); |
79 | 121 |
80 gfx::Image& avatar = ResourceBundle::GetSharedInstance(). | 122 gfx::Image& avatar = ResourceBundle::GetSharedInstance(). |
81 GetNativeImageNamed(IDR_PROFILE_AVATAR_0); | 123 GetNativeImageNamed(IDR_PROFILE_AVATAR_0); |
82 | 124 |
83 profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path, | 125 profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path, |
84 ASCIIToUTF16("My Profile"), avatar); | 126 profile_name, avatar); |
127 | |
128 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | |
129 MessageLoop::current()->Run(); | |
85 | 130 |
86 FilePath exe_path; | 131 FilePath exe_path; |
87 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); | 132 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); |
88 | 133 |
89 FilePath shortcut; | 134 FilePath shortcut; |
90 string16 shortcut_name; | 135 string16 shortcut_name; |
91 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 136 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
92 | 137 |
93 // Get the desktop path of the current user | 138 // Get the desktop path of the current user |
94 ShellUtil::GetDesktopPath(false, &shortcut); | 139 ShellUtil::GetDesktopPath(false, &shortcut); |
95 // Get the name of the shortcut with profile attached | 140 // Get the name of the shortcut with profile attached |
96 ShellUtil::GetChromeShortcutName(dist, false, ASCIIToUTF16("My Profile"), | 141 ShellUtil::GetChromeShortcutName(dist, false, profile_name, |
97 &shortcut_name); | 142 &shortcut_name); |
98 shortcut = shortcut.Append(shortcut_name); | 143 shortcut = shortcut.Append(shortcut_name); |
99 | 144 |
100 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, | 145 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, |
101 ShellUtil::VerifyChromeShortcut(exe_path.value(), | 146 ShellUtil::VerifyChromeShortcut(exe_path.value(), |
102 shortcut.value(), dist->GetAppDescription(), 0)); | 147 shortcut.value(), dist->GetAppDescription(), 0)); |
103 | 148 |
104 profile_shortcut_manager->DeleteChromeDesktopShortcut(dest_path); | 149 profile_shortcut_manager->DeleteChromeDesktopShortcut( |
sail
2012/08/23 18:46:44
should check that this succeeds
Halli
2012/08/24 02:56:49
Done.
| |
150 dest_path, profile_name); | |
105 } | 151 } |
152 | |
153 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsUpdate) { | |
154 TestingBrowserProcess* browser_process = | |
155 static_cast<TestingBrowserProcess*>(g_browser_process); | |
156 TestingProfileManager profile_manager(browser_process); | |
157 ASSERT_TRUE(profile_manager.SetUp()); | |
158 ProfileInfoCache* cache = profile_manager.profile_info_cache(); | |
159 | |
160 // Profile shortcut manager will be NULL for non-windows platforms | |
161 ProfileShortcutManager* profile_shortcut_manager = | |
sail
2012/08/23 18:46:44
all this code is repeated for each test. this shou
Halli
2012/08/24 02:56:49
Moving this code to SetUp() causes a problem in Pr
| |
162 ProfileShortcutManager::Create(*cache); | |
163 | |
164 if (!profile_shortcut_manager) | |
165 return; | |
166 | |
167 string16 profile_name = ASCIIToUTF16("My Profile"); | |
168 string16 new_profile_name = ASCIIToUTF16("My New Profile Name"); | |
169 | |
170 FilePath dest_path = cache->GetUserDataDir(); | |
171 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1")); | |
172 | |
173 cache->AddProfileToCache(dest_path, profile_name, string16(), 0); | |
174 | |
175 gfx::Image& avatar = ResourceBundle::GetSharedInstance(). | |
176 GetNativeImageNamed(IDR_PROFILE_AVATAR_0); | |
177 | |
178 profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path, | |
179 profile_name, avatar); | |
180 | |
181 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | |
182 MessageLoop::current()->Run(); | |
183 | |
184 // Cause an update in ProfileShortcutManager by modifying the profile info | |
185 // cache | |
186 cache->SetNameOfProfileAtIndex( | |
187 cache->GetIndexOfProfileWithPath(dest_path), new_profile_name); | |
188 | |
189 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | |
190 MessageLoop::current()->Run(); | |
191 | |
192 FilePath exe_path; | |
193 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); | |
194 | |
195 FilePath shortcut; | |
sail
2012/08/23 18:46:44
name is not descriptive, declaration should be mov
Halli
2012/08/24 02:56:49
Done.
| |
196 string16 shortcut_name; | |
sail
2012/08/23 18:46:44
same, declaration should be move to first use
Halli
2012/08/24 02:56:49
Done.
| |
197 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
198 | |
199 // Get the desktop path of the current user | |
200 ShellUtil::GetDesktopPath(false, &shortcut); | |
201 // Get the name of the shortcut with profile attached | |
202 ShellUtil::GetChromeShortcutName(dist, false, new_profile_name, | |
203 &shortcut_name); | |
204 shortcut = shortcut.Append(shortcut_name); | |
205 | |
206 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS, | |
sail
2012/08/23 18:46:44
currently this test looks like this:
<SetUp>crea
Halli
2012/08/24 02:56:49
Done.
| |
207 ShellUtil::VerifyChromeShortcut(exe_path.value(), | |
208 shortcut.value(), dist->GetAppDescription(), 0)); | |
209 | |
210 profile_shortcut_manager->DeleteChromeDesktopShortcut( | |
sail
2012/08/23 18:46:44
same as above, should check that this succeeds
Halli
2012/08/24 02:56:49
Done.
| |
211 dest_path, new_profile_name); | |
212 } | |
213 | |
OLD | NEW |