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