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

Side by Side Diff: components/payments/content/payment_request_spec_unittest.cc

Issue 2779453002: [Payments] Return the preferred payment method name to the merchant (Closed)
Patch Set: compile fix Created 3 years, 9 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
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/payment_request_spec.h" 5 #include "components/payments/content/payment_request_spec.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "components/payments/content/payment_request.mojom.h" 10 #include "components/payments/content/payment_request.mojom.h"
(...skipping 29 matching lines...) Expand all
40 // Test that empty method data notifies observers of an invalid spec. 40 // Test that empty method data notifies observers of an invalid spec.
41 TEST_F(PaymentRequestSpecTest, EmptyMethodData) { 41 TEST_F(PaymentRequestSpecTest, EmptyMethodData) {
42 std::vector<mojom::PaymentMethodDataPtr> method_data; 42 std::vector<mojom::PaymentMethodDataPtr> method_data;
43 RecreateSpecWithMethodData(std::move(method_data)); 43 RecreateSpecWithMethodData(std::move(method_data));
44 EXPECT_TRUE(on_invalid_spec_provided_called()); 44 EXPECT_TRUE(on_invalid_spec_provided_called());
45 45
46 // No supported card networks. 46 // No supported card networks.
47 EXPECT_EQ(0u, spec()->supported_card_networks().size()); 47 EXPECT_EQ(0u, spec()->supported_card_networks().size());
48 } 48 }
49 49
50 TEST_F(PaymentRequestSpecTest, IsMethodSupportedThroughBasicCard) {
51 mojom::PaymentMethodDataPtr entry = mojom::PaymentMethodData::New();
52 entry->supported_methods.push_back("visa");
53 entry->supported_methods.push_back("mastercard");
54 entry->supported_methods.push_back("invalid");
55 entry->supported_methods.push_back("");
56 entry->supported_methods.push_back("visa");
57 mojom::PaymentMethodDataPtr entry2 = mojom::PaymentMethodData::New();
58 entry2->supported_methods.push_back("basic-card");
59 entry2->supported_networks.push_back(mojom::BasicCardNetwork::UNIONPAY);
60 entry2->supported_networks.push_back(mojom::BasicCardNetwork::JCB);
61 entry2->supported_networks.push_back(mojom::BasicCardNetwork::VISA);
62
63 std::vector<mojom::PaymentMethodDataPtr> method_data;
64 method_data.push_back(std::move(entry));
65 method_data.push_back(std::move(entry2));
66
67 RecreateSpecWithMethodData(std::move(method_data));
68
69 // Only unionpay and jcb are supported through basic-card.
70 EXPECT_TRUE(spec()->IsMethodSupportedThroughBasicCard("unionpay"));
71 EXPECT_TRUE(spec()->IsMethodSupportedThroughBasicCard("jcb"));
72 // "visa" is NOT supported through basic card because it was specified
73 // directly first in supportedMethods.
74 EXPECT_FALSE(spec()->IsMethodSupportedThroughBasicCard("visa"));
75 EXPECT_FALSE(spec()->IsMethodSupportedThroughBasicCard("mastercard"));
76 EXPECT_FALSE(spec()->IsMethodSupportedThroughBasicCard("diners"));
77 EXPECT_FALSE(spec()->IsMethodSupportedThroughBasicCard("garbage"));
78 }
79
80 // Order matters when parsing the supportedMethods and basic card networks.
81 TEST_F(PaymentRequestSpecTest,
82 IsMethodSupportedThroughBasicCard_DifferentOrder) {
83 mojom::PaymentMethodDataPtr entry = mojom::PaymentMethodData::New();
84 entry->supported_methods.push_back("basic-card");
85 entry->supported_networks.push_back(mojom::BasicCardNetwork::UNIONPAY);
86 entry->supported_networks.push_back(mojom::BasicCardNetwork::VISA);
87 mojom::PaymentMethodDataPtr entry2 = mojom::PaymentMethodData::New();
88 entry2->supported_methods.push_back("visa");
89 entry2->supported_methods.push_back("unionpay");
90 entry2->supported_methods.push_back("jcb");
91
92 std::vector<mojom::PaymentMethodDataPtr> method_data;
93 method_data.push_back(std::move(entry));
94 method_data.push_back(std::move(entry2));
95
96 RecreateSpecWithMethodData(std::move(method_data));
97
98 // unionpay and visa are supported through basic-card; they were specified
99 // first as basic card networks.
100 EXPECT_TRUE(spec()->IsMethodSupportedThroughBasicCard("unionpay"));
101 EXPECT_TRUE(spec()->IsMethodSupportedThroughBasicCard("visa"));
102 // "jcb" is NOT supported through basic card; it was specified directly
103 // as a supportedMethods
104 EXPECT_FALSE(spec()->IsMethodSupportedThroughBasicCard("jcb"));
105 }
106
50 // Test that parsing supported methods (with invalid values and duplicates) 107 // Test that parsing supported methods (with invalid values and duplicates)
51 // works as expected. 108 // works as expected.
52 TEST_F(PaymentRequestSpecTest, SupportedMethods) { 109 TEST_F(PaymentRequestSpecTest, SupportedMethods) {
53 mojom::PaymentMethodDataPtr entry = mojom::PaymentMethodData::New(); 110 mojom::PaymentMethodDataPtr entry = mojom::PaymentMethodData::New();
54 entry->supported_methods.push_back("visa"); 111 entry->supported_methods.push_back("visa");
55 entry->supported_methods.push_back("mastercard"); 112 entry->supported_methods.push_back("mastercard");
56 entry->supported_methods.push_back("invalid"); 113 entry->supported_methods.push_back("invalid");
57 entry->supported_methods.push_back(""); 114 entry->supported_methods.push_back("");
58 entry->supported_methods.push_back("visa"); 115 entry->supported_methods.push_back("visa");
59 std::vector<mojom::PaymentMethodDataPtr> method_data; 116 std::vector<mojom::PaymentMethodDataPtr> method_data;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 RecreateSpecWithMethodData(std::move(method_data)); 260 RecreateSpecWithMethodData(std::move(method_data));
204 EXPECT_FALSE(on_invalid_spec_provided_called()); 261 EXPECT_FALSE(on_invalid_spec_provided_called());
205 262
206 // Only the specified networks are supported. 263 // Only the specified networks are supported.
207 EXPECT_EQ(2u, spec()->supported_card_networks().size()); 264 EXPECT_EQ(2u, spec()->supported_card_networks().size());
208 EXPECT_EQ("visa", spec()->supported_card_networks()[0]); 265 EXPECT_EQ("visa", spec()->supported_card_networks()[0]);
209 EXPECT_EQ("unionpay", spec()->supported_card_networks()[1]); 266 EXPECT_EQ("unionpay", spec()->supported_card_networks()[1]);
210 } 267 }
211 268
212 } // namespace payments 269 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/content/payment_request_spec.cc ('k') | components/payments/content/payment_request_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698