OLD | NEW |
---|---|
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 "chrome/browser/shell_integration.h" | 5 #include "chrome/browser/shell_integration.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 protected: | 26 protected: |
27 virtual void SetUp() OVERRIDE { | 27 virtual void SetUp() OVERRIDE { |
28 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 28 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
29 | 29 |
30 // A path to a random target. | 30 // A path to a random target. |
31 base::FilePath other_target; | 31 base::FilePath other_target; |
32 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &other_target); | 32 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &other_target); |
33 | 33 |
34 // This doesn't need to actually have a base name of "chrome.exe". | 34 // This doesn't need to actually have a base name of "chrome.exe". |
35 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &chrome_exe_); | 35 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &chrome_exe_); |
36 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &app_host_exe_); | |
36 | 37 |
37 chrome_app_id_ = | 38 chrome_app_id_ = |
38 ShellUtil::GetBrowserModelId(BrowserDistribution::GetDistribution(), | 39 ShellUtil::GetBrowserModelId(BrowserDistribution::GetDistribution(), |
39 true); | 40 true); |
40 | 41 |
42 base::FilePath default_user_data_dir; | |
43 chrome::GetDefaultUserDataDirectory(&default_user_data_dir); | |
44 base::FilePath default_profile_path = | |
45 default_user_data_dir.AppendASCII(chrome::kInitialProfile); | |
46 app_list_app_id_ = | |
47 ShellIntegration::GetAppListAppModelIdForProfile(default_profile_path); | |
48 non_default_profile_ = string16(L"NonDefault"); | |
49 non_default_chrome_app_id_ = | |
50 ShellIntegration::GetChromiumModelIdForProfile( | |
51 default_user_data_dir.Append(non_default_profile_)); | |
52 | |
41 // A temporary object to pass properties to AddTestShortcut(). | 53 // A temporary object to pass properties to AddTestShortcut(). |
42 base::win::ShortcutProperties temp_properties; | 54 base::win::ShortcutProperties temp_properties; |
43 | 55 |
44 // Shortcut 0 doesn't point to chrome.exe and thus should never be migrated. | 56 // Shortcut 0 doesn't point to chrome.exe and thus should never be migrated. |
45 temp_properties.set_target(other_target); | 57 temp_properties.set_target(other_target); |
46 temp_properties.set_app_id(L"Dumbo"); | 58 temp_properties.set_app_id(L"Dumbo"); |
47 temp_properties.set_dual_mode(false); | 59 temp_properties.set_dual_mode(false); |
48 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties)); | 60 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties)); |
49 | 61 |
50 // Shortcut 1 points to chrome.exe and thus should be migrated. | 62 // Shortcut 1 points to chrome.exe and thus should be migrated. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 temp_properties.set_target(chrome_exe_); | 94 temp_properties.set_target(chrome_exe_); |
83 temp_properties.set_app_id(same_size_as_chrome_app_id); | 95 temp_properties.set_app_id(same_size_as_chrome_app_id); |
84 temp_properties.set_dual_mode(false); | 96 temp_properties.set_dual_mode(false); |
85 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties)); | 97 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties)); |
86 | 98 |
87 // Shortcut 6 doesn't have an app_id, nor is dual_mode even set; they should | 99 // Shortcut 6 doesn't have an app_id, nor is dual_mode even set; they should |
88 // be set as expected upon migration. | 100 // be set as expected upon migration. |
89 base::win::ShortcutProperties no_properties; | 101 base::win::ShortcutProperties no_properties; |
90 no_properties.set_target(chrome_exe_); | 102 no_properties.set_target(chrome_exe_); |
91 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(no_properties)); | 103 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(no_properties)); |
104 | |
105 // Shortcut 7 tests that a non-default profile directory gets a non-default | |
koz (OOO until 15th September)
2013/04/18 02:06:08
nit: the above comments describe the shortcut, as
calamity
2013/04/18 08:24:34
Done.
| |
106 // app id. | |
107 temp_properties.set_target(chrome_exe_); | |
108 temp_properties.set_app_id(L"Dumbo"); | |
109 temp_properties.set_arguments( | |
110 string16(L"--profile-directory=") + non_default_profile_); | |
111 temp_properties.set_dual_mode(false); | |
112 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties)); | |
113 | |
114 // TODO(calamity): remove this test once app_host.exe is removed | |
115 // Shortcut 8 tests that app_host.exe shortcuts are migrated to chrome.exe | |
koz (OOO until 15th September)
2013/04/18 02:06:08
// Shortcut 8 points to app_host.exe and should be
calamity
2013/04/18 08:24:34
Done.
| |
116 // shortcuts. | |
117 temp_properties.set_target(app_host_exe_); | |
118 temp_properties.set_app_id(L"SomeAppId"); | |
119 temp_properties.set_arguments(L"--show-app-list"); | |
120 temp_properties.set_dual_mode(false); | |
121 ASSERT_NO_FATAL_FAILURE(AddTestShortcut(temp_properties)); | |
92 } | 122 } |
93 | 123 |
94 void AddTestShortcut( | 124 void AddTestShortcut( |
95 const base::win::ShortcutProperties& shortcut_properties) { | 125 const base::win::ShortcutProperties& shortcut_properties) { |
96 shortcuts_properties_.push_back(shortcut_properties); | 126 shortcuts_properties_.push_back(shortcut_properties); |
97 base::FilePath shortcut_path = | 127 base::FilePath shortcut_path = |
98 temp_dir_.path().Append(L"Shortcut " + | 128 temp_dir_.path().Append(L"Shortcut " + |
99 base::IntToString16(shortcuts_.size()) + | 129 base::IntToString16(shortcuts_.size()) + |
100 installer::kLnkExt); | 130 installer::kLnkExt); |
101 shortcuts_.push_back(shortcut_path); | 131 shortcuts_.push_back(shortcut_path); |
102 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 132 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
103 shortcut_path, shortcut_properties, | 133 shortcut_path, shortcut_properties, |
104 base::win::SHORTCUT_CREATE_ALWAYS)); | 134 base::win::SHORTCUT_CREATE_ALWAYS)); |
105 } | 135 } |
106 | 136 |
107 base::win::ScopedCOMInitializer com_initializer_; | 137 base::win::ScopedCOMInitializer com_initializer_; |
108 base::ScopedTempDir temp_dir_; | 138 base::ScopedTempDir temp_dir_; |
109 | 139 |
110 // The path to a fake chrome.exe. | 140 // The path to a fake chrome.exe. |
111 base::FilePath chrome_exe_; | 141 base::FilePath chrome_exe_; |
112 | 142 |
143 // The path to a fake app_host.exe. | |
144 base::FilePath app_host_exe_; | |
145 | |
113 // Test shortcuts. | 146 // Test shortcuts. |
114 std::vector<base::FilePath> shortcuts_; | 147 std::vector<base::FilePath> shortcuts_; |
115 | 148 |
116 // Initial properties for the test shortcuts. | 149 // Initial properties for the test shortcuts. |
117 std::vector<base::win::ShortcutProperties> shortcuts_properties_; | 150 std::vector<base::win::ShortcutProperties> shortcuts_properties_; |
118 | 151 |
119 // Chrome's AppUserModelId. | 152 // Chrome's AppUserModelId. |
120 string16 chrome_app_id_; | 153 string16 chrome_app_id_; |
154 | |
155 // A profile that isn't the Default profile. | |
156 string16 non_default_profile_; | |
157 | |
158 // Chrome's AppUserModelId for the non-default profile. | |
159 string16 non_default_chrome_app_id_; | |
160 | |
161 // The app launcher's app id. | |
162 string16 app_list_app_id_; | |
121 }; | 163 }; |
122 | 164 |
123 } // namespace | 165 } // namespace |
124 | 166 |
125 // Test migration when not checking for dual mode. | 167 // Test migration when not checking for dual mode. |
126 TEST_F(ShellIntegrationWinMigrateShortcutTest, DontCheckDualMode) { | 168 TEST_F(ShellIntegrationWinMigrateShortcutTest, DontCheckDualMode) { |
127 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 169 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
128 return; | 170 return; |
129 | 171 |
130 EXPECT_EQ(4, | 172 EXPECT_EQ(6, |
131 ShellIntegration::MigrateShortcutsInPathInternal( | 173 ShellIntegration::MigrateShortcutsInPathInternal( |
132 chrome_exe_, temp_dir_.path(), false)); | 174 chrome_exe_, app_host_exe_, temp_dir_.path(), false, false)); |
133 | 175 |
134 // Only shortcut 1, 4, 5, and 6 should have been migrated. | 176 // Only shortcut 1, 4, 5, 6, 7 and 8 should have been migrated. |
135 shortcuts_properties_[1].set_app_id(chrome_app_id_); | 177 shortcuts_properties_[1].set_app_id(chrome_app_id_); |
136 shortcuts_properties_[4].set_app_id(chrome_app_id_); | 178 shortcuts_properties_[4].set_app_id(chrome_app_id_); |
137 shortcuts_properties_[5].set_app_id(chrome_app_id_); | 179 shortcuts_properties_[5].set_app_id(chrome_app_id_); |
138 shortcuts_properties_[6].set_app_id(chrome_app_id_); | 180 shortcuts_properties_[6].set_app_id(chrome_app_id_); |
181 shortcuts_properties_[7].set_app_id(non_default_chrome_app_id_); | |
182 // app_host.exe should now be chrome.exe | |
183 shortcuts_properties_[8].set_target(chrome_exe_); | |
184 shortcuts_properties_[8].set_app_id(app_list_app_id_); | |
139 | 185 |
140 for (size_t i = 0; i < shortcuts_.size(); ++i) | 186 for (size_t i = 0; i < shortcuts_.size(); ++i) |
141 base::win::ValidateShortcut(shortcuts_[i], shortcuts_properties_[i]); | 187 base::win::ValidateShortcut(shortcuts_[i], shortcuts_properties_[i]); |
142 } | 188 } |
143 | 189 |
144 // Test migration when also checking for dual mode. | 190 // Test migration when also checking for dual mode. |
145 TEST_F(ShellIntegrationWinMigrateShortcutTest, CheckDualMode) { | 191 TEST_F(ShellIntegrationWinMigrateShortcutTest, CheckDualMode) { |
146 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 192 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
147 return; | 193 return; |
148 | 194 |
149 EXPECT_EQ(5, | 195 EXPECT_EQ(7, |
150 ShellIntegration::MigrateShortcutsInPathInternal( | 196 ShellIntegration::MigrateShortcutsInPathInternal( |
151 chrome_exe_, temp_dir_.path(), true)); | 197 chrome_exe_, app_host_exe_, temp_dir_.path(), true, false)); |
152 | 198 |
153 // Shortcut 1, 4, 5, and 6 should have had both their app_id and dual_mode | 199 // Shortcut 1, 4, 5, 6, 7 and 8 should have had both their app_id and |
154 // properties fixed and shortcut 2 should also have had it's dual_mode | 200 // dual_mode properties fixed and shortcut 2 should also have had it's |
155 // property fixed. | 201 // dual_mode property fixed. |
156 shortcuts_properties_[1].set_app_id(chrome_app_id_); | 202 shortcuts_properties_[1].set_app_id(chrome_app_id_); |
157 shortcuts_properties_[4].set_app_id(chrome_app_id_); | 203 shortcuts_properties_[4].set_app_id(chrome_app_id_); |
158 shortcuts_properties_[5].set_app_id(chrome_app_id_); | 204 shortcuts_properties_[5].set_app_id(chrome_app_id_); |
159 shortcuts_properties_[6].set_app_id(chrome_app_id_); | 205 shortcuts_properties_[6].set_app_id(chrome_app_id_); |
206 shortcuts_properties_[7].set_app_id(non_default_chrome_app_id_); | |
207 // app_host.exe should now be chrome.exe | |
208 shortcuts_properties_[8].set_target(chrome_exe_); | |
209 shortcuts_properties_[8].set_app_id(app_list_app_id_); | |
160 | 210 |
161 shortcuts_properties_[1].set_dual_mode(true); | 211 shortcuts_properties_[1].set_dual_mode(true); |
162 shortcuts_properties_[2].set_dual_mode(true); | 212 shortcuts_properties_[2].set_dual_mode(true); |
163 shortcuts_properties_[4].set_dual_mode(true); | 213 shortcuts_properties_[4].set_dual_mode(true); |
164 shortcuts_properties_[5].set_dual_mode(true); | 214 shortcuts_properties_[5].set_dual_mode(true); |
165 shortcuts_properties_[6].set_dual_mode(true); | 215 shortcuts_properties_[6].set_dual_mode(true); |
216 shortcuts_properties_[7].set_dual_mode(true); | |
217 shortcuts_properties_[8].set_dual_mode(true); | |
166 | 218 |
167 for (size_t i = 0; i < shortcuts_.size(); ++i) | 219 for (size_t i = 0; i < shortcuts_.size(); ++i) |
168 base::win::ValidateShortcut(shortcuts_[i], shortcuts_properties_[i]); | 220 base::win::ValidateShortcut(shortcuts_[i], shortcuts_properties_[i]); |
169 } | 221 } |
170 | 222 |
171 TEST(ShellIntegrationWinTest, GetAppModelIdForProfileTest) { | 223 TEST(ShellIntegrationWinTest, GetAppModelIdForProfileTest) { |
172 const string16 base_app_id( | 224 const string16 base_app_id( |
173 BrowserDistribution::GetDistribution()->GetBaseAppId()); | 225 BrowserDistribution::GetDistribution()->GetBaseAppId()); |
174 | 226 |
175 // Empty profile path should get chrome::kBrowserAppID | 227 // Empty profile path should get chrome::kBrowserAppID |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 default_profile_path)); | 267 default_profile_path)); |
216 | 268 |
217 // Non-default profile path should get chrome::kBrowserAppID + AppList joined | 269 // Non-default profile path should get chrome::kBrowserAppID + AppList joined |
218 // with profile info. | 270 // with profile info. |
219 base::FilePath profile_path(FILE_PATH_LITERAL("root")); | 271 base::FilePath profile_path(FILE_PATH_LITERAL("root")); |
220 profile_path = profile_path.Append(FILE_PATH_LITERAL("udd")); | 272 profile_path = profile_path.Append(FILE_PATH_LITERAL("udd")); |
221 profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test")); | 273 profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test")); |
222 EXPECT_EQ(base_app_id + L".udd.UserDataTest", | 274 EXPECT_EQ(base_app_id + L".udd.UserDataTest", |
223 ShellIntegration::GetAppListAppModelIdForProfile(profile_path)); | 275 ShellIntegration::GetAppListAppModelIdForProfile(profile_path)); |
224 } | 276 } |
OLD | NEW |