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

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

Issue 1860303002: Fix CFI: Invalid cast in PaymentRequestTest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/modules/payments/PaymentDetailsTestHelper.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "modules/payments/PaymentRequest.h" 5 #include "modules/payments/PaymentRequest.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/ScriptState.h" 8 #include "bindings/core/v8/ScriptState.h"
9 #include "core/dom/ExceptionCode.h" 9 #include "core/dom/ExceptionCode.h"
10 #include "core/testing/DummyPageHolder.h" 10 #include "core/testing/DummyPageHolder.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 TEST_F(PaymentRequestTest, ItemListRequired) 71 TEST_F(PaymentRequestTest, ItemListRequired)
72 { 72 {
73 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), PaymentDe tails(), getExceptionState()); 73 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), PaymentDe tails(), getExceptionState());
74 74
75 EXPECT_TRUE(getExceptionState().hadException()); 75 EXPECT_TRUE(getExceptionState().hadException());
76 EXPECT_EQ(V8TypeError, getExceptionState().code()); 76 EXPECT_EQ(V8TypeError, getExceptionState().code());
77 } 77 }
78 78
79 TEST_F(PaymentRequestTest, AtLeastOnePaymentDetailsItemRequired) 79 TEST_F(PaymentRequestTest, AtLeastOnePaymentDetailsItemRequired)
80 { 80 {
81 PaymentDetails emptyItems; 81 PaymentDetails details;
82 emptyItems.setItems(HeapVector<PaymentItem>()); 82 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption ForTest()));
83 83
84 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), emptyItem s, getExceptionState()); 84 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), details, getExceptionState());
85 85
86 EXPECT_TRUE(getExceptionState().hadException()); 86 EXPECT_TRUE(getExceptionState().hadException());
87 EXPECT_EQ(V8TypeError, getExceptionState().code()); 87 EXPECT_EQ(V8TypeError, getExceptionState().code());
88 } 88 }
89 89
90 TEST_F(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) 90 TEST_F(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable)
91 { 91 {
92 PaymentDetails details = buildPaymentDetailsForTest(); 92 PaymentDetails details;
93 details.setShippingOptions(HeapVector<ShippingOption>()); 93 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest()));
94 94
95 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, getExceptionState()); 95 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, getExceptionState());
96 96
97 EXPECT_TRUE(request->shippingOption().isNull()); 97 EXPECT_TRUE(request->shippingOption().isNull());
98 } 98 }
99 99
100 TEST_F(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable) 100 TEST_F(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable)
101 { 101 {
102 PaymentDetails details = buildPaymentDetailsForTest(); 102 PaymentDetails details;
103 EXPECT_LE(2U, details.shippingOptions().size()); 103 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest()));
104 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption ForTest()));
104 105
105 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, getExceptionState()); 106 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, getExceptionState());
106 107
107 EXPECT_TRUE(request->shippingOption().isNull()); 108 EXPECT_TRUE(request->shippingOption().isNull());
108 } 109 }
109 110
110 TEST_F(PaymentRequestTest, SelectSingleAvailableShippingOption) 111 TEST_F(PaymentRequestTest, SelectSingleAvailableShippingOption)
111 { 112 {
112 CurrencyAmount amount; 113 PaymentDetails details;
113 amount.setCurrencyCode("USD"); 114 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest()));
114 amount.setValue("10.00"); 115 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption ForTest()));
115 ShippingOption option;
116 option.setAmount(amount);
117 option.setId("standard");
118 option.setLabel("Standard shipping");
119 PaymentDetails details = buildPaymentDetailsForTest();
120 details.setShippingOptions(HeapVector<ShippingOption>(1, option));
121 116
122 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, getExceptionState()); 117 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), details, getExceptionState());
123 118
124 EXPECT_EQ("standard", request->shippingOption()); 119 EXPECT_EQ("standard", request->shippingOption());
125 } 120 }
126 121
127 TEST_F(PaymentRequestTest, AbortWithoutShowShouldThrow) 122 TEST_F(PaymentRequestTest, AbortWithoutShowShouldThrow)
128 { 123 {
129 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); 124 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState());
130 EXPECT_FALSE(getExceptionState().hadException()); 125 EXPECT_FALSE(getExceptionState().hadException());
131 126
132 request->abort(getExceptionState()); 127 request->abort(getExceptionState());
133 EXPECT_TRUE(getExceptionState().hadException()); 128 EXPECT_TRUE(getExceptionState().hadException());
134 } 129 }
135 130
136 } // namespace 131 } // namespace
137 } // namespace blink 132 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/payments/PaymentDetailsTestHelper.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698