OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/install_static/install_details.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/macros.h" | |
10 #include "chrome/install_static/install_modes.h" | |
11 #include "components/version_info/version_info_values.h" | |
12 #include "testing/gmock/include/gmock/gmock.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 using ::testing::StrEq; | |
16 | |
17 namespace install_static { | |
18 | |
19 class FakeInstallDetails : public InstallDetails { | |
20 public: | |
21 FakeInstallDetails() : InstallDetails(&payload) { | |
22 constants.size = sizeof(constants); | |
23 constants.install_suffix = L""; | |
24 constants.default_channel_name = L""; | |
25 constants.supports_multi_install = true; | |
26 if (kUseGoogleUpdateIntegration) { | |
27 constants.app_guid = L"testguid"; | |
28 constants.channel_strategy = ChannelStrategy::FIXED; | |
29 } else { | |
30 constants.app_guid = L""; | |
31 constants.channel_strategy = ChannelStrategy::UNSUPPORTED; | |
32 } | |
33 payload.size = sizeof(payload); | |
34 payload.product_version = product_version.c_str(); | |
35 payload.mode = &constants; | |
36 payload.channel = channel.c_str(); | |
37 payload.channel_length = channel.length(); | |
38 } | |
39 | |
40 void set_product_version(const char* version) { | |
41 product_version.assign(version); | |
42 payload.product_version = product_version.c_str(); | |
43 } | |
44 | |
45 void set_payload_size(size_t size) { payload.size = size; } | |
46 | |
47 void set_mode_size(size_t size) { constants.size = size; } | |
48 | |
49 InstallConstants constants = InstallConstants(); | |
50 std::wstring channel = std::wstring(L"testchannel"); | |
51 std::string product_version = std::string(PRODUCT_VERSION); | |
52 Payload payload = Payload(); | |
53 | |
54 DISALLOW_COPY_AND_ASSIGN(FakeInstallDetails); | |
55 }; | |
56 | |
57 TEST(InstallDetailsTest, GetClientStateKeyPath) { | |
58 FakeInstallDetails details; | |
59 if (kUseGoogleUpdateIntegration) { | |
60 // Single-install. | |
61 EXPECT_THAT(details.GetClientStateKeyPath(false), | |
62 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 { | |
74 // Single-install. | |
75 EXPECT_THAT(details.GetClientStateKeyPath(false), | |
76 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 } | |
87 } | |
88 | |
89 TEST(InstallDetailsTest, GetClientStateMediumKeyPath) { | |
90 FakeInstallDetails details; | |
91 if (kUseGoogleUpdateIntegration) { | |
92 // Single-install. | |
93 EXPECT_THAT( | |
94 details.GetClientStateMediumKeyPath(false), | |
95 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 { | |
110 // Single-install. | |
111 EXPECT_THAT(details.GetClientStateKeyPath(false), | |
112 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 } | |
123 } | |
124 | |
125 TEST(InstallDetailsTest, VersionMismatch) { | |
126 // All is well to begin with. | |
127 EXPECT_FALSE(FakeInstallDetails().VersionMismatch()); | |
128 | |
129 // Bad product version. | |
130 { | |
131 FakeInstallDetails details; | |
132 details.set_product_version("0.1.2.3"); | |
133 EXPECT_TRUE(details.VersionMismatch()); | |
134 } | |
135 | |
136 // Bad Payload size. | |
137 { | |
138 FakeInstallDetails details; | |
139 details.set_payload_size(sizeof(InstallDetails::Payload) + 1); | |
140 EXPECT_TRUE(details.VersionMismatch()); | |
141 } | |
142 | |
143 // Bad InstallConstants size. | |
144 { | |
145 FakeInstallDetails details; | |
146 details.set_mode_size(sizeof(InstallConstants) + 1); | |
147 EXPECT_TRUE(details.VersionMismatch()); | |
148 } | |
149 } | |
150 | |
151 } // namespace install_static | |
OLD | NEW |