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

Side by Side Diff: third_party/WebKit/Source/modules/payments/ParsePaymentManifestTest.cpp

Issue 2645813006: Download web payment manifests. (Closed)
Patch Set: Address more comments Created 3 years, 10 months 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
OLDNEW
(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 "bindings/core/v8/V8BindingForTesting.h"
6 #include "modules/payments/PaymentRequest.h"
7 #include "modules/payments/PaymentTestHelper.h"
8 #include "platform/heap/Persistent.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "wtf/Functional.h"
11 #include "wtf/Optional.h"
12 #include "wtf/Vector.h"
13
14 namespace blink {
15 namespace {
16
17 using Section = payments::mojom::blink::NativeAndroidPaymentAppManifestSection;
18 using SectionPtr =
19 payments::mojom::blink::NativeAndroidPaymentAppManifestSectionPtr;
20
21 // Gmock does not support rvalues:
22 // https://github.com/google/googletest/issues/395
23 class MockCallback {
24 public:
25 explicit MockCallback(Optional<Vector<SectionPtr>> expected)
26 : m_expected(std::move(expected)), m_called(false) {}
27
28 ~MockCallback() { EXPECT_TRUE(m_called); }
29
30 void Run(Optional<Vector<SectionPtr>> actual) {
31 m_called = true;
32 EXPECT_EQ(m_expected.has_value(), actual.has_value());
33 if (m_expected.has_value() && actual.has_value())
34 EXPECT_EQ(m_expected.value(), actual.value());
35 }
36
37 private:
38 const Optional<Vector<SectionPtr>> m_expected;
39 bool m_called;
40 };
41
42 void TestHelper(const String& input,
43 Optional<Vector<SectionPtr>> expectedOutput) {
44 V8TestingScope scope;
45 makePaymentRequestOriginSecure(scope.document());
46 PaymentRequest::PaymentRequestClient* request = PaymentRequest::create(
47 scope.getExecutionContext(), buildPaymentMethodDataForTest(),
48 buildPaymentDetailsForTest(), scope.getExceptionState());
49 EXPECT_FALSE(scope.getExceptionState().hadException());
50 MockCallback callback(std::move(expectedOutput));
51 request->ParsePaymentManifest(
52 input,
53 convertToBaseCallback(bind(&MockCallback::Run, WTF::passed(&callback))));
54 }
55
56 TEST(ParsePaymentManifestTest, NullContentIsMalformed) {
57 TestHelper(String(), Optional<Vector<SectionPtr>>());
58 }
59
60 TEST(ParsePaymentManifestTest, NonJsonContentIsMalformed) {
61 TestHelper("this is not json", Optional<Vector<SectionPtr>>());
62 }
63
64 TEST(ParsePaymentManifestTest, StringContentIsMalformed) {
65 TestHelper("\"this is a string\"", Optional<Vector<SectionPtr>>());
66 }
67
68 TEST(ParsePaymentManifestTest, EmptyDictionaryIsMalformed) {
69 TestHelper("{}", Optional<Vector<SectionPtr>>());
70 }
71
72 TEST(ParsePaymentManifestTest, NullAndroidSectionIsMalformed) {
73 TestHelper("{\"android\": null}", Optional<Vector<SectionPtr>>());
74 }
75
76 TEST(ParsePaymentManifestTest, NumberAndroidSectionIsMalformed) {
77 TestHelper("{\"android\": 0}", Optional<Vector<SectionPtr>>());
78 }
79
80 TEST(ParsePaymentManifestTest, ListOfNumbersAndroidSectionIsMalformed) {
81 TestHelper("{\"android\": [0]}", Optional<Vector<SectionPtr>>());
82 }
83
84 TEST(ParsePaymentManifestTest,
85 ListOfEmptyDictionariesAndroidSectionIsMalformed) {
86 TestHelper("{\"android\": [{}]}", Optional<Vector<SectionPtr>>());
87 }
88
89 TEST(ParsePaymentManifestTest, NoPackageNameIsMalformed) {
90 TestHelper("{\"android\": [{\"version\": 3}]}",
91 Optional<Vector<SectionPtr>>());
92 }
93
94 TEST(ParsePaymentManifestTest, OnlyPackageNameIsWellFormed) {
95 Optional<Vector<SectionPtr>> expected((Vector<SectionPtr>()));
96 expected->push_back(Section::New());
97 expected->back()->package_name = "*";
98 TestHelper("{\"android\": [{\"package\": \"*\"}]}", std::move(expected));
99 }
100
101 TEST(ParsePaymentManifestTest, WellFormed) {
102 Optional<Vector<SectionPtr>> expected((Vector<SectionPtr>()));
103 expected->push_back(Section::New());
104 expected->back()->package_name = "com.bobpay.app";
105 expected->back()->version = 3;
106 expected->back()->sha256_cert_fingerprints = Vector<String>();
107 expected->back()->sha256_cert_fingerprints->push_back("1234567890");
108 TestHelper(
109 "{\"android\": [{"
110 "\"package\": \"com.bobpay.app\","
111 "\"version\": 3,"
112 "\"sha256_cert_fingerprints\": [\"1234567890\"]}]}",
113 std::move(expected));
114 }
115
116 } // namespace
117 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698