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

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: test improvements 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_ =
138 fake_common_start_menu_.path().Append(shortcut_name);
139 system_start_menu_subdir_shortcut_ =
136 fake_common_start_menu_.path().Append( 140 fake_common_start_menu_.path().Append(
137 dist_->GetStartMenuShortcutSubfolder( 141 dist_->GetStartMenuShortcutSubfolder(
138 BrowserDistribution::SUBFOLDER_CHROME)) 142 BrowserDistribution::SUBFOLDER_CHROME))
139 .Append(shortcut_name); 143 .Append(shortcut_name);
140 user_alternate_desktop_shortcut_ = 144 user_alternate_desktop_shortcut_ =
141 fake_user_desktop_.path().Append(alternate_shortcut_name); 145 fake_user_desktop_.path().Append(alternate_shortcut_name);
142 } 146 }
143 147
144 void TearDown() override { 148 void TearDown() override {
145 // Try to unpin potentially pinned shortcuts (although pinning isn't tested, 149 // Try to unpin potentially pinned shortcuts (although pinning isn't tested,
146 // the call itself might still have pinned the Start Menu shortcuts). 150 // the call itself might still have pinned the Start Menu shortcuts).
147 base::win::UnpinShortcutFromTaskbar(user_start_menu_shortcut_); 151 base::win::UnpinShortcutFromTaskbar(user_start_menu_shortcut_);
152 base::win::UnpinShortcutFromTaskbar(user_start_menu_subdir_shortcut_);
148 base::win::UnpinShortcutFromTaskbar(system_start_menu_shortcut_); 153 base::win::UnpinShortcutFromTaskbar(system_start_menu_shortcut_);
154 base::win::UnpinShortcutFromTaskbar(system_start_menu_subdir_shortcut_);
149 base::win::UnpinShortcutFromStart(user_start_menu_shortcut_); 155 base::win::UnpinShortcutFromStart(user_start_menu_shortcut_);
156 base::win::UnpinShortcutFromStart(user_start_menu_subdir_shortcut_);
150 base::win::UnpinShortcutFromStart(system_start_menu_shortcut_); 157 base::win::UnpinShortcutFromStart(system_start_menu_shortcut_);
158 base::win::UnpinShortcutFromStart(system_start_menu_subdir_shortcut_);
151 CoUninitialize(); 159 CoUninitialize();
152 } 160 }
153 161
154 installer::MasterPreferences* GetFakeMasterPrefs( 162 installer::MasterPreferences* GetFakeMasterPrefs(
155 bool do_not_create_desktop_shortcut, 163 bool do_not_create_desktop_shortcut,
156 bool do_not_create_quick_launch_shortcut, 164 bool do_not_create_quick_launch_shortcut,
157 bool alternate_desktop_shortcut) { 165 bool alternate_desktop_shortcut) {
158 const struct { 166 const struct {
159 const char* pref_name; 167 const char* pref_name;
160 bool is_desired; 168 bool is_desired;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 base::ScopedTempDir fake_common_start_menu_; 203 base::ScopedTempDir fake_common_start_menu_;
196 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; 204 scoped_ptr<base::ScopedPathOverride> user_desktop_override_;
197 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; 205 scoped_ptr<base::ScopedPathOverride> common_desktop_override_;
198 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; 206 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_;
199 scoped_ptr<base::ScopedPathOverride> start_menu_override_; 207 scoped_ptr<base::ScopedPathOverride> start_menu_override_;
200 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; 208 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_;
201 209
202 base::FilePath user_desktop_shortcut_; 210 base::FilePath user_desktop_shortcut_;
203 base::FilePath user_quick_launch_shortcut_; 211 base::FilePath user_quick_launch_shortcut_;
204 base::FilePath user_start_menu_shortcut_; 212 base::FilePath user_start_menu_shortcut_;
213 base::FilePath user_start_menu_subdir_shortcut_;
205 base::FilePath system_desktop_shortcut_; 214 base::FilePath system_desktop_shortcut_;
206 base::FilePath system_start_menu_shortcut_; 215 base::FilePath system_start_menu_shortcut_;
216 base::FilePath system_start_menu_subdir_shortcut_;
207 base::FilePath user_alternate_desktop_shortcut_; 217 base::FilePath user_alternate_desktop_shortcut_;
208 }; 218 };
209 219
210 } // namespace 220 } // namespace
211 221
212 // Test that VisualElementsManifest.xml is not created when VisualElements are 222 // Test that VisualElementsManifest.xml is not created when VisualElements are
213 // not present. 223 // not present.
214 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { 224 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) {
215 ASSERT_TRUE( 225 ASSERT_TRUE(
216 installer::CreateVisualElementsManifest(test_dir_.path(), version_)); 226 installer::CreateVisualElementsManifest(test_dir_.path(), version_));
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 ASSERT_TRUE(base::CreateDirectory(user_start_menu_shortcut_.DirName())); 380 ASSERT_TRUE(base::CreateDirectory(user_start_menu_shortcut_.DirName()));
371 381
372 installer::CreateOrUpdateShortcuts( 382 installer::CreateOrUpdateShortcuts(
373 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, 383 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER,
374 installer::INSTALL_SHORTCUT_REPLACE_EXISTING); 384 installer::INSTALL_SHORTCUT_REPLACE_EXISTING);
375 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); 385 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_);
376 ASSERT_FALSE(base::PathExists(user_quick_launch_shortcut_)); 386 ASSERT_FALSE(base::PathExists(user_quick_launch_shortcut_));
377 ASSERT_FALSE(base::PathExists(user_start_menu_shortcut_)); 387 ASSERT_FALSE(base::PathExists(user_start_menu_shortcut_));
378 } 388 }
379 389
390 class MigrateShortcutTest : public InstallShortcutTest,
391 public testing::WithParamInterface<
392 std::tr1::tuple<
grt (UTC plus 2) 2015/10/19 17:28:45 nit: use testing::tuple and testing::get<> rather
bcwhite 2015/10/20 16:02:13 Done.
393 installer::InstallShortcutOperation,
394 installer::InstallShortcutLevel>> {
395 };
396
397 TEST_P(MigrateShortcutTest, MigrateAwayFromDeprecatedStartMenuTest) {
398 installer::InstallShortcutOperation shortcut_operation =
399 std::tr1::get<0>(GetParam());
400 installer::InstallShortcutLevel shortcut_level =
401 std::tr1::get<1>(GetParam());
gab 2015/10/19 18:00:14 Make |shortcut_operation_| and |shortcut_level_| p
bcwhite 2015/10/20 16:02:13 Done.
402
403 base::win::ShortcutProperties dummy_properties;
404 base::FilePath dummy_target;
405 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target));
406 dummy_properties.set_target(expected_properties_.target);
407 dummy_properties.set_working_dir(fake_user_desktop_.path());
408 dummy_properties.set_arguments(L"--dummy --args");
409 dummy_properties.set_app_id(L"El.Dummiest");
410
411 base::FilePath start_menu_shortcut;
412 base::FilePath start_menu_subdir_shortcut;
413 if (shortcut_level == installer::CURRENT_USER) {
414 start_menu_shortcut = user_start_menu_shortcut_;
415 start_menu_subdir_shortcut = user_start_menu_subdir_shortcut_;
416 } else {
417 start_menu_shortcut = system_start_menu_shortcut_;
418 start_menu_subdir_shortcut = system_start_menu_subdir_shortcut_;
419 }
420
421 ASSERT_TRUE(base::CreateDirectory(
422 start_menu_subdir_shortcut.DirName()));
423 ASSERT_FALSE(base::PathExists(start_menu_subdir_shortcut));
424 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink(
425 start_menu_subdir_shortcut, dummy_properties,
426 base::win::SHORTCUT_CREATE_ALWAYS));
427 ASSERT_TRUE(base::PathExists(start_menu_subdir_shortcut));
428 ASSERT_FALSE(base::PathExists(start_menu_shortcut));
429
430 installer::CreateOrUpdateShortcuts(
431 chrome_exe_, *product_, *prefs_, shortcut_level, shortcut_operation);
432 ASSERT_FALSE(base::PathExists(start_menu_subdir_shortcut));
433 ASSERT_TRUE(base::PathExists(start_menu_shortcut));
434 }
435
436 // Verify that any installer operation for any installation level triggers
437 // the migration from sub-folder to root of start-menu.
438 INSTANTIATE_TEST_CASE_P(
439 MigrateShortcutTests, MigrateShortcutTest,
440 testing::Combine(
441 testing::Values(
442 installer::INSTALL_SHORTCUT_REPLACE_EXISTING,
443 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL,
444 installer::INSTALL_SHORTCUT_CREATE_ALL),
445 testing::Values(
446 installer::CURRENT_USER,
447 installer::ALL_USERS)));
448
380 TEST_F(InstallShortcutTest, CreateIfNoSystemLevelAllSystemShortcutsExist) { 449 TEST_F(InstallShortcutTest, CreateIfNoSystemLevelAllSystemShortcutsExist) {
381 base::win::ShortcutProperties dummy_properties; 450 base::win::ShortcutProperties dummy_properties;
382 base::FilePath dummy_target; 451 base::FilePath dummy_target;
383 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target)); 452 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target));
384 dummy_properties.set_target(dummy_target); 453 dummy_properties.set_target(dummy_target);
385 454
386 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 455 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink(
387 system_desktop_shortcut_, dummy_properties, 456 system_desktop_shortcut_, dummy_properties,
388 base::win::SHORTCUT_CREATE_ALWAYS)); 457 base::win::SHORTCUT_CREATE_ALWAYS));
389 ASSERT_TRUE(base::CreateDirectory( 458 ASSERT_TRUE(base::CreateDirectory(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 installer::EscapeXmlAttributeValueInSingleQuotes(&val); 509 installer::EscapeXmlAttributeValueInSingleQuotes(&val);
441 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); 510 ASSERT_STREQ(kExpectedEscapedVal, val.c_str());
442 } 511 }
443 512
444 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { 513 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) {
445 base::string16 val(L"Google Chrome"); 514 base::string16 val(L"Google Chrome");
446 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; 515 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome";
447 installer::EscapeXmlAttributeValueInSingleQuotes(&val); 516 installer::EscapeXmlAttributeValueInSingleQuotes(&val);
448 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); 517 ASSERT_STREQ(kExpectedEscapedVal, val.c_str());
449 } 518 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698