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