| 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/V8BindingForTesting.h" | 7 #include "bindings/core/v8/V8BindingForTesting.h" |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/ExceptionCode.h" | 9 #include "core/dom/ExceptionCode.h" |
| 10 #include "modules/payments/PaymentTestHelper.h" | 10 #include "modules/payments/PaymentTestHelper.h" |
| 11 #include "platform/heap/HeapAllocator.h" | 11 #include "platform/heap/HeapAllocator.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 TEST(PaymentRequestTest, SecureContextRequired) { | 17 TEST(PaymentRequestTest, SecureContextRequired) { |
| 18 V8TestingScope scope; | 18 V8TestingScope scope; |
| 19 scope.document().setSecurityOrigin( | 19 scope.document().setSecurityOrigin( |
| 20 SecurityOrigin::create(KURL(KURL(), "http://www.example.com/"))); | 20 SecurityOrigin::create(KURL(KURL(), "http://www.example.com/"))); |
| 21 | 21 |
| 22 PaymentRequest::create( | 22 PaymentRequest::create( |
| 23 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 23 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
| 24 buildPaymentDetailsInitForTest(), scope.getExceptionState()); | 24 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 25 | 25 |
| 26 EXPECT_TRUE(scope.getExceptionState().hadException()); | 26 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 27 EXPECT_EQ(SecurityError, scope.getExceptionState().code()); | 27 EXPECT_EQ(SecurityError, scope.getExceptionState().code()); |
| 28 } | 28 } |
| 29 | 29 |
| 30 TEST(PaymentRequestTest, NoExceptionWithValidData) { | 30 TEST(PaymentRequestTest, NoExceptionWithValidData) { |
| 31 V8TestingScope scope; | 31 V8TestingScope scope; |
| 32 makePaymentRequestOriginSecure(scope.document()); | 32 makePaymentRequestOriginSecure(scope.document()); |
| 33 PaymentRequest::create( | 33 PaymentRequest::create( |
| 34 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 34 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
| 35 buildPaymentDetailsInitForTest(), scope.getExceptionState()); | 35 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 36 | 36 |
| 37 EXPECT_FALSE(scope.getExceptionState().hadException()); | 37 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 38 } | 38 } |
| 39 | 39 |
| 40 TEST(PaymentRequestTest, SupportedMethodListRequired) { | 40 TEST(PaymentRequestTest, SupportedMethodListRequired) { |
| 41 V8TestingScope scope; | 41 V8TestingScope scope; |
| 42 makePaymentRequestOriginSecure(scope.document()); | 42 makePaymentRequestOriginSecure(scope.document()); |
| 43 PaymentRequest::create( | 43 PaymentRequest::create( |
| 44 scope.getExecutionContext(), HeapVector<PaymentMethodData>(), | 44 scope.getExecutionContext(), HeapVector<PaymentMethodData>(), |
| 45 buildPaymentDetailsInitForTest(), scope.getExceptionState()); | 45 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 46 | 46 |
| 47 EXPECT_TRUE(scope.getExceptionState().hadException()); | 47 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 48 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); | 48 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 TEST(PaymentRequestTest, TotalRequired) { | 51 TEST(PaymentRequestTest, TotalRequired) { |
| 52 V8TestingScope scope; | 52 V8TestingScope scope; |
| 53 makePaymentRequestOriginSecure(scope.document()); | 53 makePaymentRequestOriginSecure(scope.document()); |
| 54 PaymentRequest::create(scope.getExecutionContext(), | 54 PaymentRequest::create(scope.getExecutionContext(), |
| 55 buildPaymentMethodDataForTest(), PaymentDetailsInit(), | 55 buildPaymentMethodDataForTest(), PaymentDetails(), |
| 56 scope.getExceptionState()); | 56 scope.getExceptionState()); |
| 57 | 57 |
| 58 EXPECT_TRUE(scope.getExceptionState().hadException()); | 58 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 59 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); | 59 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 TEST(PaymentRequestTest, ErrorMsgMustBeEmptyInConstrctor) { |
| 63 V8TestingScope scope; |
| 64 makePaymentRequestOriginSecure(scope.document()); |
| 65 PaymentRequest::create( |
| 66 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
| 67 buildPaymentDetailsErrorMsgForTest("This is an error message."), |
| 68 scope.getExceptionState()); |
| 69 |
| 70 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 71 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); |
| 72 } |
| 73 |
| 62 TEST(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) { | 74 TEST(PaymentRequestTest, NullShippingOptionWhenNoOptionsAvailable) { |
| 63 V8TestingScope scope; | 75 V8TestingScope scope; |
| 64 makePaymentRequestOriginSecure(scope.document()); | 76 makePaymentRequestOriginSecure(scope.document()); |
| 65 PaymentDetailsInit details; | 77 PaymentDetails details; |
| 66 details.setTotal(buildPaymentItemForTest()); | 78 details.setTotal(buildPaymentItemForTest()); |
| 67 PaymentOptions options; | 79 PaymentOptions options; |
| 68 options.setRequestShipping(true); | 80 options.setRequestShipping(true); |
| 69 | 81 |
| 70 PaymentRequest* request = PaymentRequest::create( | 82 PaymentRequest* request = PaymentRequest::create( |
| 71 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 83 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
| 72 options, scope.getExceptionState()); | 84 options, scope.getExceptionState()); |
| 73 | 85 |
| 74 EXPECT_TRUE(request->shippingOption().isNull()); | 86 EXPECT_TRUE(request->shippingOption().isNull()); |
| 75 } | 87 } |
| 76 | 88 |
| 77 TEST(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable) { | 89 TEST(PaymentRequestTest, NullShippingOptionWhenMultipleOptionsAvailable) { |
| 78 V8TestingScope scope; | 90 V8TestingScope scope; |
| 79 makePaymentRequestOriginSecure(scope.document()); | 91 makePaymentRequestOriginSecure(scope.document()); |
| 80 PaymentDetailsInit details; | 92 PaymentDetails details; |
| 81 details.setTotal(buildPaymentItemForTest()); | 93 details.setTotal(buildPaymentItemForTest()); |
| 82 details.setShippingOptions( | 94 details.setShippingOptions( |
| 83 HeapVector<PaymentShippingOption>(2, buildShippingOptionForTest())); | 95 HeapVector<PaymentShippingOption>(2, buildShippingOptionForTest())); |
| 84 PaymentOptions options; | 96 PaymentOptions options; |
| 85 options.setRequestShipping(true); | 97 options.setRequestShipping(true); |
| 86 | 98 |
| 87 PaymentRequest* request = PaymentRequest::create( | 99 PaymentRequest* request = PaymentRequest::create( |
| 88 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 100 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
| 89 options, scope.getExceptionState()); | 101 options, scope.getExceptionState()); |
| 90 | 102 |
| 91 EXPECT_TRUE(request->shippingOption().isNull()); | 103 EXPECT_TRUE(request->shippingOption().isNull()); |
| 92 } | 104 } |
| 93 | 105 |
| 94 TEST(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault) { | 106 TEST(PaymentRequestTest, DontSelectSingleAvailableShippingOptionByDefault) { |
| 95 V8TestingScope scope; | 107 V8TestingScope scope; |
| 96 makePaymentRequestOriginSecure(scope.document()); | 108 makePaymentRequestOriginSecure(scope.document()); |
| 97 PaymentDetailsInit details; | 109 PaymentDetails details; |
| 98 details.setTotal(buildPaymentItemForTest()); | 110 details.setTotal(buildPaymentItemForTest()); |
| 99 details.setShippingOptions(HeapVector<PaymentShippingOption>( | 111 details.setShippingOptions(HeapVector<PaymentShippingOption>( |
| 100 1, | 112 1, |
| 101 buildShippingOptionForTest(PaymentTestDataId, PaymentTestOverwriteValue, | 113 buildShippingOptionForTest(PaymentTestDataId, PaymentTestOverwriteValue, |
| 102 "standard"))); | 114 "standard"))); |
| 103 | 115 |
| 104 PaymentRequest* request = PaymentRequest::create( | 116 PaymentRequest* request = PaymentRequest::create( |
| 105 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 117 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
| 106 scope.getExceptionState()); | 118 scope.getExceptionState()); |
| 107 | 119 |
| 108 EXPECT_TRUE(request->shippingOption().isNull()); | 120 EXPECT_TRUE(request->shippingOption().isNull()); |
| 109 } | 121 } |
| 110 | 122 |
| 111 TEST(PaymentRequestTest, | 123 TEST(PaymentRequestTest, |
| 112 DontSelectSingleAvailableShippingOptionWhenShippingNotRequested) { | 124 DontSelectSingleAvailableShippingOptionWhenShippingNotRequested) { |
| 113 V8TestingScope scope; | 125 V8TestingScope scope; |
| 114 makePaymentRequestOriginSecure(scope.document()); | 126 makePaymentRequestOriginSecure(scope.document()); |
| 115 PaymentDetailsInit details; | 127 PaymentDetails details; |
| 116 details.setTotal(buildPaymentItemForTest()); | 128 details.setTotal(buildPaymentItemForTest()); |
| 117 details.setShippingOptions( | 129 details.setShippingOptions( |
| 118 HeapVector<PaymentShippingOption>(1, buildShippingOptionForTest())); | 130 HeapVector<PaymentShippingOption>(1, buildShippingOptionForTest())); |
| 119 PaymentOptions options; | 131 PaymentOptions options; |
| 120 options.setRequestShipping(false); | 132 options.setRequestShipping(false); |
| 121 | 133 |
| 122 PaymentRequest* request = PaymentRequest::create( | 134 PaymentRequest* request = PaymentRequest::create( |
| 123 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 135 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
| 124 options, scope.getExceptionState()); | 136 options, scope.getExceptionState()); |
| 125 | 137 |
| 126 EXPECT_TRUE(request->shippingOption().isNull()); | 138 EXPECT_TRUE(request->shippingOption().isNull()); |
| 127 } | 139 } |
| 128 | 140 |
| 129 TEST(PaymentRequestTest, | 141 TEST(PaymentRequestTest, |
| 130 DontSelectSingleUnselectedShippingOptionWhenShippingRequested) { | 142 DontSelectSingleUnselectedShippingOptionWhenShippingRequested) { |
| 131 V8TestingScope scope; | 143 V8TestingScope scope; |
| 132 makePaymentRequestOriginSecure(scope.document()); | 144 makePaymentRequestOriginSecure(scope.document()); |
| 133 PaymentDetailsInit details; | 145 PaymentDetails details; |
| 134 details.setTotal(buildPaymentItemForTest()); | 146 details.setTotal(buildPaymentItemForTest()); |
| 135 details.setShippingOptions( | 147 details.setShippingOptions( |
| 136 HeapVector<PaymentShippingOption>(1, buildShippingOptionForTest())); | 148 HeapVector<PaymentShippingOption>(1, buildShippingOptionForTest())); |
| 137 PaymentOptions options; | 149 PaymentOptions options; |
| 138 options.setRequestShipping(true); | 150 options.setRequestShipping(true); |
| 139 | 151 |
| 140 PaymentRequest* request = PaymentRequest::create( | 152 PaymentRequest* request = PaymentRequest::create( |
| 141 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 153 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
| 142 options, scope.getExceptionState()); | 154 options, scope.getExceptionState()); |
| 143 | 155 |
| 144 EXPECT_TRUE(request->shippingOption().isNull()); | 156 EXPECT_TRUE(request->shippingOption().isNull()); |
| 145 } | 157 } |
| 146 | 158 |
| 147 TEST(PaymentRequestTest, | 159 TEST(PaymentRequestTest, |
| 148 SelectSingleSelectedShippingOptionWhenShippingRequested) { | 160 SelectSingleSelectedShippingOptionWhenShippingRequested) { |
| 149 V8TestingScope scope; | 161 V8TestingScope scope; |
| 150 makePaymentRequestOriginSecure(scope.document()); | 162 makePaymentRequestOriginSecure(scope.document()); |
| 151 PaymentDetailsInit details; | 163 PaymentDetails details; |
| 152 details.setTotal(buildPaymentItemForTest()); | 164 details.setTotal(buildPaymentItemForTest()); |
| 153 HeapVector<PaymentShippingOption> shippingOptions( | 165 HeapVector<PaymentShippingOption> shippingOptions( |
| 154 1, | 166 1, |
| 155 buildShippingOptionForTest(PaymentTestDataId, PaymentTestOverwriteValue, | 167 buildShippingOptionForTest(PaymentTestDataId, PaymentTestOverwriteValue, |
| 156 "standard")); | 168 "standard")); |
| 157 shippingOptions[0].setSelected(true); | 169 shippingOptions[0].setSelected(true); |
| 158 details.setShippingOptions(shippingOptions); | 170 details.setShippingOptions(shippingOptions); |
| 159 PaymentOptions options; | 171 PaymentOptions options; |
| 160 options.setRequestShipping(true); | 172 options.setRequestShipping(true); |
| 161 | 173 |
| 162 PaymentRequest* request = PaymentRequest::create( | 174 PaymentRequest* request = PaymentRequest::create( |
| 163 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 175 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
| 164 options, scope.getExceptionState()); | 176 options, scope.getExceptionState()); |
| 165 | 177 |
| 166 EXPECT_EQ("standard", request->shippingOption()); | 178 EXPECT_EQ("standard", request->shippingOption()); |
| 167 } | 179 } |
| 168 | 180 |
| 169 TEST(PaymentRequestTest, | 181 TEST(PaymentRequestTest, |
| 170 SelectOnlySelectedShippingOptionWhenShippingRequested) { | 182 SelectOnlySelectedShippingOptionWhenShippingRequested) { |
| 171 V8TestingScope scope; | 183 V8TestingScope scope; |
| 172 makePaymentRequestOriginSecure(scope.document()); | 184 makePaymentRequestOriginSecure(scope.document()); |
| 173 PaymentDetailsInit details; | 185 PaymentDetails details; |
| 174 details.setTotal(buildPaymentItemForTest()); | 186 details.setTotal(buildPaymentItemForTest()); |
| 175 HeapVector<PaymentShippingOption> shippingOptions(2); | 187 HeapVector<PaymentShippingOption> shippingOptions(2); |
| 176 shippingOptions[0] = buildShippingOptionForTest( | 188 shippingOptions[0] = buildShippingOptionForTest( |
| 177 PaymentTestDataId, PaymentTestOverwriteValue, "standard"); | 189 PaymentTestDataId, PaymentTestOverwriteValue, "standard"); |
| 178 shippingOptions[0].setSelected(true); | 190 shippingOptions[0].setSelected(true); |
| 179 shippingOptions[1] = buildShippingOptionForTest( | 191 shippingOptions[1] = buildShippingOptionForTest( |
| 180 PaymentTestDataId, PaymentTestOverwriteValue, "express"); | 192 PaymentTestDataId, PaymentTestOverwriteValue, "express"); |
| 181 details.setShippingOptions(shippingOptions); | 193 details.setShippingOptions(shippingOptions); |
| 182 PaymentOptions options; | 194 PaymentOptions options; |
| 183 options.setRequestShipping(true); | 195 options.setRequestShipping(true); |
| 184 | 196 |
| 185 PaymentRequest* request = PaymentRequest::create( | 197 PaymentRequest* request = PaymentRequest::create( |
| 186 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 198 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
| 187 options, scope.getExceptionState()); | 199 options, scope.getExceptionState()); |
| 188 | 200 |
| 189 EXPECT_EQ("standard", request->shippingOption()); | 201 EXPECT_EQ("standard", request->shippingOption()); |
| 190 } | 202 } |
| 191 | 203 |
| 192 TEST(PaymentRequestTest, | 204 TEST(PaymentRequestTest, |
| 193 SelectLastSelectedShippingOptionWhenShippingRequested) { | 205 SelectLastSelectedShippingOptionWhenShippingRequested) { |
| 194 V8TestingScope scope; | 206 V8TestingScope scope; |
| 195 makePaymentRequestOriginSecure(scope.document()); | 207 makePaymentRequestOriginSecure(scope.document()); |
| 196 PaymentDetailsInit details; | 208 PaymentDetails details; |
| 197 details.setTotal(buildPaymentItemForTest()); | 209 details.setTotal(buildPaymentItemForTest()); |
| 198 HeapVector<PaymentShippingOption> shippingOptions(2); | 210 HeapVector<PaymentShippingOption> shippingOptions(2); |
| 199 shippingOptions[0] = buildShippingOptionForTest( | 211 shippingOptions[0] = buildShippingOptionForTest( |
| 200 PaymentTestDataId, PaymentTestOverwriteValue, "standard"); | 212 PaymentTestDataId, PaymentTestOverwriteValue, "standard"); |
| 201 shippingOptions[0].setSelected(true); | 213 shippingOptions[0].setSelected(true); |
| 202 shippingOptions[1] = buildShippingOptionForTest( | 214 shippingOptions[1] = buildShippingOptionForTest( |
| 203 PaymentTestDataId, PaymentTestOverwriteValue, "express"); | 215 PaymentTestDataId, PaymentTestOverwriteValue, "express"); |
| 204 shippingOptions[1].setSelected(true); | 216 shippingOptions[1].setSelected(true); |
| 205 details.setShippingOptions(shippingOptions); | 217 details.setShippingOptions(shippingOptions); |
| 206 PaymentOptions options; | 218 PaymentOptions options; |
| 207 options.setRequestShipping(true); | 219 options.setRequestShipping(true); |
| 208 | 220 |
| 209 PaymentRequest* request = PaymentRequest::create( | 221 PaymentRequest* request = PaymentRequest::create( |
| 210 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 222 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
| 211 options, scope.getExceptionState()); | 223 options, scope.getExceptionState()); |
| 212 | 224 |
| 213 EXPECT_EQ("express", request->shippingOption()); | 225 EXPECT_EQ("express", request->shippingOption()); |
| 214 } | 226 } |
| 215 | 227 |
| 216 TEST(PaymentRequestTest, NullShippingTypeWhenRequestShippingIsFalse) { | 228 TEST(PaymentRequestTest, NullShippingTypeWhenRequestShippingIsFalse) { |
| 217 V8TestingScope scope; | 229 V8TestingScope scope; |
| 218 makePaymentRequestOriginSecure(scope.document()); | 230 makePaymentRequestOriginSecure(scope.document()); |
| 219 PaymentDetailsInit details; | 231 PaymentDetails details; |
| 220 details.setTotal(buildPaymentItemForTest()); | 232 details.setTotal(buildPaymentItemForTest()); |
| 221 PaymentOptions options; | 233 PaymentOptions options; |
| 222 options.setRequestShipping(false); | 234 options.setRequestShipping(false); |
| 223 | 235 |
| 224 PaymentRequest* request = PaymentRequest::create( | 236 PaymentRequest* request = PaymentRequest::create( |
| 225 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 237 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
| 226 options, scope.getExceptionState()); | 238 options, scope.getExceptionState()); |
| 227 | 239 |
| 228 EXPECT_TRUE(request->shippingType().isNull()); | 240 EXPECT_TRUE(request->shippingType().isNull()); |
| 229 } | 241 } |
| 230 | 242 |
| 231 TEST(PaymentRequestTest, | 243 TEST(PaymentRequestTest, |
| 232 DefaultShippingTypeWhenRequestShippingIsTrueWithNoSpecificType) { | 244 DefaultShippingTypeWhenRequestShippingIsTrueWithNoSpecificType) { |
| 233 V8TestingScope scope; | 245 V8TestingScope scope; |
| 234 makePaymentRequestOriginSecure(scope.document()); | 246 makePaymentRequestOriginSecure(scope.document()); |
| 235 PaymentDetailsInit details; | 247 PaymentDetails details; |
| 236 details.setTotal(buildPaymentItemForTest()); | 248 details.setTotal(buildPaymentItemForTest()); |
| 237 PaymentOptions options; | 249 PaymentOptions options; |
| 238 options.setRequestShipping(true); | 250 options.setRequestShipping(true); |
| 239 | 251 |
| 240 PaymentRequest* request = PaymentRequest::create( | 252 PaymentRequest* request = PaymentRequest::create( |
| 241 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 253 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
| 242 options, scope.getExceptionState()); | 254 options, scope.getExceptionState()); |
| 243 | 255 |
| 244 EXPECT_EQ("shipping", request->shippingType()); | 256 EXPECT_EQ("shipping", request->shippingType()); |
| 245 } | 257 } |
| 246 | 258 |
| 247 TEST(PaymentRequestTest, DeliveryShippingTypeWhenShippingTypeIsDelivery) { | 259 TEST(PaymentRequestTest, DeliveryShippingTypeWhenShippingTypeIsDelivery) { |
| 248 V8TestingScope scope; | 260 V8TestingScope scope; |
| 249 makePaymentRequestOriginSecure(scope.document()); | 261 makePaymentRequestOriginSecure(scope.document()); |
| 250 PaymentDetailsInit details; | 262 PaymentDetails details; |
| 251 details.setTotal(buildPaymentItemForTest()); | 263 details.setTotal(buildPaymentItemForTest()); |
| 252 PaymentOptions options; | 264 PaymentOptions options; |
| 253 options.setRequestShipping(true); | 265 options.setRequestShipping(true); |
| 254 options.setShippingType("delivery"); | 266 options.setShippingType("delivery"); |
| 255 | 267 |
| 256 PaymentRequest* request = PaymentRequest::create( | 268 PaymentRequest* request = PaymentRequest::create( |
| 257 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 269 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
| 258 options, scope.getExceptionState()); | 270 options, scope.getExceptionState()); |
| 259 | 271 |
| 260 EXPECT_EQ("delivery", request->shippingType()); | 272 EXPECT_EQ("delivery", request->shippingType()); |
| 261 } | 273 } |
| 262 | 274 |
| 263 TEST(PaymentRequestTest, PickupShippingTypeWhenShippingTypeIsPickup) { | 275 TEST(PaymentRequestTest, PickupShippingTypeWhenShippingTypeIsPickup) { |
| 264 V8TestingScope scope; | 276 V8TestingScope scope; |
| 265 makePaymentRequestOriginSecure(scope.document()); | 277 makePaymentRequestOriginSecure(scope.document()); |
| 266 PaymentDetailsInit details; | 278 PaymentDetails details; |
| 267 details.setTotal(buildPaymentItemForTest()); | 279 details.setTotal(buildPaymentItemForTest()); |
| 268 PaymentOptions options; | 280 PaymentOptions options; |
| 269 options.setRequestShipping(true); | 281 options.setRequestShipping(true); |
| 270 options.setShippingType("pickup"); | 282 options.setShippingType("pickup"); |
| 271 | 283 |
| 272 PaymentRequest* request = PaymentRequest::create( | 284 PaymentRequest* request = PaymentRequest::create( |
| 273 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 285 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
| 274 options, scope.getExceptionState()); | 286 options, scope.getExceptionState()); |
| 275 | 287 |
| 276 EXPECT_EQ("pickup", request->shippingType()); | 288 EXPECT_EQ("pickup", request->shippingType()); |
| 277 } | 289 } |
| 278 | 290 |
| 279 TEST(PaymentRequestTest, DefaultShippingTypeWhenShippingTypeIsInvalid) { | 291 TEST(PaymentRequestTest, DefaultShippingTypeWhenShippingTypeIsInvalid) { |
| 280 V8TestingScope scope; | 292 V8TestingScope scope; |
| 281 makePaymentRequestOriginSecure(scope.document()); | 293 makePaymentRequestOriginSecure(scope.document()); |
| 282 PaymentDetailsInit details; | 294 PaymentDetails details; |
| 283 details.setTotal(buildPaymentItemForTest()); | 295 details.setTotal(buildPaymentItemForTest()); |
| 284 PaymentOptions options; | 296 PaymentOptions options; |
| 285 options.setRequestShipping(true); | 297 options.setRequestShipping(true); |
| 286 options.setShippingType("invalid"); | 298 options.setShippingType("invalid"); |
| 287 | 299 |
| 288 PaymentRequest* request = PaymentRequest::create( | 300 PaymentRequest* request = PaymentRequest::create( |
| 289 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 301 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
| 290 options, scope.getExceptionState()); | 302 options, scope.getExceptionState()); |
| 291 | 303 |
| 292 EXPECT_EQ("shipping", request->shippingType()); | 304 EXPECT_EQ("shipping", request->shippingType()); |
| 293 } | 305 } |
| 294 | 306 |
| 295 TEST(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress) { | 307 TEST(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress) { |
| 296 V8TestingScope scope; | 308 V8TestingScope scope; |
| 297 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 309 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 298 makePaymentRequestOriginSecure(scope.document()); | 310 makePaymentRequestOriginSecure(scope.document()); |
| 299 PaymentRequest* request = PaymentRequest::create( | 311 PaymentRequest* request = PaymentRequest::create( |
| 300 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 312 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
| 301 buildPaymentDetailsInitForTest(), scope.getExceptionState()); | 313 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 302 EXPECT_FALSE(scope.getExceptionState().hadException()); | 314 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 303 | 315 |
| 304 request->show(scope.getScriptState()) | 316 request->show(scope.getScriptState()) |
| 305 .then(funcs.expectNoCall(), funcs.expectCall()); | 317 .then(funcs.expectNoCall(), funcs.expectCall()); |
| 306 | 318 |
| 307 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 319 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 308 ->OnShippingAddressChange(payments::mojom::blink::PaymentAddress::New()); | 320 ->OnShippingAddressChange(payments::mojom::blink::PaymentAddress::New()); |
| 309 } | 321 } |
| 310 | 322 |
| 311 TEST(PaymentRequestTest, OnShippingOptionChange) { | 323 TEST(PaymentRequestTest, OnShippingOptionChange) { |
| 312 V8TestingScope scope; | 324 V8TestingScope scope; |
| 313 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 325 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 314 makePaymentRequestOriginSecure(scope.document()); | 326 makePaymentRequestOriginSecure(scope.document()); |
| 315 PaymentRequest* request = PaymentRequest::create( | 327 PaymentRequest* request = PaymentRequest::create( |
| 316 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 328 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
| 317 buildPaymentDetailsInitForTest(), scope.getExceptionState()); | 329 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 318 EXPECT_FALSE(scope.getExceptionState().hadException()); | 330 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 319 | 331 |
| 320 request->show(scope.getScriptState()) | 332 request->show(scope.getScriptState()) |
| 321 .then(funcs.expectNoCall(), funcs.expectNoCall()); | 333 .then(funcs.expectNoCall(), funcs.expectNoCall()); |
| 322 | 334 |
| 323 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 335 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 324 ->OnShippingOptionChange("standardShipping"); | 336 ->OnShippingOptionChange("standardShipping"); |
| 325 } | 337 } |
| 326 | 338 |
| 327 TEST(PaymentRequestTest, CannotCallShowTwice) { | 339 TEST(PaymentRequestTest, CannotCallShowTwice) { |
| 328 V8TestingScope scope; | 340 V8TestingScope scope; |
| 329 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 341 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 330 makePaymentRequestOriginSecure(scope.document()); | 342 makePaymentRequestOriginSecure(scope.document()); |
| 331 PaymentRequest* request = PaymentRequest::create( | 343 PaymentRequest* request = PaymentRequest::create( |
| 332 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 344 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
| 333 buildPaymentDetailsInitForTest(), scope.getExceptionState()); | 345 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 334 EXPECT_FALSE(scope.getExceptionState().hadException()); | 346 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 335 request->show(scope.getScriptState()); | 347 request->show(scope.getScriptState()); |
| 336 | 348 |
| 337 request->show(scope.getScriptState()) | 349 request->show(scope.getScriptState()) |
| 338 .then(funcs.expectNoCall(), funcs.expectCall()); | 350 .then(funcs.expectNoCall(), funcs.expectCall()); |
| 339 } | 351 } |
| 340 | 352 |
| 341 TEST(PaymentRequestTest, CannotShowAfterAborted) { | 353 TEST(PaymentRequestTest, CannotShowAfterAborted) { |
| 342 V8TestingScope scope; | 354 V8TestingScope scope; |
| 343 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 355 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 344 makePaymentRequestOriginSecure(scope.document()); | 356 makePaymentRequestOriginSecure(scope.document()); |
| 345 PaymentRequest* request = PaymentRequest::create( | 357 PaymentRequest* request = PaymentRequest::create( |
| 346 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 358 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
| 347 buildPaymentDetailsInitForTest(), scope.getExceptionState()); | 359 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 348 EXPECT_FALSE(scope.getExceptionState().hadException()); | 360 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 349 request->show(scope.getScriptState()); | 361 request->show(scope.getScriptState()); |
| 350 request->abort(scope.getScriptState()); | 362 request->abort(scope.getScriptState()); |
| 351 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( | 363 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnAbort( |
| 352 true); | 364 true); |
| 353 | 365 |
| 354 request->show(scope.getScriptState()) | 366 request->show(scope.getScriptState()) |
| 355 .then(funcs.expectNoCall(), funcs.expectCall()); | 367 .then(funcs.expectNoCall(), funcs.expectCall()); |
| 356 } | 368 } |
| 357 | 369 |
| 358 TEST(PaymentRequestTest, RejectShowPromiseOnErrorPaymentMethodNotSupported) { | 370 TEST(PaymentRequestTest, RejectShowPromiseOnErrorPaymentMethodNotSupported) { |
| 359 V8TestingScope scope; | 371 V8TestingScope scope; |
| 360 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 372 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 361 makePaymentRequestOriginSecure(scope.document()); | 373 makePaymentRequestOriginSecure(scope.document()); |
| 362 PaymentRequest* request = PaymentRequest::create( | 374 PaymentRequest* request = PaymentRequest::create( |
| 363 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 375 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
| 364 buildPaymentDetailsInitForTest(), scope.getExceptionState()); | 376 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 365 EXPECT_FALSE(scope.getExceptionState().hadException()); | 377 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 366 | 378 |
| 367 String errorMessage; | 379 String errorMessage; |
| 368 request->show(scope.getScriptState()) | 380 request->show(scope.getScriptState()) |
| 369 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); | 381 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); |
| 370 | 382 |
| 371 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnError( | 383 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnError( |
| 372 payments::mojom::blink::PaymentErrorReason::NOT_SUPPORTED); | 384 payments::mojom::blink::PaymentErrorReason::NOT_SUPPORTED); |
| 373 | 385 |
| 374 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); | 386 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); |
| 375 EXPECT_EQ("NotSupportedError: The payment method is not supported", | 387 EXPECT_EQ("NotSupportedError: The payment method is not supported", |
| 376 errorMessage); | 388 errorMessage); |
| 377 } | 389 } |
| 378 | 390 |
| 379 TEST(PaymentRequestTest, RejectShowPromiseOnErrorCancelled) { | 391 TEST(PaymentRequestTest, RejectShowPromiseOnErrorCancelled) { |
| 380 V8TestingScope scope; | 392 V8TestingScope scope; |
| 381 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 393 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 382 makePaymentRequestOriginSecure(scope.document()); | 394 makePaymentRequestOriginSecure(scope.document()); |
| 383 PaymentRequest* request = PaymentRequest::create( | 395 PaymentRequest* request = PaymentRequest::create( |
| 384 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 396 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
| 385 buildPaymentDetailsInitForTest(), scope.getExceptionState()); | 397 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 386 EXPECT_FALSE(scope.getExceptionState().hadException()); | 398 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 387 | 399 |
| 388 String errorMessage; | 400 String errorMessage; |
| 389 request->show(scope.getScriptState()) | 401 request->show(scope.getScriptState()) |
| 390 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); | 402 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); |
| 391 | 403 |
| 392 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnError( | 404 static_cast<payments::mojom::blink::PaymentRequestClient*>(request)->OnError( |
| 393 payments::mojom::blink::PaymentErrorReason::USER_CANCEL); | 405 payments::mojom::blink::PaymentErrorReason::USER_CANCEL); |
| 394 | 406 |
| 395 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); | 407 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); |
| 396 EXPECT_EQ("AbortError: Request cancelled", errorMessage); | 408 EXPECT_EQ("AbortError: Request cancelled", errorMessage); |
| 397 } | 409 } |
| 398 | 410 |
| 399 TEST(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) { | 411 TEST(PaymentRequestTest, RejectShowPromiseOnUpdateDetailsFailure) { |
| 400 V8TestingScope scope; | 412 V8TestingScope scope; |
| 401 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 413 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 402 makePaymentRequestOriginSecure(scope.document()); | 414 makePaymentRequestOriginSecure(scope.document()); |
| 403 PaymentRequest* request = PaymentRequest::create( | 415 PaymentRequest* request = PaymentRequest::create( |
| 404 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 416 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
| 405 buildPaymentDetailsInitForTest(), scope.getExceptionState()); | 417 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 406 EXPECT_FALSE(scope.getExceptionState().hadException()); | 418 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 407 | 419 |
| 408 String errorMessage; | 420 String errorMessage; |
| 409 request->show(scope.getScriptState()) | 421 request->show(scope.getScriptState()) |
| 410 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); | 422 .then(funcs.expectNoCall(), funcs.expectCall(&errorMessage)); |
| 411 | 423 |
| 412 request->onUpdatePaymentDetailsFailure("oops"); | 424 request->onUpdatePaymentDetailsFailure("oops"); |
| 413 | 425 |
| 414 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); | 426 v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate()); |
| 415 EXPECT_EQ("AbortError: oops", errorMessage); | 427 EXPECT_EQ("AbortError: oops", errorMessage); |
| 416 } | 428 } |
| 417 | 429 |
| 418 TEST(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) { | 430 TEST(PaymentRequestTest, IgnoreUpdatePaymentDetailsAfterShowPromiseResolved) { |
| 419 V8TestingScope scope; | 431 V8TestingScope scope; |
| 420 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 432 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 421 makePaymentRequestOriginSecure(scope.document()); | 433 makePaymentRequestOriginSecure(scope.document()); |
| 422 PaymentRequest* request = PaymentRequest::create( | 434 PaymentRequest* request = PaymentRequest::create( |
| 423 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 435 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
| 424 buildPaymentDetailsInitForTest(), scope.getExceptionState()); | 436 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 425 EXPECT_FALSE(scope.getExceptionState().hadException()); | 437 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 426 request->show(scope.getScriptState()) | 438 request->show(scope.getScriptState()) |
| 427 .then(funcs.expectCall(), funcs.expectNoCall()); | 439 .then(funcs.expectCall(), funcs.expectNoCall()); |
| 428 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 440 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 429 ->OnPaymentResponse(buildPaymentResponseForTest()); | 441 ->OnPaymentResponse(buildPaymentResponseForTest()); |
| 430 | 442 |
| 431 request->onUpdatePaymentDetails( | 443 request->onUpdatePaymentDetails( |
| 432 ScriptValue::from(scope.getScriptState(), "foo")); | 444 ScriptValue::from(scope.getScriptState(), "foo")); |
| 433 } | 445 } |
| 434 | 446 |
| 435 TEST(PaymentRequestTest, RejectShowPromiseOnNonPaymentDetailsUpdate) { | 447 TEST(PaymentRequestTest, RejectShowPromiseOnNonPaymentDetailsUpdate) { |
| 436 V8TestingScope scope; | 448 V8TestingScope scope; |
| 437 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 449 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 438 makePaymentRequestOriginSecure(scope.document()); | 450 makePaymentRequestOriginSecure(scope.document()); |
| 439 PaymentRequest* request = PaymentRequest::create( | 451 PaymentRequest* request = PaymentRequest::create( |
| 440 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 452 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
| 441 buildPaymentDetailsInitForTest(), scope.getExceptionState()); | 453 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 442 EXPECT_FALSE(scope.getExceptionState().hadException()); | 454 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 443 | 455 |
| 444 request->show(scope.getScriptState()) | 456 request->show(scope.getScriptState()) |
| 445 .then(funcs.expectNoCall(), funcs.expectCall()); | 457 .then(funcs.expectNoCall(), funcs.expectCall()); |
| 446 | 458 |
| 447 request->onUpdatePaymentDetails( | 459 request->onUpdatePaymentDetails( |
| 448 ScriptValue::from(scope.getScriptState(), "NotPaymentDetails")); | 460 ScriptValue::from(scope.getScriptState(), "NotPaymentDetails")); |
| 449 } | 461 } |
| 450 | 462 |
| 451 TEST(PaymentRequestTest, RejectShowPromiseOnInvalidPaymentDetailsUpdate) { | 463 TEST(PaymentRequestTest, RejectShowPromiseOnInvalidPaymentDetailsUpdate) { |
| 452 V8TestingScope scope; | 464 V8TestingScope scope; |
| 453 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 465 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 454 makePaymentRequestOriginSecure(scope.document()); | 466 makePaymentRequestOriginSecure(scope.document()); |
| 455 PaymentRequest* request = PaymentRequest::create( | 467 PaymentRequest* request = PaymentRequest::create( |
| 456 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 468 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
| 457 buildPaymentDetailsInitForTest(), scope.getExceptionState()); | 469 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 458 EXPECT_FALSE(scope.getExceptionState().hadException()); | 470 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 459 | 471 |
| 460 request->show(scope.getScriptState()) | 472 request->show(scope.getScriptState()) |
| 461 .then(funcs.expectNoCall(), funcs.expectCall()); | 473 .then(funcs.expectNoCall(), funcs.expectCall()); |
| 462 | 474 |
| 463 request->onUpdatePaymentDetails(ScriptValue::from( | 475 request->onUpdatePaymentDetails( |
| 464 scope.getScriptState(), | 476 ScriptValue::from(scope.getScriptState(), |
| 465 fromJSONString(scope.getScriptState()->isolate(), "{\"total\": {}}", | 477 fromJSONString(scope.getScriptState()->isolate(), "{}", |
| 466 scope.getExceptionState()))); | 478 scope.getExceptionState()))); |
| 467 EXPECT_FALSE(scope.getExceptionState().hadException()); | 479 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 468 } | 480 } |
| 469 | 481 |
| 470 TEST(PaymentRequestTest, | 482 TEST(PaymentRequestTest, |
| 471 ClearShippingOptionOnPaymentDetailsUpdateWithoutShippingOptions) { | 483 ClearShippingOptionOnPaymentDetailsUpdateWithoutShippingOptions) { |
| 472 V8TestingScope scope; | 484 V8TestingScope scope; |
| 473 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 485 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 474 makePaymentRequestOriginSecure(scope.document()); | 486 makePaymentRequestOriginSecure(scope.document()); |
| 475 PaymentDetailsInit details; | 487 PaymentDetails details; |
| 476 details.setTotal(buildPaymentItemForTest()); | 488 details.setTotal(buildPaymentItemForTest()); |
| 477 PaymentOptions options; | 489 PaymentOptions options; |
| 478 options.setRequestShipping(true); | 490 options.setRequestShipping(true); |
| 479 PaymentRequest* request = PaymentRequest::create( | 491 PaymentRequest* request = PaymentRequest::create( |
| 480 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, | 492 scope.getExecutionContext(), buildPaymentMethodDataForTest(), details, |
| 481 options, scope.getExceptionState()); | 493 options, scope.getExceptionState()); |
| 482 EXPECT_FALSE(scope.getExceptionState().hadException()); | 494 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 483 EXPECT_TRUE(request->shippingOption().isNull()); | 495 EXPECT_TRUE(request->shippingOption().isNull()); |
| 484 request->show(scope.getScriptState()) | 496 request->show(scope.getScriptState()) |
| 485 .then(funcs.expectNoCall(), funcs.expectNoCall()); | 497 .then(funcs.expectNoCall(), funcs.expectNoCall()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 511 TEST( | 523 TEST( |
| 512 PaymentRequestTest, | 524 PaymentRequestTest, |
| 513 ClearShippingOptionOnPaymentDetailsUpdateWithMultipleUnselectedShippingOptio
ns) { | 525 ClearShippingOptionOnPaymentDetailsUpdateWithMultipleUnselectedShippingOptio
ns) { |
| 514 V8TestingScope scope; | 526 V8TestingScope scope; |
| 515 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 527 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 516 makePaymentRequestOriginSecure(scope.document()); | 528 makePaymentRequestOriginSecure(scope.document()); |
| 517 PaymentOptions options; | 529 PaymentOptions options; |
| 518 options.setRequestShipping(true); | 530 options.setRequestShipping(true); |
| 519 PaymentRequest* request = PaymentRequest::create( | 531 PaymentRequest* request = PaymentRequest::create( |
| 520 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 532 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
| 521 buildPaymentDetailsInitForTest(), options, scope.getExceptionState()); | 533 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 522 EXPECT_FALSE(scope.getExceptionState().hadException()); | 534 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 523 request->show(scope.getScriptState()) | 535 request->show(scope.getScriptState()) |
| 524 .then(funcs.expectNoCall(), funcs.expectNoCall()); | 536 .then(funcs.expectNoCall(), funcs.expectNoCall()); |
| 525 String detail = | 537 String detail = |
| 526 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " | 538 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " |
| 527 "\"value\": \"5.00\"}}," | 539 "\"value\": \"5.00\"}}," |
| 528 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", " | 540 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", " |
| 529 "\"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 541 "\"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
| 530 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": " | 542 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": " |
| 531 "\"USD\", \"value\": \"50.00\"}}]}"; | 543 "\"USD\", \"value\": \"50.00\"}}]}"; |
| 532 | 544 |
| 533 request->onUpdatePaymentDetails( | 545 request->onUpdatePaymentDetails( |
| 534 ScriptValue::from(scope.getScriptState(), | 546 ScriptValue::from(scope.getScriptState(), |
| 535 fromJSONString(scope.getScriptState()->isolate(), | 547 fromJSONString(scope.getScriptState()->isolate(), |
| 536 detail, scope.getExceptionState()))); | 548 detail, scope.getExceptionState()))); |
| 537 EXPECT_FALSE(scope.getExceptionState().hadException()); | 549 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 538 | 550 |
| 539 EXPECT_TRUE(request->shippingOption().isNull()); | 551 EXPECT_TRUE(request->shippingOption().isNull()); |
| 540 } | 552 } |
| 541 | 553 |
| 542 TEST(PaymentRequestTest, UseTheSelectedShippingOptionFromPaymentDetailsUpdate) { | 554 TEST(PaymentRequestTest, UseTheSelectedShippingOptionFromPaymentDetailsUpdate) { |
| 543 V8TestingScope scope; | 555 V8TestingScope scope; |
| 544 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 556 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 545 makePaymentRequestOriginSecure(scope.document()); | 557 makePaymentRequestOriginSecure(scope.document()); |
| 546 PaymentOptions options; | 558 PaymentOptions options; |
| 547 options.setRequestShipping(true); | 559 options.setRequestShipping(true); |
| 548 PaymentRequest* request = PaymentRequest::create( | 560 PaymentRequest* request = PaymentRequest::create( |
| 549 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 561 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
| 550 buildPaymentDetailsInitForTest(), options, scope.getExceptionState()); | 562 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 551 EXPECT_FALSE(scope.getExceptionState().hadException()); | 563 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 552 request->show(scope.getScriptState()) | 564 request->show(scope.getScriptState()) |
| 553 .then(funcs.expectNoCall(), funcs.expectNoCall()); | 565 .then(funcs.expectNoCall(), funcs.expectNoCall()); |
| 554 String detail = | 566 String detail = |
| 555 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " | 567 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " |
| 556 "\"value\": \"5.00\"}}," | 568 "\"value\": \"5.00\"}}," |
| 557 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", " | 569 "\"shippingOptions\": [{\"id\": \"slow\", \"label\": \"Slow\", " |
| 558 "\"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," | 570 "\"amount\": {\"currency\": \"USD\", \"value\": \"5.00\"}}," |
| 559 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": " | 571 "{\"id\": \"fast\", \"label\": \"Fast\", \"amount\": {\"currency\": " |
| 560 "\"USD\", \"value\": \"50.00\"}, \"selected\": true}]}"; | 572 "\"USD\", \"value\": \"50.00\"}, \"selected\": true}]}"; |
| 561 | 573 |
| 562 request->onUpdatePaymentDetails( | 574 request->onUpdatePaymentDetails( |
| 563 ScriptValue::from(scope.getScriptState(), | 575 ScriptValue::from(scope.getScriptState(), |
| 564 fromJSONString(scope.getScriptState()->isolate(), | 576 fromJSONString(scope.getScriptState()->isolate(), |
| 565 detail, scope.getExceptionState()))); | 577 detail, scope.getExceptionState()))); |
| 566 EXPECT_FALSE(scope.getExceptionState().hadException()); | 578 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 567 | 579 |
| 568 EXPECT_EQ("fast", request->shippingOption()); | 580 EXPECT_EQ("fast", request->shippingOption()); |
| 569 } | 581 } |
| 570 | 582 |
| 571 TEST(PaymentRequestTest, NoExceptionWithErrorMessageInUpdate) { | 583 TEST(PaymentRequestTest, NoExceptionWithErrorMessageInUpdate) { |
| 572 V8TestingScope scope; | 584 V8TestingScope scope; |
| 573 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 585 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 574 makePaymentRequestOriginSecure(scope.document()); | 586 makePaymentRequestOriginSecure(scope.document()); |
| 575 PaymentRequest* request = PaymentRequest::create( | 587 PaymentRequest* request = PaymentRequest::create( |
| 576 scope.getExecutionContext(), buildPaymentMethodDataForTest(), | 588 scope.getExecutionContext(), buildPaymentMethodDataForTest(), |
| 577 buildPaymentDetailsInitForTest(), scope.getExceptionState()); | 589 buildPaymentDetailsForTest(), scope.getExceptionState()); |
| 578 EXPECT_FALSE(scope.getExceptionState().hadException()); | 590 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 579 | 591 |
| 580 request->show(scope.getScriptState()) | 592 request->show(scope.getScriptState()) |
| 581 .then(funcs.expectNoCall(), funcs.expectNoCall()); | 593 .then(funcs.expectNoCall(), funcs.expectNoCall()); |
| 582 String detailWithErrorMsg = | 594 String detailWithErrorMsg = |
| 583 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " | 595 "{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", " |
| 584 "\"value\": \"5.00\"}}," | 596 "\"value\": \"5.00\"}}," |
| 585 "\"error\": \"This is an error message.\"}"; | 597 "\"error\": \"This is an error message.\"}"; |
| 586 | 598 |
| 587 request->onUpdatePaymentDetails(ScriptValue::from( | 599 request->onUpdatePaymentDetails(ScriptValue::from( |
| 588 scope.getScriptState(), | 600 scope.getScriptState(), |
| 589 fromJSONString(scope.getScriptState()->isolate(), detailWithErrorMsg, | 601 fromJSONString(scope.getScriptState()->isolate(), detailWithErrorMsg, |
| 590 scope.getExceptionState()))); | 602 scope.getExceptionState()))); |
| 591 EXPECT_FALSE(scope.getExceptionState().hadException()); | 603 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 592 } | 604 } |
| 593 | 605 |
| 594 TEST(PaymentRequestTest, | 606 TEST(PaymentRequestTest, |
| 595 ShouldResolveWithEmptyShippingOptionsIfIDsOfShippingOptionsAreDuplicated) { | 607 ShouldResolveWithEmptyShippingOptionsIfIDsOfShippingOptionsAreDuplicated) { |
| 596 V8TestingScope scope; | 608 V8TestingScope scope; |
| 597 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 609 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 598 makePaymentRequestOriginSecure(scope.document()); | 610 makePaymentRequestOriginSecure(scope.document()); |
| 599 PaymentDetailsInit details; | 611 PaymentDetails details; |
| 600 details.setTotal(buildPaymentItemForTest()); | 612 details.setTotal(buildPaymentItemForTest()); |
| 601 HeapVector<PaymentShippingOption> shippingOptions(2); | 613 HeapVector<PaymentShippingOption> shippingOptions(2); |
| 602 shippingOptions[0] = buildShippingOptionForTest( | 614 shippingOptions[0] = buildShippingOptionForTest( |
| 603 PaymentTestDataId, PaymentTestOverwriteValue, "standard"); | 615 PaymentTestDataId, PaymentTestOverwriteValue, "standard"); |
| 604 shippingOptions[0].setSelected(true); | 616 shippingOptions[0].setSelected(true); |
| 605 shippingOptions[1] = buildShippingOptionForTest( | 617 shippingOptions[1] = buildShippingOptionForTest( |
| 606 PaymentTestDataId, PaymentTestOverwriteValue, "standard"); | 618 PaymentTestDataId, PaymentTestOverwriteValue, "standard"); |
| 607 details.setShippingOptions(shippingOptions); | 619 details.setShippingOptions(shippingOptions); |
| 608 PaymentOptions options; | 620 PaymentOptions options; |
| 609 options.setRequestShipping(true); | 621 options.setRequestShipping(true); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 627 scope.getScriptState(), | 639 scope.getScriptState(), |
| 628 fromJSONString(scope.getScriptState()->isolate(), | 640 fromJSONString(scope.getScriptState()->isolate(), |
| 629 detailWithShippingOptions, scope.getExceptionState()))); | 641 detailWithShippingOptions, scope.getExceptionState()))); |
| 630 | 642 |
| 631 EXPECT_FALSE(scope.getExceptionState().hadException()); | 643 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 632 EXPECT_TRUE(request->shippingOption().isNull()); | 644 EXPECT_TRUE(request->shippingOption().isNull()); |
| 633 } | 645 } |
| 634 | 646 |
| 635 } // namespace | 647 } // namespace |
| 636 } // namespace blink | 648 } // namespace blink |
| OLD | NEW |