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