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 <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 Loading... | |
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_); |
148 base::win::UnpinShortcutFromTaskbar(system_start_menu_shortcut_); | 152 base::win::UnpinShortcutFromTaskbar(system_start_menu_shortcut_); |
149 base::win::UnpinShortcutFromStart(user_start_menu_shortcut_); | 153 base::win::UnpinShortcutFromStart(user_start_menu_shortcut_); |
154 base::win::UnpinShortcutFromStart(user_start_menu_subdir_shortcut_); | |
150 base::win::UnpinShortcutFromStart(system_start_menu_shortcut_); | 155 base::win::UnpinShortcutFromStart(system_start_menu_shortcut_); |
156 base::win::UnpinShortcutFromStart(system_start_menu_subdir_shortcut_); | |
gab
2015/10/15 18:55:06
Also need to add matching UnpinShortcutFromTaskbar
bcwhite
2015/10/15 20:12:19
Done.
| |
151 CoUninitialize(); | 157 CoUninitialize(); |
152 } | 158 } |
153 | 159 |
154 installer::MasterPreferences* GetFakeMasterPrefs( | 160 installer::MasterPreferences* GetFakeMasterPrefs( |
155 bool do_not_create_desktop_shortcut, | 161 bool do_not_create_desktop_shortcut, |
156 bool do_not_create_quick_launch_shortcut, | 162 bool do_not_create_quick_launch_shortcut, |
157 bool alternate_desktop_shortcut) { | 163 bool alternate_desktop_shortcut) { |
158 const struct { | 164 const struct { |
159 const char* pref_name; | 165 const char* pref_name; |
160 bool is_desired; | 166 bool is_desired; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 base::ScopedTempDir fake_common_start_menu_; | 201 base::ScopedTempDir fake_common_start_menu_; |
196 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; | 202 scoped_ptr<base::ScopedPathOverride> user_desktop_override_; |
197 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; | 203 scoped_ptr<base::ScopedPathOverride> common_desktop_override_; |
198 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; | 204 scoped_ptr<base::ScopedPathOverride> user_quick_launch_override_; |
199 scoped_ptr<base::ScopedPathOverride> start_menu_override_; | 205 scoped_ptr<base::ScopedPathOverride> start_menu_override_; |
200 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; | 206 scoped_ptr<base::ScopedPathOverride> common_start_menu_override_; |
201 | 207 |
202 base::FilePath user_desktop_shortcut_; | 208 base::FilePath user_desktop_shortcut_; |
203 base::FilePath user_quick_launch_shortcut_; | 209 base::FilePath user_quick_launch_shortcut_; |
204 base::FilePath user_start_menu_shortcut_; | 210 base::FilePath user_start_menu_shortcut_; |
211 base::FilePath user_start_menu_subdir_shortcut_; | |
205 base::FilePath system_desktop_shortcut_; | 212 base::FilePath system_desktop_shortcut_; |
206 base::FilePath system_start_menu_shortcut_; | 213 base::FilePath system_start_menu_shortcut_; |
214 base::FilePath system_start_menu_subdir_shortcut_; | |
207 base::FilePath user_alternate_desktop_shortcut_; | 215 base::FilePath user_alternate_desktop_shortcut_; |
208 }; | 216 }; |
209 | 217 |
210 } // namespace | 218 } // namespace |
211 | 219 |
212 // Test that VisualElementsManifest.xml is not created when VisualElements are | 220 // Test that VisualElementsManifest.xml is not created when VisualElements are |
213 // not present. | 221 // not present. |
214 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { | 222 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { |
215 ASSERT_TRUE( | 223 ASSERT_TRUE( |
216 installer::CreateVisualElementsManifest(test_dir_.path(), version_)); | 224 installer::CreateVisualElementsManifest(test_dir_.path(), version_)); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
370 ASSERT_TRUE(base::CreateDirectory(user_start_menu_shortcut_.DirName())); | 378 ASSERT_TRUE(base::CreateDirectory(user_start_menu_shortcut_.DirName())); |
371 | 379 |
372 installer::CreateOrUpdateShortcuts( | 380 installer::CreateOrUpdateShortcuts( |
373 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, | 381 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, |
374 installer::INSTALL_SHORTCUT_REPLACE_EXISTING); | 382 installer::INSTALL_SHORTCUT_REPLACE_EXISTING); |
375 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); | 383 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); |
376 ASSERT_FALSE(base::PathExists(user_quick_launch_shortcut_)); | 384 ASSERT_FALSE(base::PathExists(user_quick_launch_shortcut_)); |
377 ASSERT_FALSE(base::PathExists(user_start_menu_shortcut_)); | 385 ASSERT_FALSE(base::PathExists(user_start_menu_shortcut_)); |
378 } | 386 } |
379 | 387 |
388 struct ShortcutParams { | |
389 installer::InstallShortcutOperation operation; | |
390 installer::InstallShortcutLevel level; | |
391 | |
392 ShortcutParams( | |
gab
2015/10/15 18:55:06
Constructor goes before members (https://google-st
bcwhite
2015/10/15 20:12:19
Done.
| |
393 installer::InstallShortcutOperation op, | |
394 installer::InstallShortcutLevel lev) | |
395 : operation(op), level(lev) {} | |
396 }; | |
397 | |
398 class MigrateShortcutTest : public InstallShortcutTest, | |
399 public testing::WithParamInterface< | |
400 ShortcutParams> { | |
401 }; | |
402 | |
403 TEST_P(MigrateShortcutTest, MigrateAwayFromDeprecatedStartMenuTest) { | |
404 installer::InstallShortcutOperation shortcut_operation = GetParam().operation; | |
405 installer::InstallShortcutLevel shortcut_level = GetParam().level; | |
406 base::win::ShortcutProperties dummy_properties; | |
407 base::FilePath dummy_target; | |
408 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target)); | |
409 dummy_properties.set_target(expected_properties_.target); | |
410 dummy_properties.set_working_dir(fake_user_desktop_.path()); | |
411 dummy_properties.set_arguments(L"--dummy --args"); | |
412 dummy_properties.set_app_id(L"El.Dummiest"); | |
413 | |
414 base::FilePath start_menu_shortcut; | |
415 base::FilePath start_menu_subdir_shortcut; | |
416 if (shortcut_level == installer::CURRENT_USER) { | |
417 start_menu_shortcut = user_start_menu_shortcut_; | |
418 start_menu_subdir_shortcut = user_start_menu_subdir_shortcut_; | |
419 } else { | |
420 start_menu_shortcut = system_start_menu_shortcut_; | |
421 start_menu_subdir_shortcut = system_start_menu_subdir_shortcut_; | |
422 } | |
423 | |
424 ASSERT_TRUE(base::CreateDirectory( | |
425 start_menu_subdir_shortcut.DirName())); | |
426 ASSERT_FALSE(base::PathExists(start_menu_subdir_shortcut)); | |
427 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | |
428 start_menu_subdir_shortcut, dummy_properties, | |
429 base::win::SHORTCUT_CREATE_ALWAYS)); | |
430 ASSERT_TRUE(base::PathExists(start_menu_subdir_shortcut)); | |
431 ASSERT_FALSE(base::PathExists(start_menu_shortcut)); | |
432 | |
433 installer::CreateOrUpdateShortcuts( | |
434 chrome_exe_, *product_, *prefs_, shortcut_level, shortcut_operation); | |
435 ASSERT_FALSE(base::PathExists(start_menu_subdir_shortcut)); | |
436 ASSERT_TRUE(base::PathExists(start_menu_shortcut)); | |
437 } | |
438 | |
439 INSTANTIATE_TEST_CASE_P( | |
gab
2015/10/15 18:55:06
Add a comment like:
// Verify that any installer
bcwhite
2015/10/15 20:12:19
Done.
| |
440 MigrateShortcutTests, MigrateShortcutTest, | |
441 testing::Values(ShortcutParams(installer::INSTALL_SHORTCUT_REPLACE_EXISTING, | |
442 installer::CURRENT_USER), | |
443 ShortcutParams(installer::INSTALL_SHORTCUT_CREATE_ALL, | |
444 installer::CURRENT_USER), | |
445 ShortcutParams(installer::INSTALL_SHORTCUT_REPLACE_EXISTING, | |
446 installer::ALL_USERS), | |
447 ShortcutParams(installer::INSTALL_SHORTCUT_CREATE_ALL, | |
gab
2015/10/15 18:55:06
Instead of using a custom struct, make your test a
bcwhite
2015/10/15 20:12:19
Nice. Done.
| |
448 installer::ALL_USERS))); | |
449 | |
380 TEST_F(InstallShortcutTest, CreateIfNoSystemLevelAllSystemShortcutsExist) { | 450 TEST_F(InstallShortcutTest, CreateIfNoSystemLevelAllSystemShortcutsExist) { |
381 base::win::ShortcutProperties dummy_properties; | 451 base::win::ShortcutProperties dummy_properties; |
382 base::FilePath dummy_target; | 452 base::FilePath dummy_target; |
383 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target)); | 453 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target)); |
384 dummy_properties.set_target(dummy_target); | 454 dummy_properties.set_target(dummy_target); |
385 | 455 |
386 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( | 456 ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink( |
387 system_desktop_shortcut_, dummy_properties, | 457 system_desktop_shortcut_, dummy_properties, |
388 base::win::SHORTCUT_CREATE_ALWAYS)); | 458 base::win::SHORTCUT_CREATE_ALWAYS)); |
389 ASSERT_TRUE(base::CreateDirectory( | 459 ASSERT_TRUE(base::CreateDirectory( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 installer::EscapeXmlAttributeValueInSingleQuotes(&val); | 510 installer::EscapeXmlAttributeValueInSingleQuotes(&val); |
441 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); | 511 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); |
442 } | 512 } |
443 | 513 |
444 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { | 514 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { |
445 base::string16 val(L"Google Chrome"); | 515 base::string16 val(L"Google Chrome"); |
446 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; | 516 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; |
447 installer::EscapeXmlAttributeValueInSingleQuotes(&val); | 517 installer::EscapeXmlAttributeValueInSingleQuotes(&val); |
448 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); | 518 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); |
449 } | 519 } |
OLD | NEW |