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