| 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 // Tests for PaymentRequest::OnPaymentResponse(). | 5 // Tests for PaymentRequest::OnPaymentResponse(). |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptFunction.h" | 7 #include "bindings/core/v8/ScriptFunction.h" |
| 8 #include "bindings/core/v8/V8BindingForTesting.h" | 8 #include "bindings/core/v8/V8BindingForTesting.h" |
| 9 #include "bindings/modules/v8/V8PaymentResponse.h" | 9 #include "bindings/modules/v8/V8PaymentResponse.h" |
| 10 #include "modules/payments/PaymentAddress.h" | 10 #include "modules/payments/PaymentAddress.h" |
| 11 #include "modules/payments/PaymentRequest.h" | 11 #include "modules/payments/PaymentRequest.h" |
| 12 #include "modules/payments/PaymentTestHelper.h" | 12 #include "modules/payments/PaymentTestHelper.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include <utility> | 14 #include <utility> |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // If the merchant requests shipping information, but the browser does not | 19 // If the merchant requests shipping information, but the browser does not |
| 20 // provide the shipping option, reject the show() promise. | 20 // provide the shipping option, reject the show() promise. |
| 21 TEST(OnPaymentResponseTest, RejectMissingShippingOption) { | 21 TEST(OnPaymentResponseTest, RejectMissingShippingOption) { |
| 22 V8TestingScope scope; | 22 V8TestingScope scope; |
| 23 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 23 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 24 makePaymentRequestOriginSecure(scope.document()); | 24 makePaymentRequestOriginSecure(scope.document()); |
| 25 PaymentOptions options; | 25 PaymentOptions options; |
| 26 options.setRequestShipping(true); | 26 options.setRequestShipping(true); |
| 27 PaymentRequest* request = PaymentRequest::create( | 27 PaymentRequest* request = PaymentRequest::create( |
| 28 scope.document(), buildPaymentMethodDataForTest(), | 28 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 29 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 29 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 30 ASSERT_FALSE(scope.getExceptionState().hadException()); | 30 ASSERT_FALSE(scope.getExceptionState().hadException()); |
| 31 payments::mojom::blink::PaymentResponsePtr response = | 31 payments::mojom::blink::PaymentResponsePtr response = |
| 32 buildPaymentResponseForTest(); | 32 buildPaymentResponseForTest(); |
| 33 response->shipping_address = payments::mojom::blink::PaymentAddress::New(); | 33 response->shipping_address = payments::mojom::blink::PaymentAddress::New(); |
| 34 response->shipping_address->country = "US"; | 34 response->shipping_address->country = "US"; |
| 35 response->shipping_address->language_code = "en"; | 35 response->shipping_address->language_code = "en"; |
| 36 response->shipping_address->script_code = "Latn"; | 36 response->shipping_address->script_code = "Latn"; |
| 37 | 37 |
| 38 request->show(scope.getScriptState()) | 38 request->show().then(funcs.expectNoCall(), funcs.expectCall()); |
| 39 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 40 | 39 |
| 41 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 40 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 42 ->OnPaymentResponse(std::move(response)); | 41 ->OnPaymentResponse(std::move(response)); |
| 43 } | 42 } |
| 44 | 43 |
| 45 // If the merchant requests shipping information, but the browser does not | 44 // If the merchant requests shipping information, but the browser does not |
| 46 // provide a shipping address, reject the show() promise. | 45 // provide a shipping address, reject the show() promise. |
| 47 TEST(OnPaymentResponseTest, RejectMissingAddress) { | 46 TEST(OnPaymentResponseTest, RejectMissingAddress) { |
| 48 V8TestingScope scope; | 47 V8TestingScope scope; |
| 49 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 48 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 50 makePaymentRequestOriginSecure(scope.document()); | 49 makePaymentRequestOriginSecure(scope.document()); |
| 51 PaymentOptions options; | 50 PaymentOptions options; |
| 52 options.setRequestShipping(true); | 51 options.setRequestShipping(true); |
| 53 PaymentRequest* request = PaymentRequest::create( | 52 PaymentRequest* request = PaymentRequest::create( |
| 54 scope.document(), buildPaymentMethodDataForTest(), | 53 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 55 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 54 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 56 ASSERT_FALSE(scope.getExceptionState().hadException()); | 55 ASSERT_FALSE(scope.getExceptionState().hadException()); |
| 57 payments::mojom::blink::PaymentResponsePtr response = | 56 payments::mojom::blink::PaymentResponsePtr response = |
| 58 buildPaymentResponseForTest(); | 57 buildPaymentResponseForTest(); |
| 59 response->shipping_option = "standardShipping"; | 58 response->shipping_option = "standardShipping"; |
| 60 | 59 |
| 61 request->show(scope.getScriptState()) | 60 request->show().then(funcs.expectNoCall(), funcs.expectCall()); |
| 62 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 63 | 61 |
| 64 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 62 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 65 ->OnPaymentResponse(std::move(response)); | 63 ->OnPaymentResponse(std::move(response)); |
| 66 } | 64 } |
| 67 | 65 |
| 68 // If the merchant requests a payer name, but the browser does not provide it, | 66 // If the merchant requests a payer name, but the browser does not provide it, |
| 69 // reject the show() promise. | 67 // reject the show() promise. |
| 70 TEST(OnPaymentResponseTest, RejectMissingName) { | 68 TEST(OnPaymentResponseTest, RejectMissingName) { |
| 71 V8TestingScope scope; | 69 V8TestingScope scope; |
| 72 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 70 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 73 makePaymentRequestOriginSecure(scope.document()); | 71 makePaymentRequestOriginSecure(scope.document()); |
| 74 PaymentOptions options; | 72 PaymentOptions options; |
| 75 options.setRequestPayerName(true); | 73 options.setRequestPayerName(true); |
| 76 PaymentRequest* request = PaymentRequest::create( | 74 PaymentRequest* request = PaymentRequest::create( |
| 77 scope.document(), buildPaymentMethodDataForTest(), | 75 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 78 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 76 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 79 EXPECT_FALSE(scope.getExceptionState().hadException()); | 77 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 80 payments::mojom::blink::PaymentResponsePtr response = | 78 payments::mojom::blink::PaymentResponsePtr response = |
| 81 payments::mojom::blink::PaymentResponse::New(); | 79 payments::mojom::blink::PaymentResponse::New(); |
| 82 | 80 |
| 83 request->show(scope.getScriptState()) | 81 request->show().then(funcs.expectNoCall(), funcs.expectCall()); |
| 84 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 85 | 82 |
| 86 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 83 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 87 ->OnPaymentResponse(std::move(response)); | 84 ->OnPaymentResponse(std::move(response)); |
| 88 } | 85 } |
| 89 | 86 |
| 90 // If the merchant requests an email address, but the browser does not provide | 87 // If the merchant requests an email address, but the browser does not provide |
| 91 // it, reject the show() promise. | 88 // it, reject the show() promise. |
| 92 TEST(OnPaymentResponseTest, RejectMissingEmail) { | 89 TEST(OnPaymentResponseTest, RejectMissingEmail) { |
| 93 V8TestingScope scope; | 90 V8TestingScope scope; |
| 94 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 91 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 95 makePaymentRequestOriginSecure(scope.document()); | 92 makePaymentRequestOriginSecure(scope.document()); |
| 96 PaymentOptions options; | 93 PaymentOptions options; |
| 97 options.setRequestPayerEmail(true); | 94 options.setRequestPayerEmail(true); |
| 98 PaymentRequest* request = PaymentRequest::create( | 95 PaymentRequest* request = PaymentRequest::create( |
| 99 scope.document(), buildPaymentMethodDataForTest(), | 96 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 100 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 97 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 101 EXPECT_FALSE(scope.getExceptionState().hadException()); | 98 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 102 payments::mojom::blink::PaymentResponsePtr response = | 99 payments::mojom::blink::PaymentResponsePtr response = |
| 103 payments::mojom::blink::PaymentResponse::New(); | 100 payments::mojom::blink::PaymentResponse::New(); |
| 104 | 101 |
| 105 request->show(scope.getScriptState()) | 102 request->show().then(funcs.expectNoCall(), funcs.expectCall()); |
| 106 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 107 | 103 |
| 108 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 104 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 109 ->OnPaymentResponse(std::move(response)); | 105 ->OnPaymentResponse(std::move(response)); |
| 110 } | 106 } |
| 111 | 107 |
| 112 // If the merchant requests a phone number, but the browser does not provide it, | 108 // If the merchant requests a phone number, but the browser does not provide it, |
| 113 // reject the show() promise. | 109 // reject the show() promise. |
| 114 TEST(OnPaymentResponseTest, RejectMissingPhone) { | 110 TEST(OnPaymentResponseTest, RejectMissingPhone) { |
| 115 V8TestingScope scope; | 111 V8TestingScope scope; |
| 116 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 112 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 117 makePaymentRequestOriginSecure(scope.document()); | 113 makePaymentRequestOriginSecure(scope.document()); |
| 118 PaymentOptions options; | 114 PaymentOptions options; |
| 119 options.setRequestPayerPhone(true); | 115 options.setRequestPayerPhone(true); |
| 120 PaymentRequest* request = PaymentRequest::create( | 116 PaymentRequest* request = PaymentRequest::create( |
| 121 scope.document(), buildPaymentMethodDataForTest(), | 117 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 122 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 118 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 123 EXPECT_FALSE(scope.getExceptionState().hadException()); | 119 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 124 payments::mojom::blink::PaymentResponsePtr response = | 120 payments::mojom::blink::PaymentResponsePtr response = |
| 125 payments::mojom::blink::PaymentResponse::New(); | 121 payments::mojom::blink::PaymentResponse::New(); |
| 126 | 122 |
| 127 request->show(scope.getScriptState()) | 123 request->show().then(funcs.expectNoCall(), funcs.expectCall()); |
| 128 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 129 | 124 |
| 130 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 125 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 131 ->OnPaymentResponse(std::move(response)); | 126 ->OnPaymentResponse(std::move(response)); |
| 132 } | 127 } |
| 133 | 128 |
| 134 // If the merchant requests shipping information, but the browser provides an | 129 // If the merchant requests shipping information, but the browser provides an |
| 135 // empty string for shipping option, reject the show() promise. | 130 // empty string for shipping option, reject the show() promise. |
| 136 TEST(OnPaymentResponseTest, RejectEmptyShippingOption) { | 131 TEST(OnPaymentResponseTest, RejectEmptyShippingOption) { |
| 137 V8TestingScope scope; | 132 V8TestingScope scope; |
| 138 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 133 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 139 makePaymentRequestOriginSecure(scope.document()); | 134 makePaymentRequestOriginSecure(scope.document()); |
| 140 PaymentOptions options; | 135 PaymentOptions options; |
| 141 options.setRequestShipping(true); | 136 options.setRequestShipping(true); |
| 142 PaymentRequest* request = PaymentRequest::create( | 137 PaymentRequest* request = PaymentRequest::create( |
| 143 scope.document(), buildPaymentMethodDataForTest(), | 138 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 144 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 139 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 145 ASSERT_FALSE(scope.getExceptionState().hadException()); | 140 ASSERT_FALSE(scope.getExceptionState().hadException()); |
| 146 payments::mojom::blink::PaymentResponsePtr response = | 141 payments::mojom::blink::PaymentResponsePtr response = |
| 147 buildPaymentResponseForTest(); | 142 buildPaymentResponseForTest(); |
| 148 response->shipping_option = ""; | 143 response->shipping_option = ""; |
| 149 response->shipping_address = payments::mojom::blink::PaymentAddress::New(); | 144 response->shipping_address = payments::mojom::blink::PaymentAddress::New(); |
| 150 response->shipping_address->country = "US"; | 145 response->shipping_address->country = "US"; |
| 151 response->shipping_address->language_code = "en"; | 146 response->shipping_address->language_code = "en"; |
| 152 response->shipping_address->script_code = "Latn"; | 147 response->shipping_address->script_code = "Latn"; |
| 153 | 148 |
| 154 request->show(scope.getScriptState()) | 149 request->show().then(funcs.expectNoCall(), funcs.expectCall()); |
| 155 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 156 | 150 |
| 157 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 151 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 158 ->OnPaymentResponse(std::move(response)); | 152 ->OnPaymentResponse(std::move(response)); |
| 159 } | 153 } |
| 160 | 154 |
| 161 // If the merchant requests shipping information, but the browser provides an | 155 // If the merchant requests shipping information, but the browser provides an |
| 162 // empty shipping address, reject the show() promise. | 156 // empty shipping address, reject the show() promise. |
| 163 TEST(OnPaymentResponseTest, RejectEmptyAddress) { | 157 TEST(OnPaymentResponseTest, RejectEmptyAddress) { |
| 164 V8TestingScope scope; | 158 V8TestingScope scope; |
| 165 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 159 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 166 makePaymentRequestOriginSecure(scope.document()); | 160 makePaymentRequestOriginSecure(scope.document()); |
| 167 PaymentOptions options; | 161 PaymentOptions options; |
| 168 options.setRequestShipping(true); | 162 options.setRequestShipping(true); |
| 169 PaymentRequest* request = PaymentRequest::create( | 163 PaymentRequest* request = PaymentRequest::create( |
| 170 scope.document(), buildPaymentMethodDataForTest(), | 164 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 171 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 165 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 172 ASSERT_FALSE(scope.getExceptionState().hadException()); | 166 ASSERT_FALSE(scope.getExceptionState().hadException()); |
| 173 payments::mojom::blink::PaymentResponsePtr response = | 167 payments::mojom::blink::PaymentResponsePtr response = |
| 174 buildPaymentResponseForTest(); | 168 buildPaymentResponseForTest(); |
| 175 response->shipping_option = "standardShipping"; | 169 response->shipping_option = "standardShipping"; |
| 176 response->shipping_address = payments::mojom::blink::PaymentAddress::New(); | 170 response->shipping_address = payments::mojom::blink::PaymentAddress::New(); |
| 177 | 171 |
| 178 request->show(scope.getScriptState()) | 172 request->show().then(funcs.expectNoCall(), funcs.expectCall()); |
| 179 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 180 | 173 |
| 181 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 174 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 182 ->OnPaymentResponse(std::move(response)); | 175 ->OnPaymentResponse(std::move(response)); |
| 183 } | 176 } |
| 184 | 177 |
| 185 // If the merchant requests a payer name, but the browser provides an empty | 178 // If the merchant requests a payer name, but the browser provides an empty |
| 186 // string for name, reject the show() promise. | 179 // string for name, reject the show() promise. |
| 187 TEST(OnPaymentResponseTest, RejectEmptyName) { | 180 TEST(OnPaymentResponseTest, RejectEmptyName) { |
| 188 V8TestingScope scope; | 181 V8TestingScope scope; |
| 189 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 182 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 190 makePaymentRequestOriginSecure(scope.document()); | 183 makePaymentRequestOriginSecure(scope.document()); |
| 191 PaymentOptions options; | 184 PaymentOptions options; |
| 192 options.setRequestPayerName(true); | 185 options.setRequestPayerName(true); |
| 193 PaymentRequest* request = PaymentRequest::create( | 186 PaymentRequest* request = PaymentRequest::create( |
| 194 scope.document(), buildPaymentMethodDataForTest(), | 187 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 195 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 188 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 196 EXPECT_FALSE(scope.getExceptionState().hadException()); | 189 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 197 payments::mojom::blink::PaymentResponsePtr response = | 190 payments::mojom::blink::PaymentResponsePtr response = |
| 198 payments::mojom::blink::PaymentResponse::New(); | 191 payments::mojom::blink::PaymentResponse::New(); |
| 199 response->payer_name = ""; | 192 response->payer_name = ""; |
| 200 | 193 |
| 201 request->show(scope.getScriptState()) | 194 request->show().then(funcs.expectNoCall(), funcs.expectCall()); |
| 202 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 203 | 195 |
| 204 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 196 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 205 ->OnPaymentResponse(std::move(response)); | 197 ->OnPaymentResponse(std::move(response)); |
| 206 } | 198 } |
| 207 | 199 |
| 208 // If the merchant requests an email, but the browser provides an empty string | 200 // If the merchant requests an email, but the browser provides an empty string |
| 209 // for email, reject the show() promise. | 201 // for email, reject the show() promise. |
| 210 TEST(OnPaymentResponseTest, RejectEmptyEmail) { | 202 TEST(OnPaymentResponseTest, RejectEmptyEmail) { |
| 211 V8TestingScope scope; | 203 V8TestingScope scope; |
| 212 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 204 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 213 makePaymentRequestOriginSecure(scope.document()); | 205 makePaymentRequestOriginSecure(scope.document()); |
| 214 PaymentOptions options; | 206 PaymentOptions options; |
| 215 options.setRequestPayerEmail(true); | 207 options.setRequestPayerEmail(true); |
| 216 PaymentRequest* request = PaymentRequest::create( | 208 PaymentRequest* request = PaymentRequest::create( |
| 217 scope.document(), buildPaymentMethodDataForTest(), | 209 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 218 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 210 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 219 EXPECT_FALSE(scope.getExceptionState().hadException()); | 211 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 220 payments::mojom::blink::PaymentResponsePtr response = | 212 payments::mojom::blink::PaymentResponsePtr response = |
| 221 payments::mojom::blink::PaymentResponse::New(); | 213 payments::mojom::blink::PaymentResponse::New(); |
| 222 response->payer_email = ""; | 214 response->payer_email = ""; |
| 223 | 215 |
| 224 request->show(scope.getScriptState()) | 216 request->show().then(funcs.expectNoCall(), funcs.expectCall()); |
| 225 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 226 | 217 |
| 227 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 218 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 228 ->OnPaymentResponse(std::move(response)); | 219 ->OnPaymentResponse(std::move(response)); |
| 229 } | 220 } |
| 230 | 221 |
| 231 // If the merchant requests a phone number, but the browser provides an empty | 222 // If the merchant requests a phone number, but the browser provides an empty |
| 232 // string for the phone number, reject the show() promise. | 223 // string for the phone number, reject the show() promise. |
| 233 TEST(OnPaymentResponseTest, RejectEmptyPhone) { | 224 TEST(OnPaymentResponseTest, RejectEmptyPhone) { |
| 234 V8TestingScope scope; | 225 V8TestingScope scope; |
| 235 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 226 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 236 makePaymentRequestOriginSecure(scope.document()); | 227 makePaymentRequestOriginSecure(scope.document()); |
| 237 PaymentOptions options; | 228 PaymentOptions options; |
| 238 options.setRequestPayerPhone(true); | 229 options.setRequestPayerPhone(true); |
| 239 PaymentRequest* request = PaymentRequest::create( | 230 PaymentRequest* request = PaymentRequest::create( |
| 240 scope.document(), buildPaymentMethodDataForTest(), | 231 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 241 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 232 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 242 EXPECT_FALSE(scope.getExceptionState().hadException()); | 233 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 243 payments::mojom::blink::PaymentResponsePtr response = | 234 payments::mojom::blink::PaymentResponsePtr response = |
| 244 payments::mojom::blink::PaymentResponse::New(); | 235 payments::mojom::blink::PaymentResponse::New(); |
| 245 response->payer_phone = ""; | 236 response->payer_phone = ""; |
| 246 | 237 |
| 247 request->show(scope.getScriptState()) | 238 request->show().then(funcs.expectNoCall(), funcs.expectCall()); |
| 248 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 249 | 239 |
| 250 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 240 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 251 ->OnPaymentResponse(std::move(response)); | 241 ->OnPaymentResponse(std::move(response)); |
| 252 } | 242 } |
| 253 | 243 |
| 254 // If the merchant does not request shipping information, but the browser | 244 // If the merchant does not request shipping information, but the browser |
| 255 // provides a shipping address, reject the show() promise. | 245 // provides a shipping address, reject the show() promise. |
| 256 TEST(OnPaymentResponseTest, RejectNotRequestedAddress) { | 246 TEST(OnPaymentResponseTest, RejectNotRequestedAddress) { |
| 257 V8TestingScope scope; | 247 V8TestingScope scope; |
| 258 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 248 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 259 makePaymentRequestOriginSecure(scope.document()); | 249 makePaymentRequestOriginSecure(scope.document()); |
| 260 PaymentOptions options; | 250 PaymentOptions options; |
| 261 options.setRequestShipping(false); | 251 options.setRequestShipping(false); |
| 262 PaymentRequest* request = PaymentRequest::create( | 252 PaymentRequest* request = PaymentRequest::create( |
| 263 scope.document(), buildPaymentMethodDataForTest(), | 253 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 264 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 254 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 265 ASSERT_FALSE(scope.getExceptionState().hadException()); | 255 ASSERT_FALSE(scope.getExceptionState().hadException()); |
| 266 payments::mojom::blink::PaymentResponsePtr response = | 256 payments::mojom::blink::PaymentResponsePtr response = |
| 267 payments::mojom::blink::PaymentResponse::New(); | 257 payments::mojom::blink::PaymentResponse::New(); |
| 268 response->shipping_address = payments::mojom::blink::PaymentAddress::New(); | 258 response->shipping_address = payments::mojom::blink::PaymentAddress::New(); |
| 269 response->shipping_address->country = "US"; | 259 response->shipping_address->country = "US"; |
| 270 response->shipping_address->language_code = "en"; | 260 response->shipping_address->language_code = "en"; |
| 271 response->shipping_address->script_code = "Latn"; | 261 response->shipping_address->script_code = "Latn"; |
| 272 | 262 |
| 273 request->show(scope.getScriptState()) | 263 request->show().then(funcs.expectNoCall(), funcs.expectCall()); |
| 274 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 275 | 264 |
| 276 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 265 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 277 ->OnPaymentResponse(std::move(response)); | 266 ->OnPaymentResponse(std::move(response)); |
| 278 } | 267 } |
| 279 | 268 |
| 280 // If the merchant does not request shipping information, but the browser | 269 // If the merchant does not request shipping information, but the browser |
| 281 // provides a shipping option, reject the show() promise. | 270 // provides a shipping option, reject the show() promise. |
| 282 TEST(OnPaymentResponseTest, RejectNotRequestedShippingOption) { | 271 TEST(OnPaymentResponseTest, RejectNotRequestedShippingOption) { |
| 283 V8TestingScope scope; | 272 V8TestingScope scope; |
| 284 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 273 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 285 makePaymentRequestOriginSecure(scope.document()); | 274 makePaymentRequestOriginSecure(scope.document()); |
| 286 PaymentOptions options; | 275 PaymentOptions options; |
| 287 options.setRequestShipping(false); | 276 options.setRequestShipping(false); |
| 288 PaymentRequest* request = PaymentRequest::create( | 277 PaymentRequest* request = PaymentRequest::create( |
| 289 scope.document(), buildPaymentMethodDataForTest(), | 278 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 290 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 279 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 291 ASSERT_FALSE(scope.getExceptionState().hadException()); | 280 ASSERT_FALSE(scope.getExceptionState().hadException()); |
| 292 payments::mojom::blink::PaymentResponsePtr response = | 281 payments::mojom::blink::PaymentResponsePtr response = |
| 293 payments::mojom::blink::PaymentResponse::New(); | 282 payments::mojom::blink::PaymentResponse::New(); |
| 294 response->shipping_option = ""; | 283 response->shipping_option = ""; |
| 295 | 284 |
| 296 request->show(scope.getScriptState()) | 285 request->show().then(funcs.expectNoCall(), funcs.expectCall()); |
| 297 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 298 | 286 |
| 299 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 287 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 300 ->OnPaymentResponse(std::move(response)); | 288 ->OnPaymentResponse(std::move(response)); |
| 301 } | 289 } |
| 302 | 290 |
| 303 // If the merchant does not request a payer name, but the browser provides it, | 291 // If the merchant does not request a payer name, but the browser provides it, |
| 304 // reject the show() promise. | 292 // reject the show() promise. |
| 305 TEST(OnPaymentResponseTest, RejectNotRequestedName) { | 293 TEST(OnPaymentResponseTest, RejectNotRequestedName) { |
| 306 V8TestingScope scope; | 294 V8TestingScope scope; |
| 307 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 295 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 308 makePaymentRequestOriginSecure(scope.document()); | 296 makePaymentRequestOriginSecure(scope.document()); |
| 309 PaymentOptions options; | 297 PaymentOptions options; |
| 310 options.setRequestPayerName(false); | 298 options.setRequestPayerName(false); |
| 311 PaymentRequest* request = PaymentRequest::create( | 299 PaymentRequest* request = PaymentRequest::create( |
| 312 scope.document(), buildPaymentMethodDataForTest(), | 300 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 313 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 301 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 314 EXPECT_FALSE(scope.getExceptionState().hadException()); | 302 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 315 payments::mojom::blink::PaymentResponsePtr response = | 303 payments::mojom::blink::PaymentResponsePtr response = |
| 316 payments::mojom::blink::PaymentResponse::New(); | 304 payments::mojom::blink::PaymentResponse::New(); |
| 317 response->payer_name = ""; | 305 response->payer_name = ""; |
| 318 | 306 |
| 319 request->show(scope.getScriptState()) | 307 request->show().then(funcs.expectNoCall(), funcs.expectCall()); |
| 320 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 321 | 308 |
| 322 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 309 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 323 ->OnPaymentResponse(std::move(response)); | 310 ->OnPaymentResponse(std::move(response)); |
| 324 } | 311 } |
| 325 | 312 |
| 326 // If the merchant does not request an email, but the browser provides it, | 313 // If the merchant does not request an email, but the browser provides it, |
| 327 // reject the show() promise. | 314 // reject the show() promise. |
| 328 TEST(OnPaymentResponseTest, RejectNotRequestedEmail) { | 315 TEST(OnPaymentResponseTest, RejectNotRequestedEmail) { |
| 329 V8TestingScope scope; | 316 V8TestingScope scope; |
| 330 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 317 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 331 makePaymentRequestOriginSecure(scope.document()); | 318 makePaymentRequestOriginSecure(scope.document()); |
| 332 PaymentOptions options; | 319 PaymentOptions options; |
| 333 options.setRequestPayerEmail(false); | 320 options.setRequestPayerEmail(false); |
| 334 PaymentRequest* request = PaymentRequest::create( | 321 PaymentRequest* request = PaymentRequest::create( |
| 335 scope.document(), buildPaymentMethodDataForTest(), | 322 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 336 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 323 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 337 EXPECT_FALSE(scope.getExceptionState().hadException()); | 324 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 338 payments::mojom::blink::PaymentResponsePtr response = | 325 payments::mojom::blink::PaymentResponsePtr response = |
| 339 payments::mojom::blink::PaymentResponse::New(); | 326 payments::mojom::blink::PaymentResponse::New(); |
| 340 response->payer_email = ""; | 327 response->payer_email = ""; |
| 341 | 328 |
| 342 request->show(scope.getScriptState()) | 329 request->show().then(funcs.expectNoCall(), funcs.expectCall()); |
| 343 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 344 | 330 |
| 345 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 331 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 346 ->OnPaymentResponse(std::move(response)); | 332 ->OnPaymentResponse(std::move(response)); |
| 347 } | 333 } |
| 348 | 334 |
| 349 // If the merchant does not request a phone number, but the browser provides it, | 335 // If the merchant does not request a phone number, but the browser provides it, |
| 350 // reject the show() promise. | 336 // reject the show() promise. |
| 351 TEST(OnPaymentResponseTest, RejectNotRequestedPhone) { | 337 TEST(OnPaymentResponseTest, RejectNotRequestedPhone) { |
| 352 V8TestingScope scope; | 338 V8TestingScope scope; |
| 353 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 339 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 354 makePaymentRequestOriginSecure(scope.document()); | 340 makePaymentRequestOriginSecure(scope.document()); |
| 355 PaymentOptions options; | 341 PaymentOptions options; |
| 356 options.setRequestPayerPhone(false); | 342 options.setRequestPayerPhone(false); |
| 357 PaymentRequest* request = PaymentRequest::create( | 343 PaymentRequest* request = PaymentRequest::create( |
| 358 scope.document(), buildPaymentMethodDataForTest(), | 344 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 359 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 345 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 360 EXPECT_FALSE(scope.getExceptionState().hadException()); | 346 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 361 payments::mojom::blink::PaymentResponsePtr response = | 347 payments::mojom::blink::PaymentResponsePtr response = |
| 362 payments::mojom::blink::PaymentResponse::New(); | 348 payments::mojom::blink::PaymentResponse::New(); |
| 363 response->payer_phone = ""; | 349 response->payer_phone = ""; |
| 364 | 350 |
| 365 request->show(scope.getScriptState()) | 351 request->show().then(funcs.expectNoCall(), funcs.expectCall()); |
| 366 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 367 | 352 |
| 368 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 353 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 369 ->OnPaymentResponse(std::move(response)); | 354 ->OnPaymentResponse(std::move(response)); |
| 370 } | 355 } |
| 371 | 356 |
| 372 // If the merchant requests shipping information, but the browser provides an | 357 // If the merchant requests shipping information, but the browser provides an |
| 373 // invalid shipping address, reject the show() promise. | 358 // invalid shipping address, reject the show() promise. |
| 374 TEST(OnPaymentResponseTest, RejectInvalidAddress) { | 359 TEST(OnPaymentResponseTest, RejectInvalidAddress) { |
| 375 V8TestingScope scope; | 360 V8TestingScope scope; |
| 376 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 361 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 377 makePaymentRequestOriginSecure(scope.document()); | 362 makePaymentRequestOriginSecure(scope.document()); |
| 378 PaymentOptions options; | 363 PaymentOptions options; |
| 379 options.setRequestShipping(true); | 364 options.setRequestShipping(true); |
| 380 PaymentRequest* request = PaymentRequest::create( | 365 PaymentRequest* request = PaymentRequest::create( |
| 381 scope.document(), buildPaymentMethodDataForTest(), | 366 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 382 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 367 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 383 ASSERT_FALSE(scope.getExceptionState().hadException()); | 368 ASSERT_FALSE(scope.getExceptionState().hadException()); |
| 384 payments::mojom::blink::PaymentResponsePtr response = | 369 payments::mojom::blink::PaymentResponsePtr response = |
| 385 buildPaymentResponseForTest(); | 370 buildPaymentResponseForTest(); |
| 386 response->shipping_option = "standardShipping"; | 371 response->shipping_option = "standardShipping"; |
| 387 response->shipping_address = payments::mojom::blink::PaymentAddress::New(); | 372 response->shipping_address = payments::mojom::blink::PaymentAddress::New(); |
| 388 response->shipping_address->country = "Atlantis"; | 373 response->shipping_address->country = "Atlantis"; |
| 389 | 374 |
| 390 request->show(scope.getScriptState()) | 375 request->show().then(funcs.expectNoCall(), funcs.expectCall()); |
| 391 .then(funcs.expectNoCall(), funcs.expectCall()); | |
| 392 | 376 |
| 393 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 377 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 394 ->OnPaymentResponse(std::move(response)); | 378 ->OnPaymentResponse(std::move(response)); |
| 395 } | 379 } |
| 396 | 380 |
| 397 class PaymentResponseFunction : public ScriptFunction { | 381 class PaymentResponseFunction : public ScriptFunction { |
| 398 public: | 382 public: |
| 399 static v8::Local<v8::Function> create(ScriptState* scriptState, | 383 static v8::Local<v8::Function> create(ScriptState* scriptState, |
| 400 ScriptValue* outValue) { | 384 ScriptValue* outValue) { |
| 401 PaymentResponseFunction* self = | 385 PaymentResponseFunction* self = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 420 | 404 |
| 421 // If the merchant requests shipping information, the resolved show() promise | 405 // If the merchant requests shipping information, the resolved show() promise |
| 422 // should contain a shipping option and an address. | 406 // should contain a shipping option and an address. |
| 423 TEST(OnPaymentResponseTest, CanRequestShippingInformation) { | 407 TEST(OnPaymentResponseTest, CanRequestShippingInformation) { |
| 424 V8TestingScope scope; | 408 V8TestingScope scope; |
| 425 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 409 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 426 makePaymentRequestOriginSecure(scope.document()); | 410 makePaymentRequestOriginSecure(scope.document()); |
| 427 PaymentOptions options; | 411 PaymentOptions options; |
| 428 options.setRequestShipping(true); | 412 options.setRequestShipping(true); |
| 429 PaymentRequest* request = PaymentRequest::create( | 413 PaymentRequest* request = PaymentRequest::create( |
| 430 scope.document(), buildPaymentMethodDataForTest(), | 414 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 431 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 415 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 432 ASSERT_FALSE(scope.getExceptionState().hadException()); | 416 ASSERT_FALSE(scope.getExceptionState().hadException()); |
| 433 payments::mojom::blink::PaymentResponsePtr response = | 417 payments::mojom::blink::PaymentResponsePtr response = |
| 434 buildPaymentResponseForTest(); | 418 buildPaymentResponseForTest(); |
| 435 response->shipping_option = "standardShipping"; | 419 response->shipping_option = "standardShipping"; |
| 436 response->shipping_address = payments::mojom::blink::PaymentAddress::New(); | 420 response->shipping_address = payments::mojom::blink::PaymentAddress::New(); |
| 437 response->shipping_address->country = "US"; | 421 response->shipping_address->country = "US"; |
| 438 response->shipping_address->language_code = "en"; | 422 response->shipping_address->language_code = "en"; |
| 439 response->shipping_address->script_code = "Latn"; | 423 response->shipping_address->script_code = "Latn"; |
| 440 ScriptValue outValue; | 424 ScriptValue outValue; |
| 441 request->show(scope.getScriptState()) | 425 request->show().then( |
| 442 .then(PaymentResponseFunction::create(scope.getScriptState(), &outValue), | 426 PaymentResponseFunction::create(scope.getScriptState(), &outValue), |
| 443 funcs.expectNoCall()); | 427 funcs.expectNoCall()); |
| 444 | 428 |
| 445 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 429 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 446 ->OnPaymentResponse(std::move(response)); | 430 ->OnPaymentResponse(std::move(response)); |
| 447 | 431 |
| 448 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | 432 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
| 449 PaymentResponse* resp = V8PaymentResponse::toImplWithTypeCheck( | 433 PaymentResponse* resp = V8PaymentResponse::toImplWithTypeCheck( |
| 450 scope.isolate(), outValue.v8Value()); | 434 scope.isolate(), outValue.v8Value()); |
| 451 EXPECT_EQ("standardShipping", resp->shippingOption()); | 435 EXPECT_EQ("standardShipping", resp->shippingOption()); |
| 452 EXPECT_EQ("US", resp->shippingAddress()->country()); | 436 EXPECT_EQ("US", resp->shippingAddress()->country()); |
| 453 EXPECT_EQ("en-Latn", resp->shippingAddress()->languageCode()); | 437 EXPECT_EQ("en-Latn", resp->shippingAddress()->languageCode()); |
| 454 } | 438 } |
| 455 | 439 |
| 456 // If the merchant requests a payer name, the resolved show() promise should | 440 // If the merchant requests a payer name, the resolved show() promise should |
| 457 // contain a payer name. | 441 // contain a payer name. |
| 458 TEST(OnPaymentResponseTest, CanRequestName) { | 442 TEST(OnPaymentResponseTest, CanRequestName) { |
| 459 V8TestingScope scope; | 443 V8TestingScope scope; |
| 460 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 444 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 461 makePaymentRequestOriginSecure(scope.document()); | 445 makePaymentRequestOriginSecure(scope.document()); |
| 462 PaymentOptions options; | 446 PaymentOptions options; |
| 463 options.setRequestPayerName(true); | 447 options.setRequestPayerName(true); |
| 464 PaymentRequest* request = PaymentRequest::create( | 448 PaymentRequest* request = PaymentRequest::create( |
| 465 scope.document(), buildPaymentMethodDataForTest(), | 449 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 466 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 450 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 467 EXPECT_FALSE(scope.getExceptionState().hadException()); | 451 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 468 payments::mojom::blink::PaymentResponsePtr response = | 452 payments::mojom::blink::PaymentResponsePtr response = |
| 469 payments::mojom::blink::PaymentResponse::New(); | 453 payments::mojom::blink::PaymentResponse::New(); |
| 470 response->payer_name = "Jon Doe"; | 454 response->payer_name = "Jon Doe"; |
| 471 ScriptValue outValue; | 455 ScriptValue outValue; |
| 472 request->show(scope.getScriptState()) | 456 request->show().then( |
| 473 .then(PaymentResponseFunction::create(scope.getScriptState(), &outValue), | 457 PaymentResponseFunction::create(scope.getScriptState(), &outValue), |
| 474 funcs.expectNoCall()); | 458 funcs.expectNoCall()); |
| 475 | 459 |
| 476 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 460 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 477 ->OnPaymentResponse(std::move(response)); | 461 ->OnPaymentResponse(std::move(response)); |
| 478 | 462 |
| 479 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | 463 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
| 480 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck( | 464 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck( |
| 481 scope.isolate(), outValue.v8Value()); | 465 scope.isolate(), outValue.v8Value()); |
| 482 EXPECT_EQ("Jon Doe", pr->payerName()); | 466 EXPECT_EQ("Jon Doe", pr->payerName()); |
| 483 } | 467 } |
| 484 | 468 |
| 485 // If the merchant requests an email address, the resolved show() promise should | 469 // If the merchant requests an email address, the resolved show() promise should |
| 486 // contain an email address. | 470 // contain an email address. |
| 487 TEST(OnPaymentResponseTest, CanRequestEmail) { | 471 TEST(OnPaymentResponseTest, CanRequestEmail) { |
| 488 V8TestingScope scope; | 472 V8TestingScope scope; |
| 489 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 473 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 490 makePaymentRequestOriginSecure(scope.document()); | 474 makePaymentRequestOriginSecure(scope.document()); |
| 491 PaymentOptions options; | 475 PaymentOptions options; |
| 492 options.setRequestPayerEmail(true); | 476 options.setRequestPayerEmail(true); |
| 493 PaymentRequest* request = PaymentRequest::create( | 477 PaymentRequest* request = PaymentRequest::create( |
| 494 scope.document(), buildPaymentMethodDataForTest(), | 478 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 495 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 479 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 496 EXPECT_FALSE(scope.getExceptionState().hadException()); | 480 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 497 payments::mojom::blink::PaymentResponsePtr response = | 481 payments::mojom::blink::PaymentResponsePtr response = |
| 498 payments::mojom::blink::PaymentResponse::New(); | 482 payments::mojom::blink::PaymentResponse::New(); |
| 499 response->payer_email = "abc@gmail.com"; | 483 response->payer_email = "abc@gmail.com"; |
| 500 ScriptValue outValue; | 484 ScriptValue outValue; |
| 501 request->show(scope.getScriptState()) | 485 request->show().then( |
| 502 .then(PaymentResponseFunction::create(scope.getScriptState(), &outValue), | 486 PaymentResponseFunction::create(scope.getScriptState(), &outValue), |
| 503 funcs.expectNoCall()); | 487 funcs.expectNoCall()); |
| 504 | 488 |
| 505 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 489 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 506 ->OnPaymentResponse(std::move(response)); | 490 ->OnPaymentResponse(std::move(response)); |
| 507 | 491 |
| 508 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | 492 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
| 509 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck( | 493 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck( |
| 510 scope.isolate(), outValue.v8Value()); | 494 scope.isolate(), outValue.v8Value()); |
| 511 EXPECT_EQ("abc@gmail.com", pr->payerEmail()); | 495 EXPECT_EQ("abc@gmail.com", pr->payerEmail()); |
| 512 } | 496 } |
| 513 | 497 |
| 514 // If the merchant requests a phone number, the resolved show() promise should | 498 // If the merchant requests a phone number, the resolved show() promise should |
| 515 // contain a phone number. | 499 // contain a phone number. |
| 516 TEST(OnPaymentResponseTest, CanRequestPhone) { | 500 TEST(OnPaymentResponseTest, CanRequestPhone) { |
| 517 V8TestingScope scope; | 501 V8TestingScope scope; |
| 518 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 502 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 519 makePaymentRequestOriginSecure(scope.document()); | 503 makePaymentRequestOriginSecure(scope.document()); |
| 520 PaymentOptions options; | 504 PaymentOptions options; |
| 521 options.setRequestPayerPhone(true); | 505 options.setRequestPayerPhone(true); |
| 522 PaymentRequest* request = PaymentRequest::create( | 506 PaymentRequest* request = PaymentRequest::create( |
| 523 scope.document(), buildPaymentMethodDataForTest(), | 507 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 524 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 508 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 525 EXPECT_FALSE(scope.getExceptionState().hadException()); | 509 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 526 payments::mojom::blink::PaymentResponsePtr response = | 510 payments::mojom::blink::PaymentResponsePtr response = |
| 527 payments::mojom::blink::PaymentResponse::New(); | 511 payments::mojom::blink::PaymentResponse::New(); |
| 528 response->payer_phone = "0123"; | 512 response->payer_phone = "0123"; |
| 529 | 513 |
| 530 ScriptValue outValue; | 514 ScriptValue outValue; |
| 531 request->show(scope.getScriptState()) | 515 request->show().then( |
| 532 .then(PaymentResponseFunction::create(scope.getScriptState(), &outValue), | 516 PaymentResponseFunction::create(scope.getScriptState(), &outValue), |
| 533 funcs.expectNoCall()); | 517 funcs.expectNoCall()); |
| 534 | 518 |
| 535 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 519 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 536 ->OnPaymentResponse(std::move(response)); | 520 ->OnPaymentResponse(std::move(response)); |
| 537 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | 521 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
| 538 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck( | 522 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck( |
| 539 scope.isolate(), outValue.v8Value()); | 523 scope.isolate(), outValue.v8Value()); |
| 540 | 524 |
| 541 EXPECT_EQ("0123", pr->payerPhone()); | 525 EXPECT_EQ("0123", pr->payerPhone()); |
| 542 } | 526 } |
| 543 | 527 |
| 544 // If the merchant does not request shipping information, the resolved show() | 528 // If the merchant does not request shipping information, the resolved show() |
| 545 // promise should contain null shipping option and address. | 529 // promise should contain null shipping option and address. |
| 546 TEST(OnPaymentResponseTest, ShippingInformationNotRequired) { | 530 TEST(OnPaymentResponseTest, ShippingInformationNotRequired) { |
| 547 V8TestingScope scope; | 531 V8TestingScope scope; |
| 548 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 532 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 549 makePaymentRequestOriginSecure(scope.document()); | 533 makePaymentRequestOriginSecure(scope.document()); |
| 550 PaymentOptions options; | 534 PaymentOptions options; |
| 551 options.setRequestShipping(false); | 535 options.setRequestShipping(false); |
| 552 PaymentRequest* request = PaymentRequest::create( | 536 PaymentRequest* request = PaymentRequest::create( |
| 553 scope.document(), buildPaymentMethodDataForTest(), | 537 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 554 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 538 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 555 ASSERT_FALSE(scope.getExceptionState().hadException()); | 539 ASSERT_FALSE(scope.getExceptionState().hadException()); |
| 556 ScriptValue outValue; | 540 ScriptValue outValue; |
| 557 request->show(scope.getScriptState()) | 541 request->show().then( |
| 558 .then(PaymentResponseFunction::create(scope.getScriptState(), &outValue), | 542 PaymentResponseFunction::create(scope.getScriptState(), &outValue), |
| 559 funcs.expectNoCall()); | 543 funcs.expectNoCall()); |
| 560 | 544 |
| 561 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 545 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 562 ->OnPaymentResponse(buildPaymentResponseForTest()); | 546 ->OnPaymentResponse(buildPaymentResponseForTest()); |
| 563 | 547 |
| 564 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | 548 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
| 565 PaymentResponse* resp = V8PaymentResponse::toImplWithTypeCheck( | 549 PaymentResponse* resp = V8PaymentResponse::toImplWithTypeCheck( |
| 566 scope.isolate(), outValue.v8Value()); | 550 scope.isolate(), outValue.v8Value()); |
| 567 EXPECT_TRUE(resp->shippingOption().isNull()); | 551 EXPECT_TRUE(resp->shippingOption().isNull()); |
| 568 EXPECT_EQ(nullptr, resp->shippingAddress()); | 552 EXPECT_EQ(nullptr, resp->shippingAddress()); |
| 569 } | 553 } |
| 570 | 554 |
| 571 // If the merchant does not request a phone number, the resolved show() promise | 555 // If the merchant does not request a phone number, the resolved show() promise |
| 572 // should contain null phone number. | 556 // should contain null phone number. |
| 573 TEST(OnPaymentResponseTest, PhoneNotRequred) { | 557 TEST(OnPaymentResponseTest, PhoneNotRequred) { |
| 574 V8TestingScope scope; | 558 V8TestingScope scope; |
| 575 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 559 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 576 makePaymentRequestOriginSecure(scope.document()); | 560 makePaymentRequestOriginSecure(scope.document()); |
| 577 PaymentOptions options; | 561 PaymentOptions options; |
| 578 options.setRequestPayerPhone(false); | 562 options.setRequestPayerPhone(false); |
| 579 PaymentRequest* request = PaymentRequest::create( | 563 PaymentRequest* request = PaymentRequest::create( |
| 580 scope.document(), buildPaymentMethodDataForTest(), | 564 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 581 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 565 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 582 EXPECT_FALSE(scope.getExceptionState().hadException()); | 566 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 583 payments::mojom::blink::PaymentResponsePtr response = | 567 payments::mojom::blink::PaymentResponsePtr response = |
| 584 payments::mojom::blink::PaymentResponse::New(); | 568 payments::mojom::blink::PaymentResponse::New(); |
| 585 response->payer_phone = String(); | 569 response->payer_phone = String(); |
| 586 ScriptValue outValue; | 570 ScriptValue outValue; |
| 587 request->show(scope.getScriptState()) | 571 request->show().then( |
| 588 .then(PaymentResponseFunction::create(scope.getScriptState(), &outValue), | 572 PaymentResponseFunction::create(scope.getScriptState(), &outValue), |
| 589 funcs.expectNoCall()); | 573 funcs.expectNoCall()); |
| 590 | 574 |
| 591 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 575 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 592 ->OnPaymentResponse(std::move(response)); | 576 ->OnPaymentResponse(std::move(response)); |
| 593 | 577 |
| 594 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | 578 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
| 595 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck( | 579 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck( |
| 596 scope.isolate(), outValue.v8Value()); | 580 scope.isolate(), outValue.v8Value()); |
| 597 EXPECT_TRUE(pr->payerPhone().isNull()); | 581 EXPECT_TRUE(pr->payerPhone().isNull()); |
| 598 } | 582 } |
| 599 | 583 |
| 600 // If the merchant does not request a payer name, the resolved show() promise | 584 // If the merchant does not request a payer name, the resolved show() promise |
| 601 // should contain null payer name. | 585 // should contain null payer name. |
| 602 TEST(OnPaymentResponseTest, NameNotRequired) { | 586 TEST(OnPaymentResponseTest, NameNotRequired) { |
| 603 V8TestingScope scope; | 587 V8TestingScope scope; |
| 604 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 588 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 605 makePaymentRequestOriginSecure(scope.document()); | 589 makePaymentRequestOriginSecure(scope.document()); |
| 606 PaymentOptions options; | 590 PaymentOptions options; |
| 607 options.setRequestPayerName(false); | 591 options.setRequestPayerName(false); |
| 608 PaymentRequest* request = PaymentRequest::create( | 592 PaymentRequest* request = PaymentRequest::create( |
| 609 scope.document(), buildPaymentMethodDataForTest(), | 593 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 610 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 594 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 611 EXPECT_FALSE(scope.getExceptionState().hadException()); | 595 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 612 payments::mojom::blink::PaymentResponsePtr response = | 596 payments::mojom::blink::PaymentResponsePtr response = |
| 613 payments::mojom::blink::PaymentResponse::New(); | 597 payments::mojom::blink::PaymentResponse::New(); |
| 614 response->payer_name = String(); | 598 response->payer_name = String(); |
| 615 ScriptValue outValue; | 599 ScriptValue outValue; |
| 616 request->show(scope.getScriptState()) | 600 request->show().then( |
| 617 .then(PaymentResponseFunction::create(scope.getScriptState(), &outValue), | 601 PaymentResponseFunction::create(scope.getScriptState(), &outValue), |
| 618 funcs.expectNoCall()); | 602 funcs.expectNoCall()); |
| 619 | 603 |
| 620 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 604 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 621 ->OnPaymentResponse(std::move(response)); | 605 ->OnPaymentResponse(std::move(response)); |
| 622 | 606 |
| 623 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | 607 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
| 624 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck( | 608 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck( |
| 625 scope.isolate(), outValue.v8Value()); | 609 scope.isolate(), outValue.v8Value()); |
| 626 EXPECT_TRUE(pr->payerName().isNull()); | 610 EXPECT_TRUE(pr->payerName().isNull()); |
| 627 } | 611 } |
| 628 | 612 |
| 629 // If the merchant does not request an email address, the resolved show() | 613 // If the merchant does not request an email address, the resolved show() |
| 630 // promise should contain null email address. | 614 // promise should contain null email address. |
| 631 TEST(OnPaymentResponseTest, EmailNotRequired) { | 615 TEST(OnPaymentResponseTest, EmailNotRequired) { |
| 632 V8TestingScope scope; | 616 V8TestingScope scope; |
| 633 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); | 617 PaymentRequestMockFunctionScope funcs(scope.getScriptState()); |
| 634 makePaymentRequestOriginSecure(scope.document()); | 618 makePaymentRequestOriginSecure(scope.document()); |
| 635 PaymentOptions options; | 619 PaymentOptions options; |
| 636 options.setRequestPayerEmail(false); | 620 options.setRequestPayerEmail(false); |
| 637 PaymentRequest* request = PaymentRequest::create( | 621 PaymentRequest* request = PaymentRequest::create( |
| 638 scope.document(), buildPaymentMethodDataForTest(), | 622 scope.getScriptState(), buildPaymentMethodDataForTest(), |
| 639 buildPaymentDetailsForTest(), options, scope.getExceptionState()); | 623 buildPaymentDetailsForTest(), options, scope.getExceptionState()); |
| 640 EXPECT_FALSE(scope.getExceptionState().hadException()); | 624 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 641 payments::mojom::blink::PaymentResponsePtr response = | 625 payments::mojom::blink::PaymentResponsePtr response = |
| 642 payments::mojom::blink::PaymentResponse::New(); | 626 payments::mojom::blink::PaymentResponse::New(); |
| 643 response->payer_email = String(); | 627 response->payer_email = String(); |
| 644 ScriptValue outValue; | 628 ScriptValue outValue; |
| 645 request->show(scope.getScriptState()) | 629 request->show().then( |
| 646 .then(PaymentResponseFunction::create(scope.getScriptState(), &outValue), | 630 PaymentResponseFunction::create(scope.getScriptState(), &outValue), |
| 647 funcs.expectNoCall()); | 631 funcs.expectNoCall()); |
| 648 | 632 |
| 649 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) | 633 static_cast<payments::mojom::blink::PaymentRequestClient*>(request) |
| 650 ->OnPaymentResponse(std::move(response)); | 634 ->OnPaymentResponse(std::move(response)); |
| 651 | 635 |
| 652 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); | 636 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); |
| 653 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck( | 637 PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck( |
| 654 scope.isolate(), outValue.v8Value()); | 638 scope.isolate(), outValue.v8Value()); |
| 655 EXPECT_TRUE(pr->payerEmail().isNull()); | 639 EXPECT_TRUE(pr->payerEmail().isNull()); |
| 656 } | 640 } |
| 657 | 641 |
| 658 } // namespace | 642 } // namespace |
| 659 } // namespace blink | 643 } // namespace blink |
| OLD | NEW |