Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/payments/content/android/utility/payment_manifest_parser.h" | |
| 6 | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 | |
| 9 namespace payments { | |
| 10 namespace { | |
| 11 | |
| 12 void ExpectUnableToParse(const std::string& input) { | |
| 13 std::vector<mojom::PaymentManifestSectionPtr> actual_output = | |
| 14 PaymentManifestParser::ParseIntoVector(input); | |
| 15 EXPECT_TRUE(actual_output.empty()); | |
| 16 } | |
| 17 | |
| 18 void ExpectParsed(const std::string& input, | |
| 19 const std::string& expected_package_name, | |
| 20 int expected_version) { | |
| 21 std::vector<mojom::PaymentManifestSectionPtr> actual_output = | |
| 22 PaymentManifestParser::ParseIntoVector(input); | |
| 23 ASSERT_EQ(1U, actual_output.size()); | |
| 24 EXPECT_EQ(expected_package_name, actual_output.front()->package_name); | |
| 25 EXPECT_EQ(expected_version, actual_output.front()->version); | |
| 26 EXPECT_TRUE(actual_output.front()->sha256_cert_fingerprints.empty()); | |
| 27 } | |
| 28 | |
| 29 void ExpectParsedWithFingerprint(const std::string& input, | |
| 30 const std::string& expected_package_name, | |
| 31 int expected_version, | |
| 32 const std::string& expected_fingerprint) { | |
| 33 std::vector<mojom::PaymentManifestSectionPtr> actual_output = | |
| 34 PaymentManifestParser::ParseIntoVector(input); | |
| 35 ASSERT_EQ(1U, actual_output.size()); | |
| 36 EXPECT_EQ(expected_package_name, actual_output.front()->package_name); | |
| 37 EXPECT_EQ(expected_version, actual_output.front()->version); | |
| 38 ASSERT_EQ(1U, actual_output.front()->sha256_cert_fingerprints.size()); | |
| 39 EXPECT_EQ(expected_fingerprint, | |
| 40 actual_output.front()->sha256_cert_fingerprints.front()); | |
| 41 } | |
| 42 | |
| 43 TEST(PaymentManifestParserTest, NullContentIsMalformed) { | |
| 44 ExpectUnableToParse(std::string()); | |
| 45 } | |
| 46 | |
| 47 TEST(PaymentManifestParserTest, NonJsonContentIsMalformed) { | |
| 48 ExpectUnableToParse("this is not json"); | |
| 49 } | |
| 50 | |
| 51 TEST(PaymentManifestParserTest, StringContentIsMalformed) { | |
| 52 ExpectUnableToParse("\"this is a string\""); | |
| 53 } | |
| 54 | |
| 55 TEST(PaymentManifestParserTest, EmptyDictionaryIsMalformed) { | |
| 56 ExpectUnableToParse("{}"); | |
| 57 } | |
| 58 | |
| 59 TEST(PaymentManifestParserTest, NullAndroidSectionIsMalformed) { | |
| 60 ExpectUnableToParse("{\"android\": null}"); | |
| 61 } | |
| 62 | |
| 63 TEST(PaymentManifestParserTest, NumberAndroidSectionIsMalformed) { | |
| 64 ExpectUnableToParse("{\"android\": 0}"); | |
| 65 } | |
| 66 | |
| 67 TEST(PaymentManifestParserTest, ListOfNumbersAndroidSectionIsMalformed) { | |
| 68 ExpectUnableToParse("{\"android\": [0]}"); | |
| 69 } | |
| 70 | |
| 71 TEST(PaymentManifestParserTest, | |
| 72 ListOfEmptyDictionariesAndroidSectionIsMalformed) { | |
| 73 ExpectUnableToParse("{\"android\": [{}]}"); | |
| 74 } | |
| 75 | |
| 76 TEST(PaymentManifestParserTest, NoPackageNameIsMalformed) { | |
| 77 ExpectUnableToParse("{\"android\": [{\"version\": 3}]}"); | |
| 78 } | |
| 79 | |
| 80 TEST(PaymentManifestParserTest, OnlyPackageNameIsWellFormed) { | |
| 81 ExpectParsed("{\"android\": [{\"package\": \"*\"}]}", "*", 0); | |
| 82 } | |
| 83 | |
| 84 TEST(PaymentManifestParserTest, WellFormed) { | |
| 85 ExpectParsedWithFingerprint( | |
| 86 "{\"android\": [{" | |
| 87 "\"package\": \"com.bobpay.app\"," | |
| 88 "\"version\": 3," | |
| 89 "\"sha256_cert_fingerprints\": [\"1234567890\"]}]}", | |
| 90 "com.bobpay.app", 3, "1234567890"); | |
| 91 } | |
| 92 | |
|
palmer
2017/03/03 22:56:31
Maybe add a test for an input that has a "com.bobp
please use gerrit instead
2017/03/09 18:05:34
Done.
| |
| 93 } // namespace | |
| 94 } // namespace payments | |
| OLD | NEW |