| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "components/payments/content/android/utility/payment_manifest_parser.h" | 5 #include "components/payments/content/utility/payment_manifest_parser.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 namespace payments { | 9 namespace payments { |
| 10 namespace { | 10 namespace { |
| 11 | 11 |
| 12 void ExpectUnableToParse(const std::string& input) { | 12 void ExpectUnableToParse(const std::string& input) { |
| 13 std::vector<mojom::PaymentManifestSectionPtr> actual_output = | 13 std::vector<mojom::PaymentManifestSectionPtr> actual_output = |
| 14 PaymentManifestParser::ParseIntoVector(input); | 14 PaymentManifestParser::ParseIntoVector(input); |
| 15 EXPECT_TRUE(actual_output.empty()); | 15 EXPECT_TRUE(actual_output.empty()); |
| 16 } | 16 } |
| 17 | 17 |
| 18 void ExpectParsed( | 18 void ExpectParsed( |
| 19 const std::string& input, | 19 const std::string& input, |
| 20 const std::string& expected_package_name, | 20 const std::string& expected_package_name, |
| 21 int expected_version, | 21 int expected_version, |
| 22 const std::vector<std::vector<uint8_t>>& expected_fingerprints = {}) { | 22 const std::vector<std::vector<uint8_t>>& expected_fingerprints) { |
| 23 std::vector<mojom::PaymentManifestSectionPtr> actual_output = | 23 std::vector<mojom::PaymentManifestSectionPtr> actual_output = |
| 24 PaymentManifestParser::ParseIntoVector(input); | 24 PaymentManifestParser::ParseIntoVector(input); |
| 25 ASSERT_EQ(1U, actual_output.size()); | 25 ASSERT_EQ(1U, actual_output.size()); |
| 26 EXPECT_EQ(expected_package_name, actual_output.front()->package_name); | 26 EXPECT_EQ(expected_package_name, actual_output.front()->package_name); |
| 27 EXPECT_EQ(expected_version, actual_output.front()->version); | 27 EXPECT_EQ(expected_version, actual_output.front()->version); |
| 28 EXPECT_EQ(expected_fingerprints, | 28 EXPECT_EQ(expected_fingerprints, |
| 29 actual_output.front()->sha256_cert_fingerprints); | 29 actual_output.front()->sha256_cert_fingerprints); |
| 30 } | 30 } |
| 31 | 31 |
| 32 TEST(PaymentManifestParserTest, NullContentIsMalformed) { | 32 TEST(PaymentManifestParserTest, NullContentIsMalformed) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 60 TEST(PaymentManifestParserTest, | 60 TEST(PaymentManifestParserTest, |
| 61 ListOfEmptyDictionariesAndroidSectionIsMalformed) { | 61 ListOfEmptyDictionariesAndroidSectionIsMalformed) { |
| 62 ExpectUnableToParse("{\"android\": [{}]}"); | 62 ExpectUnableToParse("{\"android\": [{}]}"); |
| 63 } | 63 } |
| 64 | 64 |
| 65 TEST(PaymentManifestParserTest, NoPackageNameIsMalformed) { | 65 TEST(PaymentManifestParserTest, NoPackageNameIsMalformed) { |
| 66 ExpectUnableToParse("{\"android\": [{\"version\": 3}]}"); | 66 ExpectUnableToParse("{\"android\": [{\"version\": 3}]}"); |
| 67 } | 67 } |
| 68 | 68 |
| 69 TEST(PaymentManifestParserTest, OnlyPackageNameIsWellFormed) { | 69 TEST(PaymentManifestParserTest, OnlyPackageNameIsWellFormed) { |
| 70 ExpectParsed("{\"android\": [{\"package\": \"*\"}]}", "*", 0); | 70 ExpectParsed("{\"android\": [{\"package\": \"*\"}]}", "*", 0, |
| 71 std::vector<std::vector<uint8_t>>()); |
| 71 } | 72 } |
| 72 | 73 |
| 73 TEST(PaymentManifestParserTest, WellFormed) { | 74 TEST(PaymentManifestParserTest, WellFormed) { |
| 74 ExpectParsed( | 75 ExpectParsed( |
| 75 "{\"android\": [{" | 76 "{\"android\": [{" |
| 76 "\"package\": \"com.bobpay.app\"," | 77 "\"package\": \"com.bobpay.app\"," |
| 77 "\"version\": 3," | 78 "\"version\": 3," |
| 78 "\"sha256_cert_fingerprints\": " | 79 "\"sha256_cert_fingerprints\": " |
| 79 "[\"00:01:02:03:04:05:06:07:08:09:A0:A1:A2:A3:A4:A5:A6:A7:A8:A9:B0:B1:B2:" | 80 "[\"00:01:02:03:04:05:06:07:08:09:A0:A1:A2:A3:A4:A5:A6:A7:A8:A9:B0:B1:B2:" |
| 80 "B3:B4:B5:B6:B7:B8:B9:C0:C1\"]}]}", | 81 "B3:B4:B5:B6:B7:B8:B9:C0:C1\"]}]}", |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 "{\"android\": [{" | 177 "{\"android\": [{" |
| 177 "\"package\": \"com.bobpay.app\"," | 178 "\"package\": \"com.bobpay.app\"," |
| 178 "\"version\": 3," | 179 "\"version\": 3," |
| 179 "\"sha256_cert_fingerprints\": " | 180 "\"sha256_cert_fingerprints\": " |
| 180 "[\"00:01:02:03:04:05:06:07:08:09:A0:A1:A2:A3:A4:A5:A6:A7:A8:A9:B0:B1:B2:" | 181 "[\"00:01:02:03:04:05:06:07:08:09:A0:A1:A2:A3:A4:A5:A6:A7:A8:A9:B0:B1:B2:" |
| 181 "B3:B4:B5:B6:B7:B8:B9:C0:C1:C2\"]}]}"); | 182 "B3:B4:B5:B6:B7:B8:B9:C0:C1:C2\"]}]}"); |
| 182 } | 183 } |
| 183 | 184 |
| 184 } // namespace | 185 } // namespace |
| 185 } // namespace payments | 186 } // namespace payments |
| OLD | NEW |