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

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

Issue 10823217: Create/Delete windows profile 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/file_util.h"
6 #include "base/path_service.h"
7 #include "base/scoped_temp_dir.h"
8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/extensions/event_router_forwarder.h"
11 #include "chrome/browser/io_thread.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_info_cache.h"
14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/profiles/profile_shortcut_manager.h"
16 #include "chrome/installer/util/browser_distribution.h"
17 #include "chrome/installer/util/shell_util.h"
18 #include "chrome/test/base/testing_browser_process.h"
19 #include "chrome/test/base/testing_profile.h"
20 #include "content/public/test/test_browser_thread.h"
21 #include "chrome/test/base/testing_pref_service.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "ui/base/resource/resource_bundle.h"
24
25 using content::BrowserThread;
26
27 namespace {
28
29 // Profile shortcut manager for desktop shortcuts
sail 2012/08/14 18:40:41 this should just be declared inside the test direc
Halli 2012/08/14 20:38:46 Done.
30 ProfileShortcutManager* profile_shortcut_manager;
31
32 } // namespace
33
34 namespace testing {
35
36 class ProfileManager : public ::ProfileManagerWithoutInit {
sail 2012/08/14 18:40:41 you don't actually need a profile manager or a pro
Halli 2012/08/14 20:38:46 Done.
37 public:
38 explicit ProfileManager(const FilePath& user_data_dir)
39 : ::ProfileManagerWithoutInit(user_data_dir) {}
40
41 protected:
42 virtual Profile* CreateProfileHelper(const FilePath& file_path) OVERRIDE {
43 if (!file_util::PathExists(file_path)) {
44 if (!file_util::CreateDirectory(file_path))
45 return NULL;
46 }
47 return new TestingProfile(file_path, NULL);
48 }
49
50 virtual Profile* CreateProfileAsyncHelper(const FilePath& path,
51 Delegate* delegate) OVERRIDE {
52 // This is safe while all file operations are done on the FILE thread.
53 BrowserThread::PostTask(
54 BrowserThread::FILE, FROM_HERE,
55 base::Bind(base::IgnoreResult(&file_util::CreateDirectory), path));
56
57 return new TestingProfile(path, this);
58 }
59 };
60
61 } // namespace testing
62
63 class ProfileShortcutManagerTest : public testing::Test {
64 protected:
65 ProfileShortcutManagerTest()
66 : local_state_(static_cast<TestingBrowserProcess*>(g_browser_process)),
67 extension_event_router_forwarder_(
sail 2012/08/14 18:40:41 I don't think you need most of this. You probably
Halli 2012/08/14 20:38:46 Done.
68 new extensions::EventRouterForwarder),
69 ui_thread_(BrowserThread::UI, &message_loop_),
70 db_thread_(BrowserThread::DB, &message_loop_),
71 file_thread_(BrowserThread::FILE, &message_loop_),
72 io_thread_(local_state_.Get(), NULL,
73 extension_event_router_forwarder_) {
74 system_monitor_dummy_.reset(new base::SystemMonitor);
75 static_cast<TestingBrowserProcess*>(g_browser_process)->SetIOThread(
76 &io_thread_);
77 }
78
79 virtual void SetUp() {
80 // Create a new temporary directory, and store the path
81 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
82 static_cast<TestingBrowserProcess*>(g_browser_process)->SetProfileManager(
83 new testing::ProfileManager(temp_dir_.path()));
84
85 // Profile shortcut manager will be NULL for non-windows platforms
86 profile_shortcut_manager = ProfileShortcutManager::Create();
87 }
88
89 virtual void TearDown() {
90 static_cast<TestingBrowserProcess*>(g_browser_process)->SetProfileManager(
91 NULL);
92 message_loop_.RunAllPending();
93 }
94
95 // The path to temporary directory used to contain the test operations.
96 ScopedTempDir temp_dir_;
97 ScopedTestingLocalState local_state_;
98 scoped_refptr<extensions::EventRouterForwarder>
99 extension_event_router_forwarder_;
100
101 MessageLoopForUI message_loop_;
102 content::TestBrowserThread ui_thread_;
103 content::TestBrowserThread db_thread_;
104 content::TestBrowserThread file_thread_;
105 // IOThread is necessary for the creation of some services below.
106 IOThread io_thread_;
107
108 scoped_ptr<base::SystemMonitor> system_monitor_dummy_;
109 };
110
111 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsIconExists) {
112 // Profile shortcut manager will be NULL for non-windows platforms
113 ProfileShortcutManager* profile_shortcut_manager =
114 ProfileShortcutManager::Create();
115
116 if (!profile_shortcut_manager)
117 return;
118
119 FilePath dest_path = temp_dir_.path();
120 string16 profile_name = ASCIIToUTF16("My Profile");
121
122 ProfileManager* profile_manager = g_browser_process->profile_manager();
123
124 gfx::Image& avatar = ResourceBundle::GetSharedInstance().
125 GetNativeImageNamed(profile_manager->GetProfileInfoCache().
126 GetDefaultAvatarIconResourceIDAtIndex(0));
127
128 profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path,
129 profile_name, avatar);
130
131 ASSERT_TRUE(file_util::PathExists(dest_path.Append(
132 (FILE_PATH_LITERAL("Google Profile.ico")))));
133
134 profile_shortcut_manager->DeleteChromeDesktopShortcut(dest_path);
135 }
136
137 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsLnk) {
138 // Profile shortcut manager will be NULL for non-windows platforms
139 ProfileShortcutManager* profile_shortcut_manager =
140 ProfileShortcutManager::Create();
141
142 if (!profile_shortcut_manager)
143 return;
144
145 FilePath dest_path = temp_dir_.path();
146 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1"));
147
148 ProfileManager* profile_manager = g_browser_process->profile_manager();
149
150 // Successfully create the profile.
151 TestingProfile* profile =
152 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path));
153 ASSERT_TRUE(profile);
154
155 profile->SetName(ASCIIToWide("My Profile"));
156
157 gfx::Image& avatar = ResourceBundle::GetSharedInstance().
158 GetNativeImageNamed(profile_manager->GetProfileInfoCache().
159 GetDefaultAvatarIconResourceIDAtIndex(0));
160
161 profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path,
162 profile->GetName(), avatar);
163
164 FilePath exe_path;
165 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path));
166
167 FilePath shortcut;
168 string16 shortcut_name;
169 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
170
171 // Get the desktop path of the current user
172 ShellUtil::GetDesktopPath(false, &shortcut);
173 // Get the name of the shortcut with profile attached
174 ShellUtil::GetChromeShortcutName(dist, false, profile->GetName(),
175 &shortcut_name);
176 shortcut = shortcut.Append(shortcut_name);
177
178 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
179 ShellUtil::VerifyChromeShortcut(exe_path.value(),
180 shortcut.value(), dist->GetAppDescription(), 0));
181
182 profile_shortcut_manager->DeleteChromeDesktopShortcut(dest_path);
183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698