| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/install_static/install_details.h" | 5 #include "chrome/install_static/install_details.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "chrome/install_static/install_modes.h" | 10 #include "chrome/install_static/install_modes.h" |
| 11 #include "components/version_info/version_info_values.h" | 11 #include "components/version_info/version_info_values.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 using ::testing::StrEq; | 15 using ::testing::StrEq; |
| 16 | 16 |
| 17 namespace install_static { | 17 namespace install_static { |
| 18 | 18 |
| 19 class FakeInstallDetails : public InstallDetails { | 19 class FakeInstallDetails : public InstallDetails { |
| 20 public: | 20 public: |
| 21 FakeInstallDetails() : InstallDetails(&payload) { | 21 FakeInstallDetails() : InstallDetails(&payload) { |
| 22 constants.size = sizeof(constants); | 22 constants.size = sizeof(constants); |
| 23 constants.install_suffix = L""; | 23 constants.install_suffix = L""; |
| 24 constants.default_channel_name = L""; | 24 constants.default_channel_name = L""; |
| 25 constants.supports_multi_install = true; | 25 constants.supported_multi_install = true; |
| 26 if (kUseGoogleUpdateIntegration) { | 26 if (kUseGoogleUpdateIntegration) { |
| 27 constants.app_guid = L"testguid"; | 27 constants.app_guid = L"testguid"; |
| 28 constants.channel_strategy = ChannelStrategy::FIXED; | 28 constants.channel_strategy = ChannelStrategy::FIXED; |
| 29 } else { | 29 } else { |
| 30 constants.app_guid = L""; | 30 constants.app_guid = L""; |
| 31 constants.channel_strategy = ChannelStrategy::UNSUPPORTED; | 31 constants.channel_strategy = ChannelStrategy::UNSUPPORTED; |
| 32 } | 32 } |
| 33 payload.size = sizeof(payload); | 33 payload.size = sizeof(payload); |
| 34 payload.product_version = product_version.c_str(); | 34 payload.product_version = product_version.c_str(); |
| 35 payload.mode = &constants; | 35 payload.mode = &constants; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 50 std::wstring channel = std::wstring(L"testchannel"); | 50 std::wstring channel = std::wstring(L"testchannel"); |
| 51 std::string product_version = std::string(PRODUCT_VERSION); | 51 std::string product_version = std::string(PRODUCT_VERSION); |
| 52 Payload payload = Payload(); | 52 Payload payload = Payload(); |
| 53 | 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(FakeInstallDetails); | 54 DISALLOW_COPY_AND_ASSIGN(FakeInstallDetails); |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 TEST(InstallDetailsTest, GetClientStateKeyPath) { | 57 TEST(InstallDetailsTest, GetClientStateKeyPath) { |
| 58 FakeInstallDetails details; | 58 FakeInstallDetails details; |
| 59 if (kUseGoogleUpdateIntegration) { | 59 if (kUseGoogleUpdateIntegration) { |
| 60 // Single-install. | 60 EXPECT_THAT(details.GetClientStateKeyPath(), |
| 61 EXPECT_THAT(details.GetClientStateKeyPath(false), | |
| 62 StrEq(L"Software\\Google\\Update\\ClientState\\testguid")); | 61 StrEq(L"Software\\Google\\Update\\ClientState\\testguid")); |
| 63 EXPECT_THAT(details.GetClientStateKeyPath(true), | |
| 64 StrEq(L"Software\\Google\\Update\\ClientState\\testguid")); | |
| 65 | |
| 66 // Multi-install. | |
| 67 details.payload.multi_install = true; | |
| 68 EXPECT_THAT(details.GetClientStateKeyPath(false), | |
| 69 StrEq(L"Software\\Google\\Update\\ClientState\\testguid")); | |
| 70 EXPECT_THAT(details.GetClientStateKeyPath(true), | |
| 71 StrEq(std::wstring(L"Software\\Google\\Update\\ClientState\\") | |
| 72 .append(kBinariesAppGuid))); | |
| 73 } else { | 62 } else { |
| 74 // Single-install. | 63 EXPECT_THAT(details.GetClientStateKeyPath(), |
| 75 EXPECT_THAT(details.GetClientStateKeyPath(false), | |
| 76 StrEq(std::wstring(L"Software\\").append(kProductPathName))); | 64 StrEq(std::wstring(L"Software\\").append(kProductPathName))); |
| 77 EXPECT_THAT(details.GetClientStateKeyPath(true), | |
| 78 StrEq(std::wstring(L"Software\\").append(kProductPathName))); | |
| 79 | |
| 80 // Multi-install. | |
| 81 details.payload.multi_install = true; | |
| 82 EXPECT_THAT(details.GetClientStateKeyPath(false), | |
| 83 StrEq(std::wstring(L"Software\\").append(kProductPathName))); | |
| 84 EXPECT_THAT(details.GetClientStateKeyPath(true), | |
| 85 StrEq(std::wstring(L"Software\\").append(kBinariesPathName))); | |
| 86 } | 65 } |
| 87 } | 66 } |
| 88 | 67 |
| 89 TEST(InstallDetailsTest, GetClientStateMediumKeyPath) { | 68 TEST(InstallDetailsTest, GetClientStateMediumKeyPath) { |
| 90 FakeInstallDetails details; | 69 FakeInstallDetails details; |
| 91 if (kUseGoogleUpdateIntegration) { | 70 if (kUseGoogleUpdateIntegration) { |
| 92 // Single-install. | |
| 93 EXPECT_THAT( | 71 EXPECT_THAT( |
| 94 details.GetClientStateMediumKeyPath(false), | 72 details.GetClientStateMediumKeyPath(), |
| 95 StrEq(L"Software\\Google\\Update\\ClientStateMedium\\testguid")); | 73 StrEq(L"Software\\Google\\Update\\ClientStateMedium\\testguid")); |
| 96 EXPECT_THAT( | |
| 97 details.GetClientStateMediumKeyPath(true), | |
| 98 StrEq(L"Software\\Google\\Update\\ClientStateMedium\\testguid")); | |
| 99 | |
| 100 // Multi-install. | |
| 101 details.payload.multi_install = true; | |
| 102 EXPECT_THAT( | |
| 103 details.GetClientStateMediumKeyPath(false), | |
| 104 StrEq(L"Software\\Google\\Update\\ClientStateMedium\\testguid")); | |
| 105 EXPECT_THAT( | |
| 106 details.GetClientStateMediumKeyPath(true), | |
| 107 StrEq(std::wstring(L"Software\\Google\\Update\\ClientStateMedium\\") | |
| 108 .append(kBinariesAppGuid))); | |
| 109 } else { | 74 } else { |
| 110 // Single-install. | 75 EXPECT_THAT(details.GetClientStateKeyPath(), |
| 111 EXPECT_THAT(details.GetClientStateKeyPath(false), | |
| 112 StrEq(std::wstring(L"Software\\").append(kProductPathName))); | 76 StrEq(std::wstring(L"Software\\").append(kProductPathName))); |
| 113 EXPECT_THAT(details.GetClientStateKeyPath(true), | |
| 114 StrEq(std::wstring(L"Software\\").append(kProductPathName))); | |
| 115 | |
| 116 // Multi-install. | |
| 117 details.payload.multi_install = true; | |
| 118 EXPECT_THAT(details.GetClientStateKeyPath(false), | |
| 119 StrEq(std::wstring(L"Software\\").append(kProductPathName))); | |
| 120 EXPECT_THAT(details.GetClientStateKeyPath(true), | |
| 121 StrEq(std::wstring(L"Software\\").append(kBinariesPathName))); | |
| 122 } | 77 } |
| 123 } | 78 } |
| 124 | 79 |
| 125 TEST(InstallDetailsTest, VersionMismatch) { | 80 TEST(InstallDetailsTest, VersionMismatch) { |
| 126 // All is well to begin with. | 81 // All is well to begin with. |
| 127 EXPECT_FALSE(FakeInstallDetails().VersionMismatch()); | 82 EXPECT_FALSE(FakeInstallDetails().VersionMismatch()); |
| 128 | 83 |
| 129 // Bad product version. | 84 // Bad product version. |
| 130 { | 85 { |
| 131 FakeInstallDetails details; | 86 FakeInstallDetails details; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 142 | 97 |
| 143 // Bad InstallConstants size. | 98 // Bad InstallConstants size. |
| 144 { | 99 { |
| 145 FakeInstallDetails details; | 100 FakeInstallDetails details; |
| 146 details.set_mode_size(sizeof(InstallConstants) + 1); | 101 details.set_mode_size(sizeof(InstallConstants) + 1); |
| 147 EXPECT_TRUE(details.VersionMismatch()); | 102 EXPECT_TRUE(details.VersionMismatch()); |
| 148 } | 103 } |
| 149 } | 104 } |
| 150 | 105 |
| 151 } // namespace install_static | 106 } // namespace install_static |
| OLD | NEW |