| OLD | NEW |
| 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/JSONValuesForV8.h" | 8 #include "bindings/core/v8/JSONValuesForV8.h" |
| 9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 void setSecurityOrigin(const String& securityOrigin) | 38 void setSecurityOrigin(const String& securityOrigin) |
| 39 { | 39 { |
| 40 m_page->document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(),
securityOrigin))); | 40 m_page->document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(),
securityOrigin))); |
| 41 } | 41 } |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 OwnPtr<DummyPageHolder> m_page; | 44 OwnPtr<DummyPageHolder> m_page; |
| 45 TrackExceptionState m_exceptionState; | 45 TrackExceptionState m_exceptionState; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 HeapVector<PaymentMethodData> buildPaymentMethodDataForTest() |
| 49 { |
| 50 HeapVector<PaymentMethodData> methodData(1, PaymentMethodData()); |
| 51 methodData[0].setSupportedMethods(Vector<String>(1, "food")); |
| 52 return methodData; |
| 53 } |
| 54 |
| 48 TEST_F(PaymentRequestTest, NoExceptionWithValidData) | 55 TEST_F(PaymentRequestTest, NoExceptionWithValidData) |
| 49 { | 56 { |
| 50 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaym
entDetailsForTest(), getExceptionState()); | 57 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), bu
ildPaymentDetailsForTest(), getExceptionState()); |
| 51 | 58 |
| 52 EXPECT_FALSE(getExceptionState().hadException()); | 59 EXPECT_FALSE(getExceptionState().hadException()); |
| 53 } | 60 } |
| 54 | 61 |
| 55 TEST_F(PaymentRequestTest, SecureContextRequired) | 62 TEST_F(PaymentRequestTest, SecureContextRequired) |
| 56 { | 63 { |
| 57 setSecurityOrigin("http://www.example.com"); | 64 setSecurityOrigin("http://www.example.com"); |
| 58 | 65 |
| 59 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaym
entDetailsForTest(), getExceptionState()); | 66 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), bu
ildPaymentDetailsForTest(), getExceptionState()); |
| 60 | 67 |
| 61 EXPECT_TRUE(getExceptionState().hadException()); | 68 EXPECT_TRUE(getExceptionState().hadException()); |
| 62 EXPECT_EQ(SecurityError, getExceptionState().code()); | 69 EXPECT_EQ(SecurityError, getExceptionState().code()); |
| 63 } | 70 } |
| 64 | 71 |
| 65 TEST_F(PaymentRequestTest, SupportedMethodListRequired) | 72 TEST_F(PaymentRequestTest, SupportedMethodListRequired) |
| 66 { | 73 { |
| 67 PaymentRequest::create(getScriptState(), Vector<String>(), buildPaymentDetai
lsForTest(), getExceptionState()); | 74 PaymentRequest::create(getScriptState(), HeapVector<PaymentMethodData>(), bu
ildPaymentDetailsForTest(), getExceptionState()); |
| 68 | 75 |
| 69 EXPECT_TRUE(getExceptionState().hadException()); | 76 EXPECT_TRUE(getExceptionState().hadException()); |
| 70 EXPECT_EQ(V8TypeError, getExceptionState().code()); | 77 EXPECT_EQ(V8TypeError, getExceptionState().code()); |
| 71 } | 78 } |
| 72 | 79 |
| 73 TEST_F(PaymentRequestTest, ItemListRequired) | 80 TEST_F(PaymentRequestTest, ItemListRequired) |
| 74 { | 81 { |
| 75 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), PaymentDe
tails(), getExceptionState()); | 82 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), Pa
ymentDetails(), getExceptionState()); |
| 76 | 83 |
| 77 EXPECT_TRUE(getExceptionState().hadException()); | 84 EXPECT_TRUE(getExceptionState().hadException()); |
| 78 EXPECT_EQ(V8TypeError, getExceptionState().code()); | 85 EXPECT_EQ(V8TypeError, getExceptionState().code()); |
| 79 } | 86 } |
| 80 | 87 |
| 81 TEST_F(PaymentRequestTest, ItemListIsNotEmpty) | 88 TEST_F(PaymentRequestTest, ItemListIsNotEmpty) |
| 82 { | 89 { |
| 83 PaymentDetails details; | 90 PaymentDetails details; |
| 84 details.setItems(HeapVector<PaymentItem>()); | 91 details.setItems(HeapVector<PaymentItem>()); |
| 85 | 92 |
| 86 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), details,
getExceptionState()); | 93 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), de
tails, getExceptionState()); |
| 87 | 94 |
| 88 EXPECT_TRUE(getExceptionState().hadException()); | 95 EXPECT_TRUE(getExceptionState().hadException()); |
| 89 EXPECT_EQ(V8TypeError, getExceptionState().code()); | 96 EXPECT_EQ(V8TypeError, getExceptionState().code()); |
| 90 } | 97 } |
| 91 | 98 |
| 92 TEST_F(PaymentRequestTest, AtLeastOnePaymentDetailsItemRequired) | 99 TEST_F(PaymentRequestTest, AtLeastOnePaymentDetailsItemRequired) |
| 93 { | 100 { |
| 94 PaymentDetails details; | 101 PaymentDetails details; |
| 95 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption
ForTest())); | 102 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption
ForTest())); |
| 96 | 103 |
| 97 PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), details,
getExceptionState()); | 104 PaymentRequest::create(getScriptState(), buildPaymentMethodDataForTest(), de
tails, getExceptionState()); |
| 98 | 105 |
| 99 EXPECT_TRUE(getExceptionState().hadException()); | 106 EXPECT_TRUE(getExceptionState().hadException()); |
| 100 EXPECT_EQ(V8TypeError, getExceptionState().code()); | 107 EXPECT_EQ(V8TypeError, getExceptionState().code()); |
| 101 } | 108 } |
| 102 | 109 |
| 103 TEST_F(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) | 110 TEST_F(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) |
| 104 { | 111 { |
| 105 PaymentDetails details; | 112 PaymentDetails details; |
| 106 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); | 113 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); |
| 107 PaymentOptions options; | 114 PaymentOptions options; |
| 108 options.setRequestShipping(true); | 115 options.setRequestShipping(true); |
| 109 | 116 |
| 110 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 117 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
| 111 | 118 |
| 112 EXPECT_TRUE(request->shippingOption().isNull()); | 119 EXPECT_TRUE(request->shippingOption().isNull()); |
| 113 } | 120 } |
| 114 | 121 |
| 115 TEST_F(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable) | 122 TEST_F(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable) |
| 116 { | 123 { |
| 117 PaymentDetails details; | 124 PaymentDetails details; |
| 118 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); | 125 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); |
| 119 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption
ForTest())); | 126 details.setShippingOptions(HeapVector<ShippingOption>(2, buildShippingOption
ForTest())); |
| 120 PaymentOptions options; | 127 PaymentOptions options; |
| 121 options.setRequestShipping(true); | 128 options.setRequestShipping(true); |
| 122 | 129 |
| 123 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 130 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
| 124 | 131 |
| 125 EXPECT_TRUE(request->shippingOption().isNull()); | 132 EXPECT_TRUE(request->shippingOption().isNull()); |
| 126 } | 133 } |
| 127 | 134 |
| 128 TEST_F(PaymentRequestTest, SelectSingleAvailableShippingOptionWhenShippingReques
ted) | 135 TEST_F(PaymentRequestTest, SelectSingleAvailableShippingOptionWhenShippingReques
ted) |
| 129 { | 136 { |
| 130 PaymentDetails details; | 137 PaymentDetails details; |
| 131 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); | 138 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); |
| 132 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); | 139 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); |
| 133 PaymentOptions options; | 140 PaymentOptions options; |
| 134 options.setRequestShipping(true); | 141 options.setRequestShipping(true); |
| 135 | 142 |
| 136 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 143 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
| 137 | 144 |
| 138 EXPECT_EQ("standard", request->shippingOption()); | 145 EXPECT_EQ("standard", request->shippingOption()); |
| 139 } | 146 } |
| 140 | 147 |
| 141 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault) | 148 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault) |
| 142 { | 149 { |
| 143 PaymentDetails details; | 150 PaymentDetails details; |
| 144 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); | 151 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); |
| 145 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); | 152 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest(PaymentTestDataId, PaymentTestOverwriteValue, "standard"))); |
| 146 | 153 |
| 147 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, getExceptionState()); | 154 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, getExceptionState()); |
| 148 | 155 |
| 149 EXPECT_TRUE(request->shippingOption().isNull()); | 156 EXPECT_TRUE(request->shippingOption().isNull()); |
| 150 } | 157 } |
| 151 | 158 |
| 152 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionWhenShippingNo
tRequested) | 159 TEST_F(PaymentRequestTest, DontSelectSingleAvailableShippingOptionWhenShippingNo
tRequested) |
| 153 { | 160 { |
| 154 PaymentDetails details; | 161 PaymentDetails details; |
| 155 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); | 162 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); |
| 156 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest())); | 163 details.setShippingOptions(HeapVector<ShippingOption>(1, buildShippingOption
ForTest())); |
| 157 PaymentOptions options; | 164 PaymentOptions options; |
| 158 options.setRequestShipping(false); | 165 options.setRequestShipping(false); |
| 159 | 166 |
| 160 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 167 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
| 161 | 168 |
| 162 EXPECT_TRUE(request->shippingOption().isNull()); | 169 EXPECT_TRUE(request->shippingOption().isNull()); |
| 163 } | 170 } |
| 164 | 171 |
| 165 TEST_F(PaymentRequestTest, AbortWithoutShowShouldThrow) | 172 TEST_F(PaymentRequestTest, AbortWithoutShowShouldThrow) |
| 166 { | 173 { |
| 167 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 174 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 168 EXPECT_FALSE(getExceptionState().hadException()); | 175 EXPECT_FALSE(getExceptionState().hadException()); |
| 169 | 176 |
| 170 request->abort(getExceptionState()); | 177 request->abort(getExceptionState()); |
| 171 EXPECT_TRUE(getExceptionState().hadException()); | 178 EXPECT_TRUE(getExceptionState().hadException()); |
| 172 } | 179 } |
| 173 | 180 |
| 174 class MockFunction : public ScriptFunction { | 181 class MockFunction : public ScriptFunction { |
| 175 public: | 182 public: |
| 176 static v8::Local<v8::Function> noExpectations(ScriptState* scriptState) | 183 static v8::Local<v8::Function> noExpectations(ScriptState* scriptState) |
| 177 { | 184 { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 199 { | 206 { |
| 200 ON_CALL(*this, call(testing::_)).WillByDefault(testing::ReturnArg<0>()); | 207 ON_CALL(*this, call(testing::_)).WillByDefault(testing::ReturnArg<0>()); |
| 201 } | 208 } |
| 202 | 209 |
| 203 MOCK_METHOD1(call, ScriptValue(ScriptValue)); | 210 MOCK_METHOD1(call, ScriptValue(ScriptValue)); |
| 204 }; | 211 }; |
| 205 | 212 |
| 206 TEST_F(PaymentRequestTest, CanAbortAfterShow) | 213 TEST_F(PaymentRequestTest, CanAbortAfterShow) |
| 207 { | 214 { |
| 208 ScriptState::Scope scope(getScriptState()); | 215 ScriptState::Scope scope(getScriptState()); |
| 209 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 216 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 210 EXPECT_FALSE(getExceptionState().hadException()); | 217 EXPECT_FALSE(getExceptionState().hadException()); |
| 211 | 218 |
| 212 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::noExpectations(getScriptState())); | 219 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::noExpectations(getScriptState())); |
| 213 request->abort(getExceptionState()); | 220 request->abort(getExceptionState()); |
| 214 | 221 |
| 215 EXPECT_FALSE(getExceptionState().hadException()); | 222 EXPECT_FALSE(getExceptionState().hadException()); |
| 216 } | 223 } |
| 217 | 224 |
| 218 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress) | 225 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress) |
| 219 { | 226 { |
| 220 ScriptState::Scope scope(getScriptState()); | 227 ScriptState::Scope scope(getScriptState()); |
| 221 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 228 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 222 EXPECT_FALSE(getExceptionState().hadException()); | 229 EXPECT_FALSE(getExceptionState().hadException()); |
| 223 | 230 |
| 224 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 231 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
| 225 | 232 |
| 226 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(mojom::blink::ShippingAddress::New()); | 233 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(mojom::blink::ShippingAddress::New()); |
| 227 } | 234 } |
| 228 | 235 |
| 229 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddressInResponse) | 236 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddressInResponse) |
| 230 { | 237 { |
| 231 ScriptState::Scope scope(getScriptState()); | 238 ScriptState::Scope scope(getScriptState()); |
| 232 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 239 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 233 EXPECT_FALSE(getExceptionState().hadException()); | 240 EXPECT_FALSE(getExceptionState().hadException()); |
| 234 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 241 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 235 response->shipping_address = mojom::blink::ShippingAddress::New(); | 242 response->shipping_address = mojom::blink::ShippingAddress::New(); |
| 236 | 243 |
| 237 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 244 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
| 238 | 245 |
| 239 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 246 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 240 } | 247 } |
| 241 | 248 |
| 242 TEST_F(PaymentRequestTest, DontRejectShowPromiseForValidShippingAddress) | 249 TEST_F(PaymentRequestTest, DontRejectShowPromiseForValidShippingAddress) |
| 243 { | 250 { |
| 244 ScriptState::Scope scope(getScriptState()); | 251 ScriptState::Scope scope(getScriptState()); |
| 245 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 252 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 246 EXPECT_FALSE(getExceptionState().hadException()); | 253 EXPECT_FALSE(getExceptionState().hadException()); |
| 247 mojom::blink::ShippingAddressPtr shippingAddress = mojom::blink::ShippingAdd
ress::New(); | 254 mojom::blink::ShippingAddressPtr shippingAddress = mojom::blink::ShippingAdd
ress::New(); |
| 248 shippingAddress->region_code = "US"; | 255 shippingAddress->region_code = "US"; |
| 249 shippingAddress->language_code = "en"; | 256 shippingAddress->language_code = "en"; |
| 250 shippingAddress->script_code = "Latn"; | 257 shippingAddress->script_code = "Latn"; |
| 251 | 258 |
| 252 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 259 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
| 253 | 260 |
| 254 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(std::move(shippingAddress)); | 261 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddress
Change(std::move(shippingAddress)); |
| 255 } | 262 } |
| 256 | 263 |
| 257 TEST_F(PaymentRequestTest, ResolveShowPromiseWithValidShippingAddressInResponse) | 264 TEST_F(PaymentRequestTest, ResolveShowPromiseWithValidShippingAddressInResponse) |
| 258 { | 265 { |
| 259 ScriptState::Scope scope(getScriptState()); | 266 ScriptState::Scope scope(getScriptState()); |
| 260 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 267 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 261 EXPECT_FALSE(getExceptionState().hadException()); | 268 EXPECT_FALSE(getExceptionState().hadException()); |
| 262 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); | 269 mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::N
ew(); |
| 263 response->shipping_address = mojom::blink::ShippingAddress::New(); | 270 response->shipping_address = mojom::blink::ShippingAddress::New(); |
| 264 response->shipping_address->region_code = "US"; | 271 response->shipping_address->region_code = "US"; |
| 265 response->shipping_address->language_code = "en"; | 272 response->shipping_address->language_code = "en"; |
| 266 response->shipping_address->script_code = "Latn"; | 273 response->shipping_address->script_code = "Latn"; |
| 267 | 274 |
| 268 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); | 275 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); |
| 269 | 276 |
| 270 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); | 277 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(std::move(response)); |
| 271 } | 278 } |
| 272 | 279 |
| 273 TEST_F(PaymentRequestTest, ResolveShowPromiseWithoutShippingAddressInResponse) | 280 TEST_F(PaymentRequestTest, ResolveShowPromiseWithoutShippingAddressInResponse) |
| 274 { | 281 { |
| 275 ScriptState::Scope scope(getScriptState()); | 282 ScriptState::Scope scope(getScriptState()); |
| 276 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 283 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 277 EXPECT_FALSE(getExceptionState().hadException()); | 284 EXPECT_FALSE(getExceptionState().hadException()); |
| 278 | 285 |
| 279 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); | 286 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); |
| 280 | 287 |
| 281 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 288 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
| 282 } | 289 } |
| 283 | 290 |
| 284 TEST_F(PaymentRequestTest, OnShippingOptionChange) | 291 TEST_F(PaymentRequestTest, OnShippingOptionChange) |
| 285 { | 292 { |
| 286 ScriptState::Scope scope(getScriptState()); | 293 ScriptState::Scope scope(getScriptState()); |
| 287 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 294 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 288 EXPECT_FALSE(getExceptionState().hadException()); | 295 EXPECT_FALSE(getExceptionState().hadException()); |
| 289 | 296 |
| 290 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 297 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
| 291 | 298 |
| 292 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingOptionC
hange("standardShipping"); | 299 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingOptionC
hange("standardShipping"); |
| 293 } | 300 } |
| 294 | 301 |
| 295 TEST_F(PaymentRequestTest, CannotCallShowTwice) | 302 TEST_F(PaymentRequestTest, CannotCallShowTwice) |
| 296 { | 303 { |
| 297 ScriptState::Scope scope(getScriptState()); | 304 ScriptState::Scope scope(getScriptState()); |
| 298 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 305 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 299 EXPECT_FALSE(getExceptionState().hadException()); | 306 EXPECT_FALSE(getExceptionState().hadException()); |
| 300 request->show(getScriptState()); | 307 request->show(getScriptState()); |
| 301 | 308 |
| 302 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 309 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
| 303 } | 310 } |
| 304 | 311 |
| 305 TEST_F(PaymentRequestTest, CannotCallCompleteTwice) | 312 TEST_F(PaymentRequestTest, CannotCallCompleteTwice) |
| 306 { | 313 { |
| 307 ScriptState::Scope scope(getScriptState()); | 314 ScriptState::Scope scope(getScriptState()); |
| 308 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 315 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 309 EXPECT_FALSE(getExceptionState().hadException()); | 316 EXPECT_FALSE(getExceptionState().hadException()); |
| 310 request->show(getScriptState()); | 317 request->show(getScriptState()); |
| 311 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 318 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
| 312 request->complete(getScriptState(), false); | 319 request->complete(getScriptState(), false); |
| 313 | 320 |
| 314 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); | 321 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); |
| 315 } | 322 } |
| 316 | 323 |
| 317 TEST_F(PaymentRequestTest, RejectShowPromiseOnError) | 324 TEST_F(PaymentRequestTest, RejectShowPromiseOnError) |
| 318 { | 325 { |
| 319 ScriptState::Scope scope(getScriptState()); | 326 ScriptState::Scope scope(getScriptState()); |
| 320 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 327 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 321 EXPECT_FALSE(getExceptionState().hadException()); | 328 EXPECT_FALSE(getExceptionState().hadException()); |
| 322 | 329 |
| 323 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 330 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
| 324 | 331 |
| 325 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); | 332 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); |
| 326 } | 333 } |
| 327 | 334 |
| 328 TEST_F(PaymentRequestTest, RejectCompletePromiseOnError) | 335 TEST_F(PaymentRequestTest, RejectCompletePromiseOnError) |
| 329 { | 336 { |
| 330 ScriptState::Scope scope(getScriptState()); | 337 ScriptState::Scope scope(getScriptState()); |
| 331 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 338 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 332 EXPECT_FALSE(getExceptionState().hadException()); | 339 EXPECT_FALSE(getExceptionState().hadException()); |
| 333 request->show(getScriptState()); | 340 request->show(getScriptState()); |
| 334 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 341 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
| 335 | 342 |
| 336 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); | 343 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); |
| 337 | 344 |
| 338 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); | 345 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(); |
| 339 } | 346 } |
| 340 | 347 |
| 341 TEST_F(PaymentRequestTest, ResolvePromiseOnComplete) | 348 TEST_F(PaymentRequestTest, ResolvePromiseOnComplete) |
| 342 { | 349 { |
| 343 ScriptState::Scope scope(getScriptState()); | 350 ScriptState::Scope scope(getScriptState()); |
| 344 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 351 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 345 EXPECT_FALSE(getExceptionState().hadException()); | 352 EXPECT_FALSE(getExceptionState().hadException()); |
| 346 request->show(getScriptState()); | 353 request->show(getScriptState()); |
| 347 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 354 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
| 348 | 355 |
| 349 request->complete(getScriptState(), true).then(MockFunction::expectCall(getS
criptState()), MockFunction::expectNoCall(getScriptState())); | 356 request->complete(getScriptState(), true).then(MockFunction::expectCall(getS
criptState()), MockFunction::expectNoCall(getScriptState())); |
| 350 | 357 |
| 351 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnComplete(); | 358 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnComplete(); |
| 352 } | 359 } |
| 353 | 360 |
| 354 TEST_F(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) | 361 TEST_F(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) |
| 355 { | 362 { |
| 356 ScriptState::Scope scope(getScriptState()); | 363 ScriptState::Scope scope(getScriptState()); |
| 357 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 364 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 358 EXPECT_FALSE(getExceptionState().hadException()); | 365 EXPECT_FALSE(getExceptionState().hadException()); |
| 359 | 366 |
| 360 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 367 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
| 361 | 368 |
| 362 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); | 369 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); |
| 363 } | 370 } |
| 364 | 371 |
| 365 TEST_F(PaymentRequestTest, RejectCompletePromiseOnUpdateDetailsFailure) | 372 TEST_F(PaymentRequestTest, RejectCompletePromiseOnUpdateDetailsFailure) |
| 366 { | 373 { |
| 367 ScriptState::Scope scope(getScriptState()); | 374 ScriptState::Scope scope(getScriptState()); |
| 368 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 375 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 369 EXPECT_FALSE(getExceptionState().hadException()); | 376 EXPECT_FALSE(getExceptionState().hadException()); |
| 370 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); | 377 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); |
| 371 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 378 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
| 372 | 379 |
| 373 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); | 380 request->complete(getScriptState(), true).then(MockFunction::expectNoCall(ge
tScriptState()), MockFunction::expectCall(getScriptState())); |
| 374 | 381 |
| 375 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); | 382 request->onUpdatePaymentDetailsFailure(ScriptValue::from(getScriptState(), "
oops")); |
| 376 } | 383 } |
| 377 | 384 |
| 378 TEST_F(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) | 385 TEST_F(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) |
| 379 { | 386 { |
| 380 ScriptState::Scope scope(getScriptState()); | 387 ScriptState::Scope scope(getScriptState()); |
| 381 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 388 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 382 EXPECT_FALSE(getExceptionState().hadException()); | 389 EXPECT_FALSE(getExceptionState().hadException()); |
| 383 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); | 390 request->show(getScriptState()).then(MockFunction::expectCall(getScriptState
()), MockFunction::expectNoCall(getScriptState())); |
| 384 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); | 391 static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse
(mojom::blink::PaymentResponse::New()); |
| 385 | 392 |
| 386 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), "foo")); | 393 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), "foo")); |
| 387 } | 394 } |
| 388 | 395 |
| 389 TEST_F(PaymentRequestTest, RejectShowPromiseOnNonPaymentDetailsUpdate) | 396 TEST_F(PaymentRequestTest, RejectShowPromiseOnNonPaymentDetailsUpdate) |
| 390 { | 397 { |
| 391 ScriptState::Scope scope(getScriptState()); | 398 ScriptState::Scope scope(getScriptState()); |
| 392 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 399 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 393 EXPECT_FALSE(getExceptionState().hadException()); | 400 EXPECT_FALSE(getExceptionState().hadException()); |
| 394 | 401 |
| 395 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 402 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
| 396 | 403 |
| 397 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), "NotPaym
entDetails")); | 404 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), "NotPaym
entDetails")); |
| 398 } | 405 } |
| 399 | 406 |
| 400 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidPaymentDetailsUpdate) | 407 TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidPaymentDetailsUpdate) |
| 401 { | 408 { |
| 402 ScriptState::Scope scope(getScriptState()); | 409 ScriptState::Scope scope(getScriptState()); |
| 403 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState()); | 410 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), getExceptionState()); |
| 404 EXPECT_FALSE(getExceptionState().hadException()); | 411 EXPECT_FALSE(getExceptionState().hadException()); |
| 405 | 412 |
| 406 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); | 413 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectCall(getScriptState())); |
| 407 | 414 |
| 408 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), "{}", getExceptionState()))); | 415 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), "{}", getExceptionState()))); |
| 409 EXPECT_FALSE(getExceptionState().hadException()); | 416 EXPECT_FALSE(getExceptionState().hadException()); |
| 410 } | 417 } |
| 411 | 418 |
| 412 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithoutShipp
ingOptions) | 419 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithoutShipp
ingOptions) |
| 413 { | 420 { |
| 414 ScriptState::Scope scope(getScriptState()); | 421 ScriptState::Scope scope(getScriptState()); |
| 415 PaymentDetails details; | 422 PaymentDetails details; |
| 416 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); | 423 details.setItems(HeapVector<PaymentItem>(1, buildPaymentItemForTest())); |
| 417 PaymentOptions options; | 424 PaymentOptions options; |
| 418 options.setRequestShipping(true); | 425 options.setRequestShipping(true); |
| 419 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), details, options, getExceptionState()); | 426 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), details, options, getExceptionState()); |
| 420 EXPECT_FALSE(getExceptionState().hadException()); | 427 EXPECT_FALSE(getExceptionState().hadException()); |
| 421 EXPECT_TRUE(request->shippingOption().isNull()); | 428 EXPECT_TRUE(request->shippingOption().isNull()); |
| 422 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 429 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
| 423 String detailWithShippingOptions = "{\"items\": [{\"id\": \"total\", \"label
\": \"Total\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]," | 430 String detailWithShippingOptions = "{\"items\": [{\"id\": \"total\", \"label
\": \"Total\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]," |
| 424 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \
"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]
}"; | 431 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \
"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]
}"; |
| 425 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithShippingOptions, getExceptionState()))); | 432 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithShippingOptions, getExceptionState()))); |
| 426 EXPECT_FALSE(getExceptionState().hadException()); | 433 EXPECT_FALSE(getExceptionState().hadException()); |
| 427 EXPECT_EQ("standardShippingOption", request->shippingOption()); | 434 EXPECT_EQ("standardShippingOption", request->shippingOption()); |
| 428 String detailWithoutShippingOptions = "{\"items\": [{\"id\": \"total\", \"la
bel\": \"Total\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]}"; | 435 String detailWithoutShippingOptions = "{\"items\": [{\"id\": \"total\", \"la
bel\": \"Total\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]}"; |
| 429 | 436 |
| 430 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithoutShippingOptions, getExceptionState()))); | 437 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detailWithoutShippingOptions, getExceptionState()))); |
| 431 | 438 |
| 432 EXPECT_FALSE(getExceptionState().hadException()); | 439 EXPECT_FALSE(getExceptionState().hadException()); |
| 433 EXPECT_TRUE(request->shippingOption().isNull()); | 440 EXPECT_TRUE(request->shippingOption().isNull()); |
| 434 } | 441 } |
| 435 | 442 |
| 436 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithMultiple
ShippingOptions) | 443 TEST_F(PaymentRequestTest, ClearShippingOptionOnPaymentDetailsUpdateWithMultiple
ShippingOptions) |
| 437 { | 444 { |
| 438 ScriptState::Scope scope(getScriptState()); | 445 ScriptState::Scope scope(getScriptState()); |
| 439 PaymentOptions options; | 446 PaymentOptions options; |
| 440 options.setRequestShipping(true); | 447 options.setRequestShipping(true); |
| 441 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | 448 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); |
| 442 EXPECT_FALSE(getExceptionState().hadException()); | 449 EXPECT_FALSE(getExceptionState().hadException()); |
| 443 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 450 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
| 444 String detail = "{\"items\": [{\"id\": \"total\", \"label\": \"Total\", \"am
ount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]," | 451 String detail = "{\"items\": [{\"id\": \"total\", \"label\": \"Total\", \"am
ount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]," |
| 445 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\
": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 452 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", \"amount\
": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
| 446 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}}]}"; | 453 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": \"US
D\", \"value\": \"50.00\"}}]}"; |
| 447 | 454 |
| 448 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); | 455 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); |
| 449 EXPECT_FALSE(getExceptionState().hadException()); | 456 EXPECT_FALSE(getExceptionState().hadException()); |
| 450 | 457 |
| 451 EXPECT_TRUE(request->shippingOption().isNull()); | 458 EXPECT_TRUE(request->shippingOption().isNull()); |
| 452 } | 459 } |
| 453 | 460 |
| 454 TEST_F(PaymentRequestTest, UseTheSingleShippingOptionFromPaymentDetailsUpdate) | 461 TEST_F(PaymentRequestTest, UseTheSingleShippingOptionFromPaymentDetailsUpdate) |
| 455 { | 462 { |
| 456 ScriptState::Scope scope(getScriptState()); | 463 ScriptState::Scope scope(getScriptState()); |
| 457 PaymentOptions options; | 464 PaymentOptions options; |
| 458 options.setRequestShipping(true); | 465 options.setRequestShipping(true); |
| 459 PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<St
ring>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); | 466 PaymentRequest* request = PaymentRequest::create(getScriptState(), buildPaym
entMethodDataForTest(), buildPaymentDetailsForTest(), options, getExceptionState
()); |
| 460 EXPECT_FALSE(getExceptionState().hadException()); | 467 EXPECT_FALSE(getExceptionState().hadException()); |
| 461 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); | 468 request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptSta
te()), MockFunction::expectNoCall(getScriptState())); |
| 462 String detail = "{\"items\": [{\"id\": \"total\", \"label\": \"Total\", \"am
ount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]," | 469 String detail = "{\"items\": [{\"id\": \"total\", \"label\": \"Total\", \"am
ount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]," |
| 463 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \
"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]
}"; | 470 "\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": \
"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}]
}"; |
| 464 | 471 |
| 465 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); | 472 request->onUpdatePaymentDetails(ScriptValue::from(getScriptState(), fromJSON
String(getScriptState(), detail, getExceptionState()))); |
| 466 EXPECT_FALSE(getExceptionState().hadException()); | 473 EXPECT_FALSE(getExceptionState().hadException()); |
| 467 | 474 |
| 468 EXPECT_EQ("standardShippingOption", request->shippingOption()); | 475 EXPECT_EQ("standardShippingOption", request->shippingOption()); |
| 469 } | 476 } |
| 470 | 477 |
| 471 } // namespace | 478 } // namespace |
| 472 } // namespace blink | 479 } // namespace blink |
| OLD | NEW |