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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/memory/ptr_util.h" | |
7 #include "base/path_service.h" | 6 #include "base/path_service.h" |
8 #include "components/update_client/updater_state.h" | 7 #include "components/update_client/updater_state.h" |
9 #include "components/update_client/utils.h" | 8 #include "components/update_client/utils.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "url/gurl.h" | 10 #include "url/gurl.h" |
12 | 11 |
13 using std::string; | 12 using std::string; |
14 | 13 |
15 namespace { | 14 namespace { |
16 | 15 |
17 base::FilePath MakeTestFilePath(const char* file) { | 16 base::FilePath MakeTestFilePath(const char* file) { |
18 base::FilePath path; | 17 base::FilePath path; |
19 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 18 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
20 return path.AppendASCII("components/test/data/update_client") | 19 return path.AppendASCII("components/test/data/update_client") |
21 .AppendASCII(file); | 20 .AppendASCII(file); |
22 } | 21 } |
23 | 22 |
24 } // namespace | 23 } // namespace |
25 | 24 |
26 namespace update_client { | 25 namespace update_client { |
27 | 26 |
28 TEST(UpdateClientUtils, BuildProtocolRequest_ProdIdVersion) { | |
29 // Verifies that |prod_id| and |version| are serialized. | |
30 const string request = BuildProtocolRequest("some_prod_id", "1.0", "", "", "", | |
31 "", "", "", nullptr); | |
32 EXPECT_NE(string::npos, request.find(" version=\"some_prod_id-1.0\" ")); | |
33 } | |
34 | |
35 TEST(UpdateClientUtils, BuildProtocolRequest_DownloadPreference) { | |
36 // Verifies that an empty |download_preference| is not serialized. | |
37 const string request_no_dlpref = | |
38 BuildProtocolRequest("", "", "", "", "", "", "", "", nullptr); | |
39 EXPECT_EQ(string::npos, request_no_dlpref.find(" dlpref=")); | |
40 | |
41 // Verifies that |download_preference| is serialized. | |
42 const string request_with_dlpref = | |
43 BuildProtocolRequest("", "", "", "", "", "some pref", "", "", nullptr); | |
44 EXPECT_NE(string::npos, request_with_dlpref.find(" dlpref=\"some pref\"")); | |
45 } | |
46 | |
47 TEST(UpdateClientUtils, BuildProtocolRequest_UpdaterState) {} | |
48 | |
49 TEST(UpdateClientUtils, VerifyFileHash256) { | 27 TEST(UpdateClientUtils, VerifyFileHash256) { |
50 EXPECT_TRUE(VerifyFileHash256( | 28 EXPECT_TRUE(VerifyFileHash256( |
51 MakeTestFilePath("jebgalgnebhfojomionfpkfelancnnkf.crx"), | 29 MakeTestFilePath("jebgalgnebhfojomionfpkfelancnnkf.crx"), |
52 std::string( | 30 std::string( |
53 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87"))); | 31 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87"))); |
54 | 32 |
55 EXPECT_FALSE(VerifyFileHash256( | 33 EXPECT_FALSE(VerifyFileHash256( |
56 MakeTestFilePath("jebgalgnebhfojomionfpkfelancnnkf.crx"), | 34 MakeTestFilePath("jebgalgnebhfojomionfpkfelancnnkf.crx"), |
57 std::string(""))); | 35 std::string(""))); |
58 | 36 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 urls.assign(std::begin(test4), std::end(test4)); | 141 urls.assign(std::begin(test4), std::end(test4)); |
164 RemoveUnsecureUrls(&urls); | 142 RemoveUnsecureUrls(&urls); |
165 EXPECT_EQ(0u, urls.size()); | 143 EXPECT_EQ(0u, urls.size()); |
166 | 144 |
167 const GURL test5[] = {GURL("http://foo"), GURL("http://bar")}; | 145 const GURL test5[] = {GURL("http://foo"), GURL("http://bar")}; |
168 urls.assign(std::begin(test5), std::end(test5)); | 146 urls.assign(std::begin(test5), std::end(test5)); |
169 RemoveUnsecureUrls(&urls); | 147 RemoveUnsecureUrls(&urls); |
170 EXPECT_EQ(0u, urls.size()); | 148 EXPECT_EQ(0u, urls.size()); |
171 } | 149 } |
172 | 150 |
173 TEST(UpdateClientUtils, BuildProtocolRequestUpdaterStateAttributes) { | |
174 // When no updater state is provided, then check that the elements and | |
175 // attributes related to the updater state are not serialized. | |
176 std::string request = | |
177 BuildProtocolRequest("", "", "", "", "", "", "", "", nullptr).c_str(); | |
178 EXPECT_EQ(std::string::npos, request.find(" domainjoined")); | |
179 EXPECT_EQ(std::string::npos, request.find("<updater")); | |
180 | |
181 UpdaterState::Attributes attributes; | |
182 attributes["domainjoined"] = "1"; | |
183 attributes["name"] = "Omaha"; | |
184 attributes["version"] = "1.2.3.4"; | |
185 attributes["laststarted"] = "1"; | |
186 attributes["lastchecked"] = "2"; | |
187 attributes["autoupdatecheckenabled"] = "0"; | |
188 attributes["updatepolicy"] = "-1"; | |
189 request = BuildProtocolRequest( | |
190 "", "", "", "", "", "", "", "", | |
191 base::MakeUnique<UpdaterState::Attributes>(attributes)); | |
192 EXPECT_NE(std::string::npos, request.find(" domainjoined=\"1\"")); | |
193 const std::string updater_element = | |
194 "<updater autoupdatecheckenabled=\"0\" " | |
195 "lastchecked=\"2\" laststarted=\"1\" name=\"Omaha\" " | |
196 "updatepolicy=\"-1\" version=\"1.2.3.4\"/>"; | |
197 #if defined(GOOGLE_CHROME_BUILD) | |
198 EXPECT_NE(std::string::npos, request.find(updater_element)); | |
199 #else | |
200 EXPECT_EQ(std::string::npos, request.find(updater_element)); | |
201 #endif // GOOGLE_CHROME_BUILD | |
202 } | |
203 | |
204 } // namespace update_client | 151 } // namespace update_client |
OLD | NEW |