| 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/installer/setup/install.h" | 5 #include "chrome/installer/setup/install.h" |
| 6 | 6 |
| 7 #include <objbase.h> | 7 #include <objbase.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <tuple> |
| 12 | 13 |
| 13 #include "base/base_paths.h" | 14 #include "base/base_paths.h" |
| 14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 15 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
| 16 #include "base/files/scoped_temp_dir.h" | 17 #include "base/files/scoped_temp_dir.h" |
| 17 #include "base/macros.h" | 18 #include "base/macros.h" |
| 18 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/test/scoped_path_override.h" | 21 #include "base/test/scoped_path_override.h" |
| 21 #include "base/test/test_shortcut_win.h" | 22 #include "base/test/test_shortcut_win.h" |
| 22 #include "base/version.h" | 23 #include "base/version.h" |
| 23 #include "base/win/shortcut.h" | 24 #include "base/win/shortcut.h" |
| 25 #include "chrome/install_static/install_modes.h" |
| 26 #include "chrome/install_static/test/scoped_install_details.h" |
| 24 #include "chrome/installer/setup/install_worker.h" | 27 #include "chrome/installer/setup/install_worker.h" |
| 25 #include "chrome/installer/setup/installer_state.h" | 28 #include "chrome/installer/setup/installer_state.h" |
| 26 #include "chrome/installer/setup/setup_constants.h" | 29 #include "chrome/installer/setup/setup_constants.h" |
| 27 #include "chrome/installer/util/browser_distribution.h" | 30 #include "chrome/installer/util/browser_distribution.h" |
| 28 #include "chrome/installer/util/install_util.h" | 31 #include "chrome/installer/util/install_util.h" |
| 29 #include "chrome/installer/util/master_preferences.h" | 32 #include "chrome/installer/util/master_preferences.h" |
| 30 #include "chrome/installer/util/master_preferences_constants.h" | 33 #include "chrome/installer/util/master_preferences_constants.h" |
| 31 #include "chrome/installer/util/product.h" | 34 #include "chrome/installer/util/product.h" |
| 32 #include "chrome/installer/util/shell_util.h" | 35 #include "chrome/installer/util/shell_util.h" |
| 33 #include "chrome/installer/util/util_constants.h" | 36 #include "chrome/installer/util/util_constants.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 35 | 38 |
| 36 namespace { | 39 namespace { |
| 37 | 40 |
| 38 class CreateVisualElementsManifestTest : public testing::Test { | 41 // A parameterized test harness for testing |
| 42 // installer::CreateVisualElementsManifest. The parameters are: |
| 43 // 0: an index into a brand's install_static::kInstallModes array. |
| 44 // 1: the expected manifest. |
| 45 class CreateVisualElementsManifestTest |
| 46 : public ::testing::TestWithParam< |
| 47 std::tuple<install_static::InstallConstantIndex, const char*>> { |
| 39 protected: | 48 protected: |
| 49 CreateVisualElementsManifestTest() |
| 50 : scoped_install_details_(false /* !system_level */, |
| 51 std::get<0>(GetParam())), |
| 52 expected_manifest_(std::get<1>(GetParam())), |
| 53 version_("0.0.0.0") {} |
| 54 |
| 40 void SetUp() override { | 55 void SetUp() override { |
| 41 // Create a temp directory for testing. | 56 // Create a temp directory for testing. |
| 42 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 57 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
| 43 | 58 |
| 44 version_ = base::Version("0.0.0.0"); | |
| 45 | |
| 46 version_dir_ = test_dir_.GetPath().AppendASCII(version_.GetString()); | 59 version_dir_ = test_dir_.GetPath().AppendASCII(version_.GetString()); |
| 47 ASSERT_TRUE(base::CreateDirectory(version_dir_)); | 60 ASSERT_TRUE(base::CreateDirectory(version_dir_)); |
| 48 | 61 |
| 49 manifest_path_ = | 62 manifest_path_ = |
| 50 test_dir_.GetPath().Append(installer::kVisualElementsManifest); | 63 test_dir_.GetPath().Append(installer::kVisualElementsManifest); |
| 51 } | 64 } |
| 52 | 65 |
| 53 void TearDown() override { | 66 void TearDown() override { |
| 54 // Clean up test directory manually so we can fail if it leaks. | 67 // Clean up test directory manually so we can fail if it leaks. |
| 55 ASSERT_TRUE(test_dir_.Delete()); | 68 ASSERT_TRUE(test_dir_.Delete()); |
| 56 } | 69 } |
| 57 | 70 |
| 71 // InstallDetails for this test run. |
| 72 install_static::ScopedInstallDetails scoped_install_details_; |
| 73 |
| 74 // The expected contents of the manifest. |
| 75 const char* const expected_manifest_; |
| 76 |
| 77 // A dummy version number used to create the version directory. |
| 78 const base::Version version_; |
| 79 |
| 58 // The temporary directory used to contain the test operations. | 80 // The temporary directory used to contain the test operations. |
| 59 base::ScopedTempDir test_dir_; | 81 base::ScopedTempDir test_dir_; |
| 60 | 82 |
| 61 // A dummy version number used to create the version directory. | |
| 62 base::Version version_; | |
| 63 | |
| 64 // The path to |test_dir_|\|version_|. | 83 // The path to |test_dir_|\|version_|. |
| 65 base::FilePath version_dir_; | 84 base::FilePath version_dir_; |
| 66 | 85 |
| 67 // The path to VisualElementsManifest.xml. | 86 // The path to VisualElementsManifest.xml. |
| 68 base::FilePath manifest_path_; | 87 base::FilePath manifest_path_; |
| 88 |
| 89 private: |
| 90 DISALLOW_COPY_AND_ASSIGN(CreateVisualElementsManifestTest); |
| 69 }; | 91 }; |
| 70 | 92 |
| 93 constexpr char kExpectedPrimaryManifest[] = |
| 94 "<Application xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\r\n" |
| 95 " <VisualElements\r\n" |
| 96 " ShowNameOnSquare150x150Logo='on'\r\n" |
| 97 " Square150x150Logo='0.0.0.0\\VisualElements\\Logo.png'\r\n" |
| 98 " Square70x70Logo='0.0.0.0\\VisualElements\\SmallLogo.png'\r\n" |
| 99 " Square44x44Logo='0.0.0.0\\VisualElements\\SmallLogo.png'\r\n" |
| 100 " ForegroundText='light'\r\n" |
| 101 " BackgroundColor='#212121'/>\r\n" |
| 102 "</Application>\r\n"; |
| 103 |
| 104 #if defined(GOOGLE_CHROME_BUILD) |
| 105 constexpr char kExpectedCanaryManifest[] = |
| 106 "<Application xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\r\n" |
| 107 " <VisualElements\r\n" |
| 108 " ShowNameOnSquare150x150Logo='on'\r\n" |
| 109 " Square150x150Logo='0.0.0.0\\VisualElements\\LogoCanary.png'\r\n" |
| 110 " Square70x70Logo='0.0.0.0\\VisualElements\\SmallLogoCanary.png'\r\n" |
| 111 " Square44x44Logo='0.0.0.0\\VisualElements\\SmallLogoCanary.png'\r\n" |
| 112 " ForegroundText='light'\r\n" |
| 113 " BackgroundColor='#212121'/>\r\n" |
| 114 "</Application>\r\n"; |
| 115 |
| 116 INSTANTIATE_TEST_CASE_P( |
| 117 GoogleChrome, |
| 118 CreateVisualElementsManifestTest, |
| 119 testing::Combine(testing::Values(install_static::STABLE_INDEX), |
| 120 testing::Values(kExpectedPrimaryManifest))); |
| 121 INSTANTIATE_TEST_CASE_P( |
| 122 CanaryChrome, |
| 123 CreateVisualElementsManifestTest, |
| 124 testing::Combine(testing::Values(install_static::CANARY_INDEX), |
| 125 testing::Values(kExpectedCanaryManifest))); |
| 126 #else |
| 127 INSTANTIATE_TEST_CASE_P( |
| 128 Chromium, |
| 129 CreateVisualElementsManifestTest, |
| 130 testing::Combine(testing::Values(install_static::CHROMIUM_INDEX), |
| 131 testing::Values(kExpectedPrimaryManifest))); |
| 132 #endif |
| 133 |
| 71 class InstallShortcutTest : public testing::Test { | 134 class InstallShortcutTest : public testing::Test { |
| 72 protected: | 135 protected: |
| 73 void SetUp() override { | 136 void SetUp() override { |
| 74 EXPECT_EQ(S_OK, CoInitialize(NULL)); | 137 EXPECT_EQ(S_OK, CoInitialize(NULL)); |
| 75 | 138 |
| 76 dist_ = BrowserDistribution::GetDistribution(); | 139 dist_ = BrowserDistribution::GetDistribution(); |
| 77 ASSERT_TRUE(dist_ != NULL); | 140 ASSERT_TRUE(dist_ != NULL); |
| 78 product_.reset(new installer::Product(dist_)); | 141 product_.reset(new installer::Product(dist_)); |
| 79 | 142 |
| 80 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 143 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 base::FilePath user_start_menu_subdir_shortcut_; | 258 base::FilePath user_start_menu_subdir_shortcut_; |
| 196 base::FilePath system_desktop_shortcut_; | 259 base::FilePath system_desktop_shortcut_; |
| 197 base::FilePath system_start_menu_shortcut_; | 260 base::FilePath system_start_menu_shortcut_; |
| 198 base::FilePath system_start_menu_subdir_shortcut_; | 261 base::FilePath system_start_menu_subdir_shortcut_; |
| 199 }; | 262 }; |
| 200 | 263 |
| 201 } // namespace | 264 } // namespace |
| 202 | 265 |
| 203 // Test that VisualElementsManifest.xml is not created when VisualElements are | 266 // Test that VisualElementsManifest.xml is not created when VisualElements are |
| 204 // not present. | 267 // not present. |
| 205 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { | 268 TEST_P(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { |
| 206 ASSERT_TRUE( | 269 ASSERT_TRUE( |
| 207 installer::CreateVisualElementsManifest(test_dir_.GetPath(), version_)); | 270 installer::CreateVisualElementsManifest(test_dir_.GetPath(), version_)); |
| 208 ASSERT_FALSE(base::PathExists(manifest_path_)); | 271 ASSERT_FALSE(base::PathExists(manifest_path_)); |
| 209 } | 272 } |
| 210 | 273 |
| 211 // Test that VisualElementsManifest.xml is created with the correct content when | 274 // Test that VisualElementsManifest.xml is created with the correct content when |
| 212 // VisualElements are present. | 275 // VisualElements are present. |
| 213 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestCreated) { | 276 TEST_P(CreateVisualElementsManifestTest, VisualElementsManifestCreated) { |
| 214 ASSERT_TRUE(base::CreateDirectory( | 277 ASSERT_TRUE(base::CreateDirectory( |
| 215 version_dir_.Append(installer::kVisualElements))); | 278 version_dir_.Append(installer::kVisualElements))); |
| 216 ASSERT_TRUE( | 279 ASSERT_TRUE( |
| 217 installer::CreateVisualElementsManifest(test_dir_.GetPath(), version_)); | 280 installer::CreateVisualElementsManifest(test_dir_.GetPath(), version_)); |
| 218 ASSERT_TRUE(base::PathExists(manifest_path_)); | 281 ASSERT_TRUE(base::PathExists(manifest_path_)); |
| 219 | 282 |
| 220 std::string read_manifest; | 283 std::string read_manifest; |
| 221 ASSERT_TRUE(base::ReadFileToString(manifest_path_, &read_manifest)); | 284 ASSERT_TRUE(base::ReadFileToString(manifest_path_, &read_manifest)); |
| 222 | 285 |
| 223 static const char kExpectedManifest[] = | 286 ASSERT_STREQ(expected_manifest_, read_manifest.c_str()); |
| 224 "<Application xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\r\n" | |
| 225 " <VisualElements\r\n" | |
| 226 " ShowNameOnSquare150x150Logo='on'\r\n" | |
| 227 " Square150x150Logo='0.0.0.0\\VisualElements\\Logo.png'\r\n" | |
| 228 " Square70x70Logo='0.0.0.0\\VisualElements\\SmallLogo.png'\r\n" | |
| 229 " Square44x44Logo='0.0.0.0\\VisualElements\\SmallLogo.png'\r\n" | |
| 230 " ForegroundText='light'\r\n" | |
| 231 " BackgroundColor='#212121'/>\r\n" | |
| 232 "</Application>\r\n"; | |
| 233 | |
| 234 ASSERT_STREQ(kExpectedManifest, read_manifest.c_str()); | |
| 235 } | 287 } |
| 236 | 288 |
| 237 TEST_F(InstallShortcutTest, CreateAllShortcuts) { | 289 TEST_F(InstallShortcutTest, CreateAllShortcuts) { |
| 238 installer::CreateOrUpdateShortcuts( | 290 installer::CreateOrUpdateShortcuts( |
| 239 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, | 291 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, |
| 240 installer::INSTALL_SHORTCUT_CREATE_ALL); | 292 installer::INSTALL_SHORTCUT_CREATE_ALL); |
| 241 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); | 293 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); |
| 242 base::win::ValidateShortcut(user_quick_launch_shortcut_, | 294 base::win::ValidateShortcut(user_quick_launch_shortcut_, |
| 243 expected_properties_); | 295 expected_properties_); |
| 244 base::win::ValidateShortcut(user_start_menu_shortcut_, | 296 base::win::ValidateShortcut(user_start_menu_shortcut_, |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 installer::EscapeXmlAttributeValueInSingleQuotes(&val); | 518 installer::EscapeXmlAttributeValueInSingleQuotes(&val); |
| 467 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); | 519 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); |
| 468 } | 520 } |
| 469 | 521 |
| 470 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { | 522 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { |
| 471 base::string16 val(L"Google Chrome"); | 523 base::string16 val(L"Google Chrome"); |
| 472 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; | 524 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; |
| 473 installer::EscapeXmlAttributeValueInSingleQuotes(&val); | 525 installer::EscapeXmlAttributeValueInSingleQuotes(&val); |
| 474 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); | 526 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); |
| 475 } | 527 } |
| OLD | NEW |