Index: components/payments/content/android/utility/payment_manifest_parser_test.cc |
diff --git a/components/payments/content/android/utility/payment_manifest_parser_test.cc b/components/payments/content/android/utility/payment_manifest_parser_test.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7e1d9ff9b6fcc583486cd2febc83e309a1e025fa |
--- /dev/null |
+++ b/components/payments/content/android/utility/payment_manifest_parser_test.cc |
@@ -0,0 +1,94 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/payments/content/android/utility/payment_manifest_parser.h" |
+ |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace payments { |
+namespace { |
+ |
+void ExpectUnableToParse(const std::string& input) { |
+ std::vector<mojom::PaymentManifestSectionPtr> actual_output = |
+ PaymentManifestParser::ParseIntoVector(input); |
+ EXPECT_TRUE(actual_output.empty()); |
+} |
+ |
+void ExpectParsed(const std::string& input, |
+ const std::string& expected_package_name, |
+ int expected_version) { |
+ std::vector<mojom::PaymentManifestSectionPtr> actual_output = |
+ PaymentManifestParser::ParseIntoVector(input); |
+ ASSERT_EQ(1U, actual_output.size()); |
+ EXPECT_EQ(expected_package_name, actual_output.front()->package_name); |
+ EXPECT_EQ(expected_version, actual_output.front()->version); |
+ EXPECT_TRUE(actual_output.front()->sha256_cert_fingerprints.empty()); |
+} |
+ |
+void ExpectParsedWithFingerprint(const std::string& input, |
+ const std::string& expected_package_name, |
+ int expected_version, |
+ const std::string& expected_fingerprint) { |
+ std::vector<mojom::PaymentManifestSectionPtr> actual_output = |
+ PaymentManifestParser::ParseIntoVector(input); |
+ ASSERT_EQ(1U, actual_output.size()); |
+ EXPECT_EQ(expected_package_name, actual_output.front()->package_name); |
+ EXPECT_EQ(expected_version, actual_output.front()->version); |
+ ASSERT_EQ(1U, actual_output.front()->sha256_cert_fingerprints.size()); |
+ EXPECT_EQ(expected_fingerprint, |
+ actual_output.front()->sha256_cert_fingerprints.front()); |
+} |
+ |
+TEST(PaymentManifestParserTest, NullContentIsMalformed) { |
+ ExpectUnableToParse(std::string()); |
+} |
+ |
+TEST(PaymentManifestParserTest, NonJsonContentIsMalformed) { |
+ ExpectUnableToParse("this is not json"); |
+} |
+ |
+TEST(PaymentManifestParserTest, StringContentIsMalformed) { |
+ ExpectUnableToParse("\"this is a string\""); |
+} |
+ |
+TEST(PaymentManifestParserTest, EmptyDictionaryIsMalformed) { |
+ ExpectUnableToParse("{}"); |
+} |
+ |
+TEST(PaymentManifestParserTest, NullAndroidSectionIsMalformed) { |
+ ExpectUnableToParse("{\"android\": null}"); |
+} |
+ |
+TEST(PaymentManifestParserTest, NumberAndroidSectionIsMalformed) { |
+ ExpectUnableToParse("{\"android\": 0}"); |
+} |
+ |
+TEST(PaymentManifestParserTest, ListOfNumbersAndroidSectionIsMalformed) { |
+ ExpectUnableToParse("{\"android\": [0]}"); |
+} |
+ |
+TEST(PaymentManifestParserTest, |
+ ListOfEmptyDictionariesAndroidSectionIsMalformed) { |
+ ExpectUnableToParse("{\"android\": [{}]}"); |
+} |
+ |
+TEST(PaymentManifestParserTest, NoPackageNameIsMalformed) { |
+ ExpectUnableToParse("{\"android\": [{\"version\": 3}]}"); |
+} |
+ |
+TEST(PaymentManifestParserTest, OnlyPackageNameIsWellFormed) { |
+ ExpectParsed("{\"android\": [{\"package\": \"*\"}]}", "*", 0); |
+} |
+ |
+TEST(PaymentManifestParserTest, WellFormed) { |
+ ExpectParsedWithFingerprint( |
+ "{\"android\": [{" |
+ "\"package\": \"com.bobpay.app\"," |
+ "\"version\": 3," |
+ "\"sha256_cert_fingerprints\": [\"1234567890\"]}]}", |
+ "com.bobpay.app", 3, "1234567890"); |
+} |
+ |
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.
|
+} // namespace |
+} // namespace payments |