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

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, 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
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 ShellUtil::VerifyShortcutStatus VerifyProfileShortcut(
28 const string16& profile_name) {
29 FilePath exe_path;
30 CHECK(PathService::Get(base::FILE_EXE, &exe_path));
31
32 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
33
34 // Get the desktop path of the current user.
35 FilePath shortcut_path;
36 ShellUtil::GetDesktopPath(false, &shortcut_path);
37 // Get the name of the shortcut with profile attached
38 string16 shortcut_name;
39 ShellUtil::GetChromeShortcutName(dist, false, profile_name,
40 &shortcut_name);
41 shortcut_path = shortcut_path.Append(shortcut_name);
42
43 return ShellUtil::VerifyChromeShortcut(
44 exe_path.value(), shortcut_path.value(), dist->GetAppDescription(),
45 0);
46 }
47
48 } // namespace
49
22 class ProfileShortcutManagerTest : public testing::Test { 50 class ProfileShortcutManagerTest : public testing::Test {
23 protected: 51 protected:
24 ProfileShortcutManagerTest() 52 ProfileShortcutManagerTest()
25 : file_thread_(BrowserThread::FILE, &message_loop_) { 53 : ui_thread_(BrowserThread::UI, &message_loop_),
54 file_thread_(BrowserThread::FILE, &message_loop_) {
26 } 55 }
27 56
28 virtual void SetUp() { 57 virtual void SetUp() {
29 // Create a new temporary directory, and store the path 58 TestingBrowserProcess* browser_process =
30 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 59 static_cast<TestingBrowserProcess*>(g_browser_process);
60 profile_manager_.reset(new TestingProfileManager(browser_process));
61 ASSERT_TRUE(profile_manager_->SetUp());
62 ProfileInfoCache* cache = profile_manager_->profile_info_cache();
63 // Profile shortcut manager will be NULL for non-windows platforms
64 profile_shortcut_manager_.reset(ProfileShortcutManager::Create(*cache));
65
66 dest_path_ = profile_manager_->profile_info_cache()->GetUserDataDir();
67 dest_path_ = dest_path_.Append(FILE_PATH_LITERAL("New Profile 1"));
68 file_util::CreateDirectoryW(dest_path_);
69 profile_name_ = ASCIIToUTF16("My profile");
31 } 70 }
32 71
33 virtual void TearDown() { 72 virtual void TearDown() {
34 message_loop_.RunAllPending(); 73 message_loop_.RunAllPending();
74 profile_shortcut_manager_->DeleteProfileDesktopShortcut(
75 dest_path_, profile_name_);
76 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
77 MessageLoop::current()->Run();
78 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_FAILURE_UNEXPECTED,
gab 2012/08/24 20:27:02 Hmmm that makes me think we probably want a VERIFY
79 VerifyProfileShortcut(profile_name_));
80 ASSERT_FALSE(file_util::PathExists(dest_path_.Append(
81 FILE_PATH_LITERAL("Google Profile.ico"))));
35 } 82 }
36 83
37 // The path to temporary directory used to contain the test operations.
38 ScopedTempDir temp_dir_;
39
40 MessageLoopForUI message_loop_; 84 MessageLoopForUI message_loop_;
85 content::TestBrowserThread ui_thread_;
41 content::TestBrowserThread file_thread_; 86 content::TestBrowserThread file_thread_;
87 scoped_ptr<TestingProfileManager> profile_manager_;
88 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_;
89 FilePath dest_path_;
90 string16 profile_name_;
42 }; 91 };
43 92
44 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsIconExists) { 93 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsCreate) {
45 // Profile shortcut manager will be NULL for non-windows platforms 94 if (!profile_shortcut_manager_.get())
46 ProfileShortcutManager* profile_shortcut_manager =
47 ProfileShortcutManager::Create();
48
49 if (!profile_shortcut_manager)
50 return; 95 return;
51 96 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_FAILURE_UNEXPECTED,
52 FilePath dest_path = temp_dir_.path(); 97 VerifyProfileShortcut(profile_name_));
53 string16 profile_name = ASCIIToUTF16("My Profile"); 98 ASSERT_FALSE(file_util::PathExists(dest_path_.Append(
99 FILE_PATH_LITERAL("Google Profile.ico"))));
54 100
55 gfx::Image& avatar = ResourceBundle::GetSharedInstance(). 101 gfx::Image& avatar = ResourceBundle::GetSharedInstance().
56 GetNativeImageNamed(IDR_PROFILE_AVATAR_0); 102 GetNativeImageNamed(IDR_PROFILE_AVATAR_0);
57 103
58 profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path, 104 profile_shortcut_manager_->StartProfileDesktopShortcutCreation(
59 profile_name, avatar); 105 dest_path_, profile_name_, avatar);
106 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
107 MessageLoop::current()->Run();
60 108
61 ASSERT_TRUE(file_util::PathExists(dest_path.Append( 109 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
62 (FILE_PATH_LITERAL("Google Profile.ico"))))); 110 VerifyProfileShortcut(profile_name_));
63 111 ASSERT_TRUE(file_util::PathExists(dest_path_.Append(
64 profile_shortcut_manager->DeleteChromeDesktopShortcut(dest_path); 112 FILE_PATH_LITERAL("Google Profile.ico"))));
65
66 // TODO(hallielaine): Verify shortcut deletion
67 } 113 }
68 114
69 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsLnk) { 115 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsUpdate) {
70 // Profile shortcut manager will be NULL for non-windows platforms 116 if (!profile_shortcut_manager_.get())
71 ProfileShortcutManager* profile_shortcut_manager = 117 return;
72 ProfileShortcutManager::Create(); 118 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_FAILURE_UNEXPECTED,
119 VerifyProfileShortcut(profile_name_));
73 120
74 if (!profile_shortcut_manager) 121 profile_manager_->profile_info_cache()->AddProfileToCache(
75 return; 122 dest_path_, profile_name_, string16(), 0);
76
77 FilePath dest_path = temp_dir_.path();
78 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1"));
79
80 gfx::Image& avatar = ResourceBundle::GetSharedInstance(). 123 gfx::Image& avatar = ResourceBundle::GetSharedInstance().
81 GetNativeImageNamed(IDR_PROFILE_AVATAR_0); 124 GetNativeImageNamed(IDR_PROFILE_AVATAR_0);
82 125
83 profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path, 126 profile_shortcut_manager_->StartProfileDesktopShortcutCreation(
84 ASCIIToUTF16("My Profile"), avatar); 127 dest_path_, profile_name_, avatar);
128 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
129 MessageLoop::current()->Run();
130 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
131 VerifyProfileShortcut(profile_name_));
132 string16 new_profile_name = ASCIIToUTF16("My New Profile Name");
133 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_FAILURE_UNEXPECTED,
134 VerifyProfileShortcut(new_profile_name));
85 135
86 FilePath exe_path; 136 // Cause an update in ProfileShortcutManager by modifying the profile info
87 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); 137 // cache
138 profile_manager_->profile_info_cache()->SetNameOfProfileAtIndex(
139 profile_manager_->profile_info_cache()->GetIndexOfProfileWithPath(
140 dest_path_), new_profile_name);
141 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
142 MessageLoop::current()->Run();
143 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_FAILURE_UNEXPECTED,
144 VerifyProfileShortcut(profile_name_));
145 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
146 VerifyProfileShortcut(new_profile_name));
88 147
89 FilePath shortcut; 148 profile_name_ = new_profile_name;
90 string16 shortcut_name; 149 }
91 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
92 150
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_stub.cc ('k') | chrome/browser/profiles/profile_shortcut_manager_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698