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