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

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: added menu_root to cleanup code 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))
gab 2015/10/20 18:25:59 Should also deprecate BrowserDistribution::SUBFOLD
bcwhite 2015/10/20 19:03:12 Will do once "app shortcut location" gets resolved
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 CoUninitialize(); 155 CoUninitialize();
150 } 156 }
151 157
152 installer::MasterPreferences* GetFakeMasterPrefs( 158 installer::MasterPreferences* GetFakeMasterPrefs(
153 bool do_not_create_desktop_shortcut, 159 bool do_not_create_desktop_shortcut,
154 bool do_not_create_quick_launch_shortcut, 160 bool do_not_create_quick_launch_shortcut,
155 bool alternate_desktop_shortcut) { 161 bool alternate_desktop_shortcut) {
156 const struct { 162 const struct {
157 const char* pref_name; 163 const char* pref_name;
158 bool is_desired; 164 bool is_desired;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 base::ScopedTempDir fake_common_start_menu_; 199 base::ScopedTempDir fake_common_start_menu_;
194 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; 200 scoped_ptr<base::ScopedPathOverride> user_desktop_override_;
195 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; 201 scoped_ptr<base::ScopedPathOverride> common_desktop_override_;
196 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; 202 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_;
197 scoped_ptr<base::ScopedPathOverride> start_menu_override_; 203 scoped_ptr<base::ScopedPathOverride> start_menu_override_;
198 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; 204 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_;
199 205
200 base::FilePath user_desktop_shortcut_; 206 base::FilePath user_desktop_shortcut_;
201 base::FilePath user_quick_launch_shortcut_; 207 base::FilePath user_quick_launch_shortcut_;
202 base::FilePath user_start_menu_shortcut_; 208 base::FilePath user_start_menu_shortcut_;
209 base::FilePath user_start_menu_subdir_shortcut_;
203 base::FilePath system_desktop_shortcut_; 210 base::FilePath system_desktop_shortcut_;
204 base::FilePath system_start_menu_shortcut_; 211 base::FilePath system_start_menu_shortcut_;
212 base::FilePath system_start_menu_subdir_shortcut_;
205 base::FilePath user_alternate_desktop_shortcut_; 213 base::FilePath user_alternate_desktop_shortcut_;
206 }; 214 };
207 215
208 } // namespace 216 } // namespace
209 217
210 // Test that VisualElementsManifest.xml is not created when VisualElements are 218 // Test that VisualElementsManifest.xml is not created when VisualElements are
211 // not present. 219 // not present.
212 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { 220 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) {
213 ASSERT_TRUE( 221 ASSERT_TRUE(
214 installer::CreateVisualElementsManifest(test_dir_.path(), version_)); 222 installer::CreateVisualElementsManifest(test_dir_.path(), version_));
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 ASSERT_TRUE(base::CreateDirectory(user_start_menu_shortcut_.DirName())); 376 ASSERT_TRUE(base::CreateDirectory(user_start_menu_shortcut_.DirName()));
369 377
370 installer::CreateOrUpdateShortcuts( 378 installer::CreateOrUpdateShortcuts(
371 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, 379 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER,
372 installer::INSTALL_SHORTCUT_REPLACE_EXISTING); 380 installer::INSTALL_SHORTCUT_REPLACE_EXISTING);
373 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); 381 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_);
374 ASSERT_FALSE(base::PathExists(user_quick_launch_shortcut_)); 382 ASSERT_FALSE(base::PathExists(user_quick_launch_shortcut_));
375 ASSERT_FALSE(base::PathExists(user_start_menu_shortcut_)); 383 ASSERT_FALSE(base::PathExists(user_start_menu_shortcut_));
376 } 384 }
377 385
386 class MigrateShortcutTest : public InstallShortcutTest,
387 public testing::WithParamInterface<
388 testing::tuple<
389 installer::InstallShortcutOperation,
390 installer::InstallShortcutLevel>> {
391
392 public:
393 MigrateShortcutTest() : shortcut_operation_(testing::get<0>(GetParam())),
394 shortcut_level_(testing::get<1>(GetParam())) {}
395
396 protected:
397 const installer::InstallShortcutOperation shortcut_operation_;
398 const installer::InstallShortcutLevel shortcut_level_;
399 };
gab 2015/10/20 18:25:59 private: DISALLOW_COPY_AND_ASSIGN(MigrateShortcut
bcwhite 2015/10/20 19:03:12 Done.
400
401 TEST_P(MigrateShortcutTest, MigrateAwayFromDeprecatedStartMenuTest) {
402 base::win::ShortcutProperties dummy_properties;
403 base::FilePath dummy_target;
404 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target));
405 dummy_properties.set_target(expected_properties_.target);
406 dummy_properties.set_working_dir(fake_user_desktop_.path());
407 dummy_properties.set_arguments(L"--dummy --args");
408 dummy_properties.set_app_id(L"El.Dummiest");
409
410 base::FilePath start_menu_shortcut;
411 base::FilePath start_menu_subdir_shortcut;
412 if (shortcut_level_ == installer::CURRENT_USER) {
413 start_menu_shortcut = user_start_menu_shortcut_;
414 start_menu_subdir_shortcut = user_start_menu_subdir_shortcut_;
415 } else {
416 start_menu_shortcut = system_start_menu_shortcut_;
417 start_menu_subdir_shortcut = system_start_menu_subdir_shortcut_;
418 }
419
420 ASSERT_TRUE(base::CreateDirectory(
421 start_menu_subdir_shortcut.DirName()));
422 ASSERT_FALSE(base::PathExists(start_menu_subdir_shortcut));
423 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink(
424 start_menu_subdir_shortcut, dummy_properties,
425 base::win::SHORTCUT_CREATE_ALWAYS));
426 ASSERT_TRUE(base::PathExists(start_menu_subdir_shortcut));
427 ASSERT_FALSE(base::PathExists(start_menu_shortcut));
428
429 installer::CreateOrUpdateShortcuts(
430 chrome_exe_, *product_, *prefs_, shortcut_level_, shortcut_operation_);
431 ASSERT_FALSE(base::PathExists(start_menu_subdir_shortcut));
432 ASSERT_TRUE(base::PathExists(start_menu_shortcut));
433 }
434
435 // Verify that any installer operation for any installation level triggers
436 // the migration from sub-folder to root of start-menu.
437 INSTANTIATE_TEST_CASE_P(
438 MigrateShortcutTests, MigrateShortcutTest,
439 testing::Combine(
440 testing::Values(
441 installer::INSTALL_SHORTCUT_REPLACE_EXISTING,
442 installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL,
443 installer::INSTALL_SHORTCUT_CREATE_ALL),
444 testing::Values(
445 installer::CURRENT_USER,
446 installer::ALL_USERS)));
447
378 TEST_F(InstallShortcutTest, CreateIfNoSystemLevelAllSystemShortcutsExist) { 448 TEST_F(InstallShortcutTest, CreateIfNoSystemLevelAllSystemShortcutsExist) {
379 base::win::ShortcutProperties dummy_properties; 449 base::win::ShortcutProperties dummy_properties;
380 base::FilePath dummy_target; 450 base::FilePath dummy_target;
381 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target)); 451 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target));
382 dummy_properties.set_target(dummy_target); 452 dummy_properties.set_target(dummy_target);
383 453
384 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( 454 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink(
385 system_desktop_shortcut_, dummy_properties, 455 system_desktop_shortcut_, dummy_properties,
386 base::win::SHORTCUT_CREATE_ALWAYS)); 456 base::win::SHORTCUT_CREATE_ALWAYS));
387 ASSERT_TRUE(base::CreateDirectory( 457 ASSERT_TRUE(base::CreateDirectory(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 installer::EscapeXmlAttributeValueInSingleQuotes(&val); 508 installer::EscapeXmlAttributeValueInSingleQuotes(&val);
439 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); 509 ASSERT_STREQ(kExpectedEscapedVal, val.c_str());
440 } 510 }
441 511
442 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { 512 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) {
443 base::string16 val(L"Google Chrome"); 513 base::string16 val(L"Google Chrome");
444 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; 514 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome";
445 installer::EscapeXmlAttributeValueInSingleQuotes(&val); 515 installer::EscapeXmlAttributeValueInSingleQuotes(&val);
446 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); 516 ASSERT_STREQ(kExpectedEscapedVal, val.c_str());
447 } 517 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698