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

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/message_loop.h"
7 #include "base/path_service.h"
8 #include "base/scoped_temp_dir.h"
9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_shortcut_manager.h"
12 #include "chrome/installer/util/browser_distribution.h"
13 #include "chrome/installer/util/shell_util.h"
14 #include "content/public/test/test_browser_thread.h"
15 #include "chrome/test/base/testing_pref_service.h"
16 #include "grit/theme_resources.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/base/resource/resource_bundle.h"
19
20 using content::BrowserThread;
21
22 class ProfileShortcutManagerTest : public testing::Test {
23 protected:
24 ProfileShortcutManagerTest()
25 : file_thread_(BrowserThread::FILE, &message_loop_) {
26 }
27
28 virtual void SetUp() {
29 // Create a new temporary directory, and store the path
30 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
31 }
32
33 virtual void TearDown() {
34 message_loop_.RunAllPending();
35 }
36
37 // The path to temporary directory used to contain the test operations.
38 ScopedTempDir temp_dir_;
39
40 MessageLoopForUI message_loop_;
41 content::TestBrowserThread file_thread_;
42 };
43
44 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsIconExists) {
45 // Profile shortcut manager will be NULL for non-windows platforms
46 ProfileShortcutManager* profile_shortcut_manager =
47 ProfileShortcutManager::Create();
48
49 if (!profile_shortcut_manager)
50 return;
51
52 FilePath dest_path = temp_dir_.path();
53 string16 profile_name = ASCIIToUTF16("My Profile");
54
55 gfx::Image& avatar = ResourceBundle::GetSharedInstance().
56 GetNativeImageNamed(IDR_PROFILE_AVATAR_0);
57
58 profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path,
59 profile_name, avatar);
60
61 ASSERT_TRUE(file_util::PathExists(dest_path.Append(
62 (FILE_PATH_LITERAL("Google Profile.ico")))));
63
64 profile_shortcut_manager->DeleteChromeDesktopShortcut(dest_path);
sail 2012/08/14 20:53:17 maybe add a TODO to verify deletion?
Halli 2012/08/14 21:24:19 Done.
65 }
66
67 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsLnk) {
68 // Profile shortcut manager will be NULL for non-windows platforms
69 ProfileShortcutManager* profile_shortcut_manager =
70 ProfileShortcutManager::Create();
71
72 if (!profile_shortcut_manager)
73 return;
74
75 FilePath dest_path = temp_dir_.path();
76 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile 1"));
77
78 gfx::Image& avatar = ResourceBundle::GetSharedInstance().
79 GetNativeImageNamed(IDR_PROFILE_AVATAR_0);
80
81 profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path,
82 ASCIIToUTF16("My Profile"), avatar);
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, ASCIIToUTF16("My Profile"),
95 &shortcut_name);
96 shortcut = shortcut.Append(shortcut_name);
97
98 EXPECT_EQ(ShellUtil::VERIFY_SHORTCUT_SUCCESS,
99 ShellUtil::VerifyChromeShortcut(exe_path.value(),
100 shortcut.value(), dist->GetAppDescription(), 0));
sail 2012/08/14 20:53:17 this should be indented 4 spaces
Halli 2012/08/14 21:24:19 Done.
101
102 profile_shortcut_manager->DeleteChromeDesktopShortcut(dest_path);
103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698