Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(492)

Side by Side Diff: components/update_client/utils_unittest.cc

Issue 2498873003: Refactor how the updater state data is serialized in update checks. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/update_client/utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
6 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "components/update_client/updater_state.h"
7 #include "components/update_client/utils.h" 9 #include "components/update_client/utils.h"
8 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
9 #include "url/gurl.h" 11 #include "url/gurl.h"
10 12
11 using std::string; 13 using std::string;
12 14
13 namespace { 15 namespace {
14 16
15 base::FilePath MakeTestFilePath(const char* file) { 17 base::FilePath MakeTestFilePath(const char* file) {
16 base::FilePath path; 18 base::FilePath path;
17 PathService::Get(base::DIR_SOURCE_ROOT, &path); 19 PathService::Get(base::DIR_SOURCE_ROOT, &path);
18 return path.AppendASCII("components/test/data/update_client") 20 return path.AppendASCII("components/test/data/update_client")
19 .AppendASCII(file); 21 .AppendASCII(file);
20 } 22 }
21 23
22 } // namespace 24 } // namespace
23 25
24 namespace update_client { 26 namespace update_client {
25 27
26 TEST(UpdateClientUtils, BuildProtocolRequest_ProdIdVersion) { 28 TEST(UpdateClientUtils, BuildProtocolRequest_ProdIdVersion) {
27 // Verifies that |prod_id| and |version| are serialized. 29 // Verifies that |prod_id| and |version| are serialized.
28 const string request = 30 const string request = BuildProtocolRequest("some_prod_id", "1.0", "", "", "",
29 BuildProtocolRequest("some_prod_id", "1.0", "", "", "", "", "", ""); 31 "", "", "", nullptr);
30 EXPECT_NE(string::npos, request.find(" version=\"some_prod_id-1.0\" ")); 32 EXPECT_NE(string::npos, request.find(" version=\"some_prod_id-1.0\" "));
31 } 33 }
32 34
33 TEST(UpdateClientUtils, BuildProtocolRequest_DownloadPreference) { 35 TEST(UpdateClientUtils, BuildProtocolRequest_DownloadPreference) {
34 // Verifies that an empty |download_preference| is not serialized. 36 // Verifies that an empty |download_preference| is not serialized.
35 const string request_no_dlpref = 37 const string request_no_dlpref =
36 BuildProtocolRequest("", "", "", "", "", "", "", ""); 38 BuildProtocolRequest("", "", "", "", "", "", "", "", nullptr);
37 EXPECT_EQ(string::npos, request_no_dlpref.find(" dlpref=")); 39 EXPECT_EQ(string::npos, request_no_dlpref.find(" dlpref="));
38 40
39 // Verifies that |download_preference| is serialized. 41 // Verifies that |download_preference| is serialized.
40 const string request_with_dlpref = 42 const string request_with_dlpref =
41 BuildProtocolRequest("", "", "", "", "", "some pref", "", ""); 43 BuildProtocolRequest("", "", "", "", "", "some pref", "", "", nullptr);
42 EXPECT_NE(string::npos, request_with_dlpref.find(" dlpref=\"some pref\"")); 44 EXPECT_NE(string::npos, request_with_dlpref.find(" dlpref=\"some pref\""));
43 } 45 }
44 46
47 TEST(UpdateClientUtils, BuildProtocolRequest_UpdaterState) {}
48
45 TEST(UpdateClientUtils, VerifyFileHash256) { 49 TEST(UpdateClientUtils, VerifyFileHash256) {
46 EXPECT_TRUE(VerifyFileHash256( 50 EXPECT_TRUE(VerifyFileHash256(
47 MakeTestFilePath("jebgalgnebhfojomionfpkfelancnnkf.crx"), 51 MakeTestFilePath("jebgalgnebhfojomionfpkfelancnnkf.crx"),
48 std::string( 52 std::string(
49 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87"))); 53 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87")));
50 54
51 EXPECT_FALSE(VerifyFileHash256( 55 EXPECT_FALSE(VerifyFileHash256(
52 MakeTestFilePath("jebgalgnebhfojomionfpkfelancnnkf.crx"), 56 MakeTestFilePath("jebgalgnebhfojomionfpkfelancnnkf.crx"),
53 std::string(""))); 57 std::string("")));
54 58
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 urls.assign(std::begin(test4), std::end(test4)); 163 urls.assign(std::begin(test4), std::end(test4));
160 RemoveUnsecureUrls(&urls); 164 RemoveUnsecureUrls(&urls);
161 EXPECT_EQ(0u, urls.size()); 165 EXPECT_EQ(0u, urls.size());
162 166
163 const GURL test5[] = {GURL("http://foo"), GURL("http://bar")}; 167 const GURL test5[] = {GURL("http://foo"), GURL("http://bar")};
164 urls.assign(std::begin(test5), std::end(test5)); 168 urls.assign(std::begin(test5), std::end(test5));
165 RemoveUnsecureUrls(&urls); 169 RemoveUnsecureUrls(&urls);
166 EXPECT_EQ(0u, urls.size()); 170 EXPECT_EQ(0u, urls.size());
167 } 171 }
168 172
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
169 } // namespace update_client 204 } // namespace update_client
OLDNEW
« no previous file with comments | « components/update_client/utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698