Chromium Code Reviews| 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 class CreateVisualElementsManifestTest |
| 42 : public ::testing::TestWithParam< | |
| 43 std::tuple<install_static::InstallConstantIndex, const char*>> { | |
|
robertshield
2017/02/20 19:11:16
It would be cool if the parameters were described
grt (UTC plus 2)
2017/02/21 13:21:16
Done.
| |
| 39 protected: | 44 protected: |
| 45 CreateVisualElementsManifestTest() | |
| 46 : scoped_install_details_(false /* !system_level */, | |
| 47 std::get<0>(GetParam())), | |
| 48 expected_manifest_(std::get<1>(GetParam())), | |
| 49 version_("0.0.0.0") {} | |
| 50 | |
| 40 void SetUp() override { | 51 void SetUp() override { |
| 41 // Create a temp directory for testing. | 52 // Create a temp directory for testing. |
| 42 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 53 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
| 43 | 54 |
| 44 version_ = base::Version("0.0.0.0"); | |
| 45 | |
| 46 version_dir_ = test_dir_.GetPath().AppendASCII(version_.GetString()); | 55 version_dir_ = test_dir_.GetPath().AppendASCII(version_.GetString()); |
| 47 ASSERT_TRUE(base::CreateDirectory(version_dir_)); | 56 ASSERT_TRUE(base::CreateDirectory(version_dir_)); |
| 48 | 57 |
| 49 manifest_path_ = | 58 manifest_path_ = |
| 50 test_dir_.GetPath().Append(installer::kVisualElementsManifest); | 59 test_dir_.GetPath().Append(installer::kVisualElementsManifest); |
| 51 } | 60 } |
| 52 | 61 |
| 53 void TearDown() override { | 62 void TearDown() override { |
| 54 // Clean up test directory manually so we can fail if it leaks. | 63 // Clean up test directory manually so we can fail if it leaks. |
| 55 ASSERT_TRUE(test_dir_.Delete()); | 64 ASSERT_TRUE(test_dir_.Delete()); |
| 56 } | 65 } |
| 57 | 66 |
| 67 // InstallDetails for this test run. | |
| 68 install_static::ScopedInstallDetails scoped_install_details_; | |
| 69 | |
| 70 // The expected contents of the manifest. | |
| 71 const char* const expected_manifest_; | |
| 72 | |
| 73 // A dummy version number used to create the version directory. | |
| 74 const base::Version version_; | |
| 75 | |
| 58 // The temporary directory used to contain the test operations. | 76 // The temporary directory used to contain the test operations. |
| 59 base::ScopedTempDir test_dir_; | 77 base::ScopedTempDir test_dir_; |
| 60 | 78 |
| 61 // A dummy version number used to create the version directory. | |
| 62 base::Version version_; | |
| 63 | |
| 64 // The path to |test_dir_|\|version_|. | 79 // The path to |test_dir_|\|version_|. |
| 65 base::FilePath version_dir_; | 80 base::FilePath version_dir_; |
| 66 | 81 |
| 67 // The path to VisualElementsManifest.xml. | 82 // The path to VisualElementsManifest.xml. |
| 68 base::FilePath manifest_path_; | 83 base::FilePath manifest_path_; |
| 84 | |
| 85 private: | |
| 86 DISALLOW_COPY_AND_ASSIGN(CreateVisualElementsManifestTest); | |
| 69 }; | 87 }; |
| 70 | 88 |
| 89 constexpr char kExpectedPrimaryManifest[] = | |
| 90 "<Application xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\r\n" | |
| 91 " <VisualElements\r\n" | |
| 92 " ShowNameOnSquare150x150Logo='on'\r\n" | |
| 93 " Square150x150Logo='0.0.0.0\\VisualElements\\Logo.png'\r\n" | |
| 94 " Square70x70Logo='0.0.0.0\\VisualElements\\SmallLogo.png'\r\n" | |
| 95 " Square44x44Logo='0.0.0.0\\VisualElements\\SmallLogo.png'\r\n" | |
| 96 " ForegroundText='light'\r\n" | |
| 97 " BackgroundColor='#212121'/>\r\n" | |
| 98 "</Application>\r\n"; | |
| 99 | |
| 100 #if defined(GOOGLE_CHROME_BUILD) | |
| 101 constexpr char kExpectedCanaryManifest[] = | |
| 102 "<Application xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\r\n" | |
| 103 " <VisualElements\r\n" | |
| 104 " ShowNameOnSquare150x150Logo='on'\r\n" | |
| 105 " Square150x150Logo='0.0.0.0\\VisualElements\\LogoCanary.png'\r\n" | |
| 106 " Square70x70Logo='0.0.0.0\\VisualElements\\SmallLogoCanary.png'\r\n" | |
| 107 " Square44x44Logo='0.0.0.0\\VisualElements\\SmallLogoCanary.png'\r\n" | |
| 108 " ForegroundText='light'\r\n" | |
| 109 " BackgroundColor='#212121'/>\r\n" | |
| 110 "</Application>\r\n"; | |
| 111 | |
| 112 INSTANTIATE_TEST_CASE_P( | |
| 113 GoogleChrome, | |
| 114 CreateVisualElementsManifestTest, | |
| 115 testing::Combine(testing::Values(install_static::STABLE_INDEX), | |
| 116 testing::Values(kExpectedPrimaryManifest))); | |
| 117 INSTANTIATE_TEST_CASE_P( | |
| 118 CanaryChrome, | |
| 119 CreateVisualElementsManifestTest, | |
| 120 testing::Combine(testing::Values(install_static::CANARY_INDEX), | |
| 121 testing::Values(kExpectedCanaryManifest))); | |
| 122 #else | |
| 123 INSTANTIATE_TEST_CASE_P( | |
| 124 Chromium, | |
| 125 CreateVisualElementsManifestTest, | |
| 126 testing::Combine(testing::Values(install_static::CHROMIUM_INDEX), | |
| 127 testing::Values(kExpectedPrimaryManifest))); | |
| 128 #endif | |
| 129 | |
| 71 class InstallShortcutTest : public testing::Test { | 130 class InstallShortcutTest : public testing::Test { |
| 72 protected: | 131 protected: |
| 73 void SetUp() override { | 132 void SetUp() override { |
| 74 EXPECT_EQ(S_OK, CoInitialize(NULL)); | 133 EXPECT_EQ(S_OK, CoInitialize(NULL)); |
| 75 | 134 |
| 76 dist_ = BrowserDistribution::GetDistribution(); | 135 dist_ = BrowserDistribution::GetDistribution(); |
| 77 ASSERT_TRUE(dist_ != NULL); | 136 ASSERT_TRUE(dist_ != NULL); |
| 78 product_.reset(new installer::Product(dist_)); | 137 product_.reset(new installer::Product(dist_)); |
| 79 | 138 |
| 80 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 139 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_; | 254 base::FilePath user_start_menu_subdir_shortcut_; |
| 196 base::FilePath system_desktop_shortcut_; | 255 base::FilePath system_desktop_shortcut_; |
| 197 base::FilePath system_start_menu_shortcut_; | 256 base::FilePath system_start_menu_shortcut_; |
| 198 base::FilePath system_start_menu_subdir_shortcut_; | 257 base::FilePath system_start_menu_subdir_shortcut_; |
| 199 }; | 258 }; |
| 200 | 259 |
| 201 } // namespace | 260 } // namespace |
| 202 | 261 |
| 203 // Test that VisualElementsManifest.xml is not created when VisualElements are | 262 // Test that VisualElementsManifest.xml is not created when VisualElements are |
| 204 // not present. | 263 // not present. |
| 205 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { | 264 TEST_P(CreateVisualElementsManifestTest, VisualElementsManifestNotCreated) { |
| 206 ASSERT_TRUE( | 265 ASSERT_TRUE( |
| 207 installer::CreateVisualElementsManifest(test_dir_.GetPath(), version_)); | 266 installer::CreateVisualElementsManifest(test_dir_.GetPath(), version_)); |
| 208 ASSERT_FALSE(base::PathExists(manifest_path_)); | 267 ASSERT_FALSE(base::PathExists(manifest_path_)); |
| 209 } | 268 } |
| 210 | 269 |
| 211 // Test that VisualElementsManifest.xml is created with the correct content when | 270 // Test that VisualElementsManifest.xml is created with the correct content when |
| 212 // VisualElements are present. | 271 // VisualElements are present. |
| 213 TEST_F(CreateVisualElementsManifestTest, VisualElementsManifestCreated) { | 272 TEST_P(CreateVisualElementsManifestTest, VisualElementsManifestCreated) { |
| 214 ASSERT_TRUE(base::CreateDirectory( | 273 ASSERT_TRUE(base::CreateDirectory( |
| 215 version_dir_.Append(installer::kVisualElements))); | 274 version_dir_.Append(installer::kVisualElements))); |
| 216 ASSERT_TRUE( | 275 ASSERT_TRUE( |
| 217 installer::CreateVisualElementsManifest(test_dir_.GetPath(), version_)); | 276 installer::CreateVisualElementsManifest(test_dir_.GetPath(), version_)); |
| 218 ASSERT_TRUE(base::PathExists(manifest_path_)); | 277 ASSERT_TRUE(base::PathExists(manifest_path_)); |
| 219 | 278 |
| 220 std::string read_manifest; | 279 std::string read_manifest; |
| 221 ASSERT_TRUE(base::ReadFileToString(manifest_path_, &read_manifest)); | 280 ASSERT_TRUE(base::ReadFileToString(manifest_path_, &read_manifest)); |
| 222 | 281 |
| 223 static const char kExpectedManifest[] = | 282 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 } | 283 } |
| 236 | 284 |
| 237 TEST_F(InstallShortcutTest, CreateAllShortcuts) { | 285 TEST_F(InstallShortcutTest, CreateAllShortcuts) { |
| 238 installer::CreateOrUpdateShortcuts( | 286 installer::CreateOrUpdateShortcuts( |
| 239 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, | 287 chrome_exe_, *product_, *prefs_, installer::CURRENT_USER, |
| 240 installer::INSTALL_SHORTCUT_CREATE_ALL); | 288 installer::INSTALL_SHORTCUT_CREATE_ALL); |
| 241 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); | 289 base::win::ValidateShortcut(user_desktop_shortcut_, expected_properties_); |
| 242 base::win::ValidateShortcut(user_quick_launch_shortcut_, | 290 base::win::ValidateShortcut(user_quick_launch_shortcut_, |
| 243 expected_properties_); | 291 expected_properties_); |
| 244 base::win::ValidateShortcut(user_start_menu_shortcut_, | 292 base::win::ValidateShortcut(user_start_menu_shortcut_, |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 installer::EscapeXmlAttributeValueInSingleQuotes(&val); | 514 installer::EscapeXmlAttributeValueInSingleQuotes(&val); |
| 467 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); | 515 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); |
| 468 } | 516 } |
| 469 | 517 |
| 470 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { | 518 TEST(EscapeXmlAttributeValueTest, DontEscapeNormalValue) { |
| 471 base::string16 val(L"Google Chrome"); | 519 base::string16 val(L"Google Chrome"); |
| 472 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; | 520 static const wchar_t kExpectedEscapedVal[] = L"Google Chrome"; |
| 473 installer::EscapeXmlAttributeValueInSingleQuotes(&val); | 521 installer::EscapeXmlAttributeValueInSingleQuotes(&val); |
| 474 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); | 522 ASSERT_STREQ(kExpectedEscapedVal, val.c_str()); |
| 475 } | 523 } |
| OLD | NEW |