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/path_service.h" | 6 #include "base/path_service.h" |
7 #include "components/update_client/utils.h" | 7 #include "components/update_client/utils.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "url/gurl.h" | 9 #include "url/gurl.h" |
10 | 10 |
11 using std::string; | 11 using std::string; |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 base::FilePath MakeTestFilePath(const char* file) { | 15 base::FilePath MakeTestFilePath(const char* file) { |
16 base::FilePath path; | 16 base::FilePath path; |
17 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 17 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
18 return path.AppendASCII("components/test/data/update_client") | 18 return path.AppendASCII("components/test/data/update_client") |
19 .AppendASCII(file); | 19 .AppendASCII(file); |
20 } | 20 } |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 namespace update_client { | 24 namespace update_client { |
25 | 25 |
| 26 TEST(UpdateClientUtils, BuildProtocolRequest_ProdIdVersion) { |
| 27 // Verifies that |prod_id| and |version| are serialized. |
| 28 const string request = |
| 29 BuildProtocolRequest("some_prod_id", "1.0", "", "", "", "", "", ""); |
| 30 EXPECT_NE(string::npos, request.find(" version=\"some_prod_id-1.0\" ")); |
| 31 } |
| 32 |
26 TEST(UpdateClientUtils, BuildProtocolRequest_DownloadPreference) { | 33 TEST(UpdateClientUtils, BuildProtocolRequest_DownloadPreference) { |
27 const string emptystr; | |
28 | |
29 // Verifies that an empty |download_preference| is not serialized. | 34 // Verifies that an empty |download_preference| is not serialized. |
30 const string request_no_dlpref = BuildProtocolRequest( | 35 const string request_no_dlpref = |
31 emptystr, emptystr, emptystr, emptystr, emptystr, emptystr, emptystr); | 36 BuildProtocolRequest("", "", "", "", "", "", "", ""); |
32 EXPECT_EQ(string::npos, request_no_dlpref.find(" dlpref=")); | 37 EXPECT_EQ(string::npos, request_no_dlpref.find(" dlpref=")); |
33 | 38 |
34 // Verifies that |download_preference| is serialized. | 39 // Verifies that |download_preference| is serialized. |
35 const string request_with_dlpref = BuildProtocolRequest( | 40 const string request_with_dlpref = |
36 emptystr, emptystr, emptystr, emptystr, "some pref", emptystr, emptystr); | 41 BuildProtocolRequest("", "", "", "", "", "some pref", "", ""); |
37 EXPECT_NE(string::npos, request_with_dlpref.find(" dlpref=\"some pref\"")); | 42 EXPECT_NE(string::npos, request_with_dlpref.find(" dlpref=\"some pref\"")); |
38 } | 43 } |
39 | 44 |
40 TEST(UpdateClientUtils, VerifyFileHash256) { | 45 TEST(UpdateClientUtils, VerifyFileHash256) { |
41 EXPECT_TRUE(VerifyFileHash256( | 46 EXPECT_TRUE(VerifyFileHash256( |
42 MakeTestFilePath("jebgalgnebhfojomionfpkfelancnnkf.crx"), | 47 MakeTestFilePath("jebgalgnebhfojomionfpkfelancnnkf.crx"), |
43 std::string( | 48 std::string( |
44 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87"))); | 49 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87"))); |
45 | 50 |
46 EXPECT_FALSE(VerifyFileHash256( | 51 EXPECT_FALSE(VerifyFileHash256( |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 RemoveUnsecureUrls(&urls); | 160 RemoveUnsecureUrls(&urls); |
156 EXPECT_EQ(0u, urls.size()); | 161 EXPECT_EQ(0u, urls.size()); |
157 | 162 |
158 const GURL test5[] = {GURL("http://foo"), GURL("http://bar")}; | 163 const GURL test5[] = {GURL("http://foo"), GURL("http://bar")}; |
159 urls.assign(std::begin(test5), std::end(test5)); | 164 urls.assign(std::begin(test5), std::end(test5)); |
160 RemoveUnsecureUrls(&urls); | 165 RemoveUnsecureUrls(&urls); |
161 EXPECT_EQ(0u, urls.size()); | 166 EXPECT_EQ(0u, urls.size()); |
162 } | 167 } |
163 | 168 |
164 } // namespace update_client | 169 } // namespace update_client |
OLD | NEW |