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 "chrome/browser/shell_integration.h" | |
6 | |
7 #include "base/file_path.h" | |
8 #include "base/file_util.h" | |
9 #include "base/files/scoped_temp_dir.h" | |
10 #include "base/string_number_conversions.h" | |
11 #include "base/test/test_shortcut_win.h" | |
12 #include "base/win/scoped_com_initializer.h" | |
13 #include "base/win/windows_version.h" | |
14 #include "chrome/common/chrome_constants.h" | |
15 #include "chrome/common/chrome_paths_internal.h" | |
16 #include "chrome/installer/util/browser_distribution.h" | |
17 #include "chrome/installer/util/shell_util.h" | |
18 #include "chrome/installer/util/util_constants.h" | |
19 #include "testing/gtest/include/gtest/gtest.h" | |
20 | |
21 namespace { | |
22 | |
23 class ShellIntegrationWinMigrateShortcutTest : public testing::Test { | |
24 protected: | |
25 virtual void SetUp() OVERRIDE { | |
26 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
27 | |
28 // A path to a random target. | |
29 FilePath other_target; | |
30 file_util::CreateTemporaryFile(&other_target); | |
grt (UTC plus 2)
2013/01/03 02:30:44
could these files be placed in temp_dir_ so they'r
gab
2013/01/03 21:14:57
Done.
| |
31 | |
32 // This doesn't need to actually have a base name of "chrome.exe". | |
33 file_util::CreateTemporaryFile(&chrome_exe_); | |
34 | |
35 chrome_app_id_ = | |
36 ShellUtil::GetBrowserModelId(BrowserDistribution::GetDistribution(), | |
37 true); | |
38 | |
39 // Shortcut 0 doesn't point to chrome.exe and thus should never be migrated. | |
40 shortcuts_properties_[0].set_target(other_target); | |
41 shortcuts_properties_[0].set_app_id(L"Dumbo"); | |
42 shortcuts_properties_[0].set_dual_mode(false); | |
43 | |
44 // Shortcut 1 points to chrome.exe and thus should be migrated. | |
45 shortcuts_properties_[1].set_target(chrome_exe_); | |
46 shortcuts_properties_[1].set_app_id(L"Dumbo"); | |
47 shortcuts_properties_[1].set_dual_mode(false); | |
48 | |
49 // Shortcut 2 points to chrome.exe, but already has the right appid and thus | |
50 // should only be migrated if dual_mode is desired. | |
51 shortcuts_properties_[2].set_target(chrome_exe_); | |
52 shortcuts_properties_[2].set_app_id(chrome_app_id_); | |
53 shortcuts_properties_[2].set_dual_mode(false); | |
54 | |
55 // Shortcut 3 is like shortcut 2 except it has dual_mode and thus should | |
56 // never be migrated. | |
57 shortcuts_properties_[3].set_target(chrome_exe_); | |
58 shortcuts_properties_[3].set_app_id(chrome_app_id_); | |
59 shortcuts_properties_[3].set_dual_mode(true); | |
60 | |
61 // Shortcut 4 is like shortcut 1, but it's appid is a prefix of the expected | |
62 // appid instead of being totally different. | |
63 string16 chrome_app_id_is_prefix(chrome_app_id_); | |
64 chrome_app_id_is_prefix.push_back(L'1'); | |
65 shortcuts_properties_[4].set_target(chrome_exe_); | |
66 shortcuts_properties_[4].set_app_id(chrome_app_id_is_prefix); | |
67 shortcuts_properties_[4].set_dual_mode(false); | |
68 | |
69 // Shortcut 5 is like shortcut 1, but it's appid is of the same size as the | |
70 // expected appid. | |
71 string16 same_size_as_chrome_app_id(L'1', chrome_app_id_.size()); | |
72 shortcuts_properties_[5].set_target(chrome_exe_); | |
73 shortcuts_properties_[5].set_app_id(same_size_as_chrome_app_id); | |
74 shortcuts_properties_[5].set_dual_mode(false); | |
75 | |
76 for (int i = 0; i < kNumTestShortcuts; i++) { | |
77 shortcuts_[i] = temp_dir_.path().Append(base::IntToString16(i) + | |
78 installer::kLnkExt); | |
79 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | |
80 shortcuts_[i], shortcuts_properties_[i], | |
81 base::win::SHORTCUT_CREATE_ALWAYS)); | |
82 } | |
83 } | |
84 | |
85 static const int kNumTestShortcuts = 6; | |
86 | |
87 base::win::ScopedCOMInitializer com_initializer_; | |
88 base::ScopedTempDir temp_dir_; | |
89 | |
90 // The path to a fake chrome.exe. | |
91 FilePath chrome_exe_; | |
92 | |
93 // Test shortcuts. | |
94 FilePath shortcuts_[kNumTestShortcuts]; | |
grt (UTC plus 2)
2013/01/03 02:30:44
suggest making this a vector so you don't need kNu
gab
2013/01/03 21:14:57
Done.
| |
95 | |
96 // Inititial properties for the test shortcuts. | |
97 base::win::ShortcutProperties shortcuts_properties_[kNumTestShortcuts]; | |
grt (UTC plus 2)
2013/01/03 02:30:44
vectorize this, too?
gab
2013/01/03 21:14:57
Done.
| |
98 | |
99 // This Chrome's AppUserModelId. | |
100 string16 chrome_app_id_; | |
101 }; | |
102 | |
103 } // namespace | |
104 | |
105 // Test migration when not checking for dual mode. | |
106 TEST_F(ShellIntegrationWinMigrateShortcutTest, DontCheckDualMode) { | |
107 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
108 return; | |
109 | |
110 EXPECT_EQ(3, | |
111 shell_integration::internals::MigrateShortcutsInPath( | |
112 chrome_exe_, temp_dir_.path(), false)); | |
113 | |
114 // Only shortcut 1, 4, and 5 should have been migrated. | |
115 shortcuts_properties_[1].set_app_id(chrome_app_id_); | |
116 shortcuts_properties_[4].set_app_id(chrome_app_id_); | |
117 shortcuts_properties_[5].set_app_id(chrome_app_id_); | |
118 | |
119 for (int i = 0; i < kNumTestShortcuts; i++) | |
120 base::win::ValidateShortcut(shortcuts_[i], shortcuts_properties_[i]); | |
121 } | |
122 | |
123 // Test migration when also checking for dual mode. | |
124 TEST_F(ShellIntegrationWinMigrateShortcutTest, CheckDualMode) { | |
125 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
126 return; | |
127 | |
128 EXPECT_EQ(4, | |
129 shell_integration::internals::MigrateShortcutsInPath( | |
130 chrome_exe_, temp_dir_.path(), true)); | |
131 | |
132 // Shortcut 1, 4, and 5 should have had both their app_id and dual_mode | |
133 // properties fixed and shortcut 2 should also have had it's dual_mode | |
134 // property fixed. | |
135 shortcuts_properties_[1].set_app_id(chrome_app_id_); | |
136 shortcuts_properties_[4].set_app_id(chrome_app_id_); | |
137 shortcuts_properties_[5].set_app_id(chrome_app_id_); | |
138 | |
139 shortcuts_properties_[1].set_dual_mode(true); | |
140 shortcuts_properties_[2].set_dual_mode(true); | |
141 shortcuts_properties_[4].set_dual_mode(true); | |
142 shortcuts_properties_[5].set_dual_mode(true); | |
143 | |
144 for (int i = 0; i < kNumTestShortcuts; i++) | |
145 base::win::ValidateShortcut(shortcuts_[i], shortcuts_properties_[i]); | |
146 } | |
147 | |
148 TEST(ShellIntegrationWinTest, GetAppModelIdForProfileTest) { | |
149 const string16 base_app_id( | |
150 BrowserDistribution::GetDistribution()->GetBaseAppId()); | |
151 | |
152 // Empty profile path should get chrome::kBrowserAppID | |
153 FilePath empty_path; | |
154 EXPECT_EQ(base_app_id, | |
155 ShellIntegration::GetAppModelIdForProfile(base_app_id, empty_path)); | |
156 | |
157 // Default profile path should get chrome::kBrowserAppID | |
158 FilePath default_user_data_dir; | |
159 chrome::GetDefaultUserDataDirectory(&default_user_data_dir); | |
160 FilePath default_profile_path = | |
161 default_user_data_dir.AppendASCII(chrome::kInitialProfile); | |
162 EXPECT_EQ(base_app_id, | |
163 ShellIntegration::GetAppModelIdForProfile(base_app_id, | |
164 default_profile_path)); | |
165 | |
166 // Non-default profile path should get chrome::kBrowserAppID joined with | |
167 // profile info. | |
168 FilePath profile_path(FILE_PATH_LITERAL("root")); | |
169 profile_path = profile_path.Append(FILE_PATH_LITERAL("udd")); | |
170 profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test")); | |
171 EXPECT_EQ(base_app_id + L".udd.UserDataTest", | |
172 ShellIntegration::GetAppModelIdForProfile(base_app_id, | |
173 profile_path)); | |
174 } | |
OLD | NEW |