OLD | NEW |
(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 "chrome/test/base/testing_pref_service.h" |
| 15 #include "content/public/test/test_browser_thread.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); |
| 65 |
| 66 // TODO(hallielaine): Verify shortcut deletion |
| 67 } |
| 68 |
| 69 TEST_F(ProfileShortcutManagerTest, DesktopShortcutsLnk) { |
| 70 // Profile shortcut manager will be NULL for non-windows platforms |
| 71 ProfileShortcutManager* profile_shortcut_manager = |
| 72 ProfileShortcutManager::Create(); |
| 73 |
| 74 if (!profile_shortcut_manager) |
| 75 return; |
| 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(). |
| 81 GetNativeImageNamed(IDR_PROFILE_AVATAR_0); |
| 82 |
| 83 profile_shortcut_manager->CreateChromeDesktopShortcut(dest_path, |
| 84 ASCIIToUTF16("My Profile"), avatar); |
| 85 |
| 86 FilePath exe_path; |
| 87 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); |
| 88 |
| 89 FilePath shortcut; |
| 90 string16 shortcut_name; |
| 91 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 92 |
| 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 } |
OLD | NEW |