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

Side by Side Diff: chrome/installer/setup/install_unittest.cc

Issue 1289333005: Change shortcut install location to non-subdir. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move shortcut instead of delete/create Created 5 years, 2 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 <objbase.h> 5 #include <objbase.h>
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 installer::kLnkExt); 119 installer::kLnkExt);
120 base::string16 alternate_shortcut_name( 120 base::string16 alternate_shortcut_name(
121 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME_ALTERNATE) + 121 dist_->GetShortcutName(BrowserDistribution::SHORTCUT_CHROME_ALTERNATE) +
122 installer::kLnkExt); 122 installer::kLnkExt);
123 123
124 user_desktop_shortcut_ = 124 user_desktop_shortcut_ =
125 fake_user_desktop_.path().Append(shortcut_name); 125 fake_user_desktop_.path().Append(shortcut_name);
126 user_quick_launch_shortcut_ = 126 user_quick_launch_shortcut_ =
127 fake_user_quick_launch_.path().Append(shortcut_name); 127 fake_user_quick_launch_.path().Append(shortcut_name);
128 user_start_menu_shortcut_ = 128 user_start_menu_shortcut_ =
129 fake_start_menu_.path().Append(shortcut_name);
130 user_start_menu_subdir_shortcut_ =
129 fake_start_menu_.path().Append( 131 fake_start_menu_.path().Append(
130 dist_->GetStartMenuShortcutSubfolder( 132 dist_->GetStartMenuShortcutSubfolder(
131 BrowserDistribution::SUBFOLDER_CHROME)) 133 BrowserDistribution::SUBFOLDER_CHROME))
132 .Append(shortcut_name); 134 .Append(shortcut_name);
133 system_desktop_shortcut_ = 135 system_desktop_shortcut_ =
134 fake_common_desktop_.path().Append(shortcut_name); 136 fake_common_desktop_.path().Append(shortcut_name);
135 system_start_menu_shortcut_ = 137 system_start_menu_shortcut_ =
136 fake_common_start_menu_.path().Append( 138 fake_common_start_menu_.path().Append(shortcut_name);
137 dist_->GetStartMenuShortcutSubfolder(
138 BrowserDistribution::SUBFOLDER_CHROME))
139 .Append(shortcut_name);
140 user_alternate_desktop_shortcut_ = 139 user_alternate_desktop_shortcut_ =
141 fake_user_desktop_.path().Append(alternate_shortcut_name); 140 fake_user_desktop_.path().Append(alternate_shortcut_name);
142 } 141 }
143 142
144 void TearDown() override { 143 void TearDown() override {
145 // Try to unpin potentially pinned shortcuts (although pinning isn't tested, 144 // Try to unpin potentially pinned shortcuts (although pinning isn't tested,
146 // the call itself might still have pinned the Start Menu shortcuts). 145 // the call itself might still have pinned the Start Menu shortcuts).
147 base::win::UnpinShortcutFromTaskbar(user_start_menu_shortcut_); 146 base::win::UnpinShortcutFromTaskbar(user_start_menu_shortcut_);
148 base::win::UnpinShortcutFromTaskbar(system_start_menu_shortcut_); 147 base::win::UnpinShortcutFromTaskbar(system_start_menu_shortcut_);
149 base::win::UnpinShortcutFromStart(user_start_menu_shortcut_); 148 base::win::UnpinShortcutFromStart(user_start_menu_shortcut_);
149 base::win::UnpinShortcutFromStart(user_start_menu_subdir_shortcut_);
150 base::win::UnpinShortcutFromStart(system_start_menu_shortcut_); 150 base::win::UnpinShortcutFromStart(system_start_menu_shortcut_);
151 CoUninitialize(); 151 CoUninitialize();
152 } 152 }
153 153
154 installer::MasterPreferences* GetFakeMasterPrefs( 154 installer::MasterPreferences* GetFakeMasterPrefs(
155 bool do_not_create_desktop_shortcut, 155 bool do_not_create_desktop_shortcut,
156 bool do_not_create_quick_launch_shortcut, 156 bool do_not_create_quick_launch_shortcut,
157 bool alternate_desktop_shortcut) { 157 bool alternate_desktop_shortcut) {
158 const struct { 158 const struct {
159 const char* pref_name; 159 const char* pref_name;
(...skipping 12 matching lines...) Expand all
172 master_prefs += (i == 0 ? "\"" : ",\""); 172 master_prefs += (i == 0 ? "\"" : ",\"");
173 master_prefs += desired_prefs[i].pref_name; 173 master_prefs += desired_prefs[i].pref_name;
174 master_prefs += "\":"; 174 master_prefs += "\":";
175 master_prefs += desired_prefs[i].is_desired ? "true" : "false"; 175 master_prefs += desired_prefs[i].is_desired ? "true" : "false";
176 } 176 }
177 master_prefs += "}}"; 177 master_prefs += "}}";
178 178
179 return new installer::MasterPreferences(master_prefs); 179 return new installer::MasterPreferences(master_prefs);
180 } 180 }
181 181
182 void MigrationTest(installer::InstallShortcutOperation shortcut_operation);
183
182 base::win::ShortcutProperties expected_properties_; 184 base::win::ShortcutProperties expected_properties_;
183 base::win::ShortcutProperties expected_start_menu_properties_; 185 base::win::ShortcutProperties expected_start_menu_properties_;
184 186
185 BrowserDistribution* dist_; 187 BrowserDistribution* dist_;
186 base::FilePath chrome_exe_; 188 base::FilePath chrome_exe_;
187 scoped_ptr<installer::Product> product_; 189 scoped_ptr<installer::Product> product_;
188 scoped_ptr<installer::MasterPreferences> prefs_; 190 scoped_ptr<installer::MasterPreferences> prefs_;
189 191
190 base::ScopedTempDir temp_dir_; 192 base::ScopedTempDir temp_dir_;
191 base::ScopedTempDir fake_user_desktop_; 193 base::ScopedTempDir fake_user_desktop_;
192 base::ScopedTempDir fake_common_desktop_; 194 base::ScopedTempDir fake_common_desktop_;
193 base::ScopedTempDir fake_user_quick_launch_; 195 base::ScopedTempDir fake_user_quick_launch_;
194 base::ScopedTempDir fake_start_menu_; 196 base::ScopedTempDir fake_start_menu_;
195 base::ScopedTempDir fake_common_start_menu_; 197 base::ScopedTempDir fake_common_start_menu_;
196 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; 198 scoped_ptr<base::ScopedPathOverride> user_desktop_override_;
197 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; 199 scoped_ptr<base::ScopedPathOverride> common_desktop_override_;
198 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; 200 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_;
199 scoped_ptr<base::ScopedPathOverride> start_menu_override_; 201 scoped_ptr<base::ScopedPathOverride> start_menu_override_;
200 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; 202 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_;
201 203
202 base::FilePath user_desktop_shortcut_; 204 base::FilePath user_desktop_shortcut_;
203 base::FilePath user_quick_launch_shortcut_; 205 base::FilePath user_quick_launch_shortcut_;
204 base::FilePath user_start_menu_shortcut_; 206 base::FilePath user_start_menu_shortcut_;
207 base::FilePath user_start_menu_subdir_shortcut_;
205 base::FilePath system_desktop_shortcut_; 208 base::FilePath system_desktop_shortcut_;
206 base::FilePath system_start_menu_shortcut_; 209 base::FilePath system_start_menu_shortcut_;
207 base::FilePath user_alternate_desktop_shortcut_; 210 base::FilePath user_alternate_desktop_shortcut_;
208 }; 211 };
209 212
210 } // namespace 213 } // namespace
211 214
212 // Test that VisualElementsManifest.xml is not created when VisualElements are 215 // Test that VisualElementsManifest.xml is not created when VisualElements are
213 // not present. 216 // not present.
214 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { 217 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 ASSERT_TRUE(base::CreateDirectory(user_start_menu_shortcut_.DirName())); 373 ASSERT_TRUE(base::CreateDirectory(user_start_menu_shortcut_.DirName()));
371 374
372 installer::CreateOrUpdateShortcuts( 375 installer::CreateOrUpdateShortcuts(
373 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, 376 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER,
374 installer::INSTALL_SHORTCUT_REPLACE_EXISTING); 377 installer::INSTALL_SHORTCUT_REPLACE_EXISTING);
375 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); 378 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_);
376 ASSERT_FALSE(base::PathExists(user_quick_launch_shortcut_)); 379 ASSERT_FALSE(base::PathExists(user_quick_launch_shortcut_));
377 ASSERT_FALSE(base::PathExists(user_start_menu_shortcut_)); 380 ASSERT_FALSE(base::PathExists(user_start_menu_shortcut_));
378 } 381 }
379 382
383 void InstallShortcutTest::MigrationTest(
gab 2015/10/13 19:35:09 s/MigrationTest/MigrateAwayFromDeprecatedStartMenu
bcwhite 2015/10/15 18:29:35 Done.
384 installer::InstallShortcutOperation shortcut_operation) {
385 base::win::ShortcutProperties dummy_properties;
386 base::FilePath dummy_target;
387 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target));
388 dummy_properties.set_target(expected_properties_.target);
389 dummy_properties.set_working_dir(fake_user_desktop_.path());
390 dummy_properties.set_arguments(L"--dummy --args");
391 dummy_properties.set_app_id(L"El.Dummiest");
392
393 ASSERT_TRUE(base::CreateDirectory(
394 user_start_menu_subdir_shortcut_.DirName()));
395 ASSERT_FALSE(base::PathExists(user_start_menu_subdir_shortcut_));
396 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink(
397 user_start_menu_subdir_shortcut_, dummy_properties,
398 base::win::SHORTCUT_CREATE_ALWAYS));
399 ASSERT_TRUE(base::PathExists(user_start_menu_subdir_shortcut_));
400 ASSERT_FALSE(base::PathExists(user_start_menu_shortcut_));
401
402 installer::CreateOrUpdateShortcuts(
403 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER,
404 shortcut_operation);
405 ASSERT_FALSE(base::PathExists(user_start_menu_subdir_shortcut_));
406 ASSERT_TRUE(base::PathExists(user_start_menu_shortcut_));
407 }
408
409 TEST_F(InstallShortcutTest, MigrateExistingDuringUpdate) {
410 MigrationTest(installer::INSTALL_SHORTCUT_REPLACE_EXISTING);
411 }
412
413 TEST_F(InstallShortcutTest, MigrateExistingDuringInstall) {
414 MigrationTest(installer::INSTALL_SHORTCUT_CREATE_ALL);
415 }
gab 2015/10/13 19:35:09 I still think it'd be better to TEST_P to test acr
bcwhite 2015/10/15 18:29:35 Done.
416
380 TEST_F(InstallShortcutTest, CreateIfNoSystemLevelAllSystemShortcutsExist) { 417 TEST_F(InstallShortcutTest, CreateIfNoSystemLevelAllSystemShortcutsExist) {
381 base::win::ShortcutProperties dummy_properties; 418 base::win::ShortcutProperties dummy_properties;
382 base::FilePath dummy_target; 419 base::FilePath dummy_target;
383 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target)); 420 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target));
384 dummy_properties.set_target(dummy_target); 421 dummy_properties.set_target(dummy_target);
385 422
386 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 423 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink(
387 system_desktop_shortcut_, dummy_properties, 424 system_desktop_shortcut_, dummy_properties,
388 base::win::SHORTCUT_CREATE_ALWAYS)); 425 base::win::SHORTCUT_CREATE_ALWAYS));
389 ASSERT_TRUE(base::CreateDirectory( 426 ASSERT_TRUE(base::CreateDirectory(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 installer::EscapeXmlAttributeValueInSingleQuotes(&val); 477 installer::EscapeXmlAttributeValueInSingleQuotes(&val);
441 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); 478 ASSERT_STREQ(kExpectedEscapedVal, val.c_str());
442 } 479 }
443 480
444 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { 481 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) {
445 base::string16 val(L"Google Chrome"); 482 base::string16 val(L"Google Chrome");
446 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; 483 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome";
447 installer::EscapeXmlAttributeValueInSingleQuotes(&val); 484 installer::EscapeXmlAttributeValueInSingleQuotes(&val);
448 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); 485 ASSERT_STREQ(kExpectedEscapedVal, val.c_str());
449 } 486 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698