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

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/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"
15 #include "chrome/test/base/testing_browser_process.h"
14 #include "chrome/test/base/testing_pref_service.h" 16 #include "chrome/test/base/testing_pref_service.h"
17 #include "chrome/test/base/testing_profile.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 IsShortcutForProfile(const string16& profile_name) {
sail 2012/08/24 04:32:26 maybe ProfileShortcutExists or DoesProfileShortcut
Halli 2012/08/24 17:23:56 Done.
28 FilePath exe_path;
29 DCHECK(PathService::Get(base::FILE_EXE, &exe_path));
30
31 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
32
33 // 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.
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 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.
43 ShellUtil::VerifyChromeShortcut(
44 exe_path.value(), shortcut_path.value(), dist->GetAppDescription(),
45 0))
46 return true;
47 return false;
48 }
49
50 } // namespace
51
22 class ProfileShortcutManagerTest : public testing::Test { 52 class ProfileShortcutManagerTest : public testing::Test {
23 protected: 53 protected:
24 ProfileShortcutManagerTest() 54 ProfileShortcutManagerTest()
25 : file_thread_(BrowserThread::FILE, &message_loop_) { 55 : ui_thread_(BrowserThread::UI, &message_loop_),
56 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.
26 } 57 }
27 58
28 virtual void SetUp() { 59 virtual void SetUp() {
29 // Create a new temporary directory, and store the path 60 // Create a new temporary directory, and store the path
30 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 61 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
62
63 TestingBrowserProcess* browser_process =
64 static_cast<TestingBrowserProcess*>(g_browser_process);
65 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.
66 ASSERT_TRUE(profile_manager.SetUp());
67 cache_ = profile_manager.profile_info_cache();
68 // Profile shortcut manager will be NULL for non-windows platforms
69 profile_shortcut_manager_ = ProfileShortcutManager::Create(*cache_);
31 } 70 }
32 71
33 virtual void TearDown() { 72 virtual void TearDown() {
34 message_loop_.RunAllPending(); 73 message_loop_.RunAllPending();
35 } 74 }
36 75
37 // The path to temporary directory used to contain the test operations. 76 // The path to temporary directory used to contain the test operations.
38 ScopedTempDir temp_dir_; 77 ScopedTempDir temp_dir_;
39 78
40 MessageLoopForUI message_loop_; 79 MessageLoopForUI message_loop_;
80 content::TestBrowserThread ui_thread_;
41 content::TestBrowserThread file_thread_; 81 content::TestBrowserThread file_thread_;
82 ProfileInfoCache* cache_;
83 ProfileShortcutManager* profile_shortcut_manager_;
42 }; 84 };
43 85
44 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsIconExists) { 86 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) {
45 // Profile shortcut manager will be NULL for non-windows platforms 87 if (!profile_shortcut_manager_)
46 ProfileShortcutManager* profile_shortcut_manager = 88 return;
47 ProfileShortcutManager::Create(); 89 FilePath dest_path = temp_dir_.path();
90 string16 profile_name = ASCIIToUTF16("My profile");
48 91
49 if (!profile_shortcut_manager) 92 EXPECT_FALSE(IsShortcutForProfile(profile_name));
50 return; 93 ASSERT_FALSE(file_util::PathExists(dest_path.Append(
51 94 (FILE_PATH_LITERAL("Google Profile.ico")))));
52 FilePath dest_path = temp_dir_.path();
53 string16 profile_name = ASCIIToUTF16("My Profile");
54 95
55 gfx::Image& avatar = ResourceBundle::GetSharedInstance(). 96 gfx::Image& avatar = ResourceBundle::GetSharedInstance().
56 GetNativeImageNamed(IDR_PROFILE_AVATAR_0); 97 GetNativeImageNamed(IDR_PROFILE_AVATAR_0);
57 98
58 profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path, 99 profile_shortcut_manager_->StartProfileDesktopShortcutCreation(
59 profile_name, avatar); 100 dest_path, profile_name, avatar);
101 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
102 MessageLoop::current()->Run();
60 103
104 EXPECT_TRUE(IsShortcutForProfile(profile_name));
61 ASSERT_TRUE(file_util::PathExists(dest_path.Append( 105 ASSERT_TRUE(file_util::PathExists(dest_path.Append(
62 (FILE_PATH_LITERAL("Google Profile.ico"))))); 106 (FILE_PATH_LITERAL("Google Profile.ico")))));
63 107
64 profile_shortcut_manager->DeleteChromeDesktopShortcut(dest_path); 108 profile_shortcut_manager_->DeleteProfileDesktopShortcut(
65 109 dest_path, profile_name);
66 // TODO(hallielaine): Verify shortcut deletion 110 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
111 MessageLoop::current()->Run();
112 EXPECT_FALSE(IsShortcutForProfile(profile_name));
113 ASSERT_FALSE(file_util::PathExists(dest_path.Append(
114 (FILE_PATH_LITERAL("Google Profile.ico")))));
67 } 115 }
68 116
69 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsLnk) { 117 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsUpdate) {
70 // Profile shortcut manager will be NULL for non-windows platforms 118 if (!profile_shortcut_manager_)
71 ProfileShortcutManager* profile_shortcut_manager = 119 return;
72 ProfileShortcutManager::Create(); 120 string16 profile_name = ASCIIToUTF16("My profile");
121 EXPECT_FALSE(IsShortcutForProfile(profile_name));
73 122
74 if (!profile_shortcut_manager) 123 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.
75 return; 124 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
76
77 FilePath dest_path = temp_dir_.path();
78 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1")); 125 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1"));
79 126
127 cache_->AddProfileToCache(dest_path, profile_name, string16(), 0);
80 gfx::Image& avatar = ResourceBundle::GetSharedInstance(). 128 gfx::Image& avatar = ResourceBundle::GetSharedInstance().
81 GetNativeImageNamed(IDR_PROFILE_AVATAR_0); 129 GetNativeImageNamed(IDR_PROFILE_AVATAR_0);
82 130
83 profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path, 131 profile_shortcut_manager_->StartProfileDesktopShortcutCreation(
84 ASCIIToUTF16("My Profile"), avatar); 132 dest_path, profile_name, avatar);
133 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
134 MessageLoop::current()->Run();
135 EXPECT_TRUE(IsShortcutForProfile(profile_name));
136 EXPECT_FALSE(IsShortcutForProfile(new_profile_name));
85 137
86 FilePath exe_path; 138 // Cause an update in ProfileShortcutManager by modifying the profile info
87 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); 139 // cache
140 cache_->SetNameOfProfileAtIndex(
141 cache_->GetIndexOfProfileWithPath(dest_path), new_profile_name);
142 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
143 MessageLoop::current()->Run();
144 EXPECT_FALSE(IsShortcutForProfile(profile_name));
145 EXPECT_TRUE(IsShortcutForProfile(new_profile_name));
88 146
89 FilePath shortcut; 147 profile_shortcut_manager_->DeleteProfileDesktopShortcut(
90 string16 shortcut_name; 148 dest_path, new_profile_name);
91 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 149 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
150 MessageLoop::current()->Run();
151 EXPECT_FALSE(IsShortcutForProfile(profile_name));
152 EXPECT_FALSE(IsShortcutForProfile(new_profile_name));
153 }
92 154
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