Chromium Code Reviews| Index: third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp |
| diff --git a/third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp b/third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp |
| index bc9af1a275f4aaa67d1e7b83e3573fbc680bd556..487cf27e22695952cacee1a408b767493385d8b7 100644 |
| --- a/third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp |
| +++ b/third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp |
| @@ -507,5 +507,211 @@ TEST_F(PaymentRequestTest, UseTheSingleShippingOptionFromPaymentDetailsUpdate) |
| EXPECT_EQ("standardShippingOption", request->shippingOption()); |
| } |
| +TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailTrueAndValidPayerEmailInResponse) |
| +{ |
| + ScriptState::Scope scope(getScriptState()); |
| + PaymentOptions options; |
| + options.setRequestPayerEmail(true); |
| + PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); |
| + EXPECT_FALSE(getExceptionState().hadException()); |
| + mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New(); |
| + response->payer_email = "abc@gmail.com"; |
| + |
| + ScriptValue outValue; |
| + request->show(getScriptState()).then(PaymentResponseFunction::create(getScriptState(), &outValue), MockFunction::expectNoCall(getScriptState())); |
| + |
| + static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response)); |
| + v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); |
| + PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState()->isolate(), outValue.v8Value()); |
| + |
| + EXPECT_EQ("abc@gmail.com", pr->payerEmail()); |
| +} |
| + |
| +TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailTrueAndEmptyPayerEmailInResponse) |
| +{ |
| + ScriptState::Scope scope(getScriptState()); |
| + PaymentOptions options; |
| + options.setRequestPayerEmail(true); |
| + PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); |
| + EXPECT_FALSE(getExceptionState().hadException()); |
| + mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New(); |
| + response->payer_email = ""; |
| + |
| + request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptState()), MockFunction::expectCall(getScriptState())); |
| + |
| + static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response)); |
| +} |
| + |
| +TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailTrueAndNullPayerEmailInResponse) |
| +{ |
| + ScriptState::Scope scope(getScriptState()); |
| + PaymentOptions options; |
| + options.setRequestPayerEmail(true); |
| + PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); |
| + EXPECT_FALSE(getExceptionState().hadException()); |
| + mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New(); |
| + |
|
zino
2016/06/07 16:40:08
response->payer_email = String(); // null string
|
| + request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptState()), MockFunction::expectCall(getScriptState())); |
| + |
| + static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response)); |
| +} |
| + |
| +TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailFalseAndEmptyPayerEmailInResponse) |
| +{ |
| + ScriptState::Scope scope(getScriptState()); |
| + PaymentOptions options; |
| + options.setRequestPayerEmail(false); |
| + PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); |
| + EXPECT_FALSE(getExceptionState().hadException()); |
| + mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New(); |
| + response->payer_email = ""; |
| + |
| + ScriptValue outValue; |
| + request->show(getScriptState()).then(PaymentResponseFunction::create(getScriptState(), &outValue), MockFunction::expectNoCall(getScriptState())); |
| + |
| + static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response)); |
| + v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); |
| + PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState()->isolate(), outValue.v8Value()); |
| + |
| + EXPECT_TRUE(pr->payerEmail().isEmpty()); |
|
zino
2016/06/07 16:40:08
You should use isNull() instead of isEmpty(). (If
|
| +} |
| + |
| +TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailFalseAndNullPayerEmailInResponse) |
| +{ |
| + ScriptState::Scope scope(getScriptState()); |
| + PaymentOptions options; |
| + options.setRequestPayerEmail(false); |
| + PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); |
| + EXPECT_FALSE(getExceptionState().hadException()); |
| + mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New(); |
| + |
| + ScriptValue outValue; |
| + request->show(getScriptState()).then(PaymentResponseFunction::create(getScriptState(), &outValue), MockFunction::expectNoCall(getScriptState())); |
| + |
| + static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response)); |
| + v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); |
| + PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState()->isolate(), outValue.v8Value()); |
| + |
| + EXPECT_TRUE(pr->payerEmail().isNull()); |
| +} |
| + |
| +TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailFalseAndPayerEmailExistsInResponse) |
|
zino
2016/06/07 16:40:08
Do we really need this? If we want this, we should
please use gerrit instead
2016/06/07 17:04:24
OK to remove.
|
| +{ |
| + ScriptState::Scope scope(getScriptState()); |
| + PaymentOptions options; |
| + options.setRequestPayerEmail(false); |
| + PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); |
| + EXPECT_FALSE(getExceptionState().hadException()); |
| + mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New(); |
| + response->payer_email = "abc@gmail.com"; |
| + |
| + request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptState()), MockFunction::expectCall(getScriptState())); |
| + |
| + static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response)); |
| +} |
| + |
| +TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneTrueAndValidPayerPhoneInResponse) |
| +{ |
| + ScriptState::Scope scope(getScriptState()); |
| + PaymentOptions options; |
| + options.setRequestPayerPhone(true); |
| + PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); |
| + EXPECT_FALSE(getExceptionState().hadException()); |
| + mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New(); |
| + response->payer_phone = "0123"; |
| + |
| + ScriptValue outValue; |
| + request->show(getScriptState()).then(PaymentResponseFunction::create(getScriptState(), &outValue), MockFunction::expectNoCall(getScriptState())); |
| + |
| + static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response)); |
| + v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); |
| + PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState()->isolate(), outValue.v8Value()); |
| + |
| + EXPECT_EQ("0123", pr->payerPhone()); |
| +} |
| + |
| +TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndEmptyPayerPhoneInResponse) |
| +{ |
| + ScriptState::Scope scope(getScriptState()); |
| + PaymentOptions options; |
| + options.setRequestPayerPhone(true); |
| + PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); |
| + EXPECT_FALSE(getExceptionState().hadException()); |
| + mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New(); |
| + response->payer_phone = ""; |
| + |
| + request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptState()), MockFunction::expectCall(getScriptState())); |
| + |
| + static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response)); |
| +} |
| + |
| +TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndNullPayerPhoneInResponse) |
| +{ |
| + ScriptState::Scope scope(getScriptState()); |
| + PaymentOptions options; |
| + options.setRequestPayerPhone(true); |
| + PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); |
| + EXPECT_FALSE(getExceptionState().hadException()); |
| + mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New(); |
| + |
| + request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptState()), MockFunction::expectCall(getScriptState())); |
| + |
| + static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response)); |
| +} |
| + |
| +TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneFalseAndEmptyPayerPhoneInResponse) |
| +{ |
| + ScriptState::Scope scope(getScriptState()); |
| + PaymentOptions options; |
| + options.setRequestPayerPhone(false); |
| + PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); |
| + EXPECT_FALSE(getExceptionState().hadException()); |
| + mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New(); |
| + response->payer_phone = ""; |
| + |
| + ScriptValue outValue; |
| + request->show(getScriptState()).then(PaymentResponseFunction::create(getScriptState(), &outValue), MockFunction::expectNoCall(getScriptState())); |
| + |
| + static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response)); |
| + v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); |
| + PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState()->isolate(), outValue.v8Value()); |
| + |
| + EXPECT_TRUE(pr->payerPhone().isEmpty()); |
|
zino
2016/06/07 16:40:08
isNull
|
| +} |
| + |
| +TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneFalseAndNullPayerPhoneInResponse) |
| +{ |
| + ScriptState::Scope scope(getScriptState()); |
| + PaymentOptions options; |
| + options.setRequestPayerPhone(false); |
| + PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); |
| + EXPECT_FALSE(getExceptionState().hadException()); |
| + mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New(); |
| + |
| + ScriptValue outValue; |
| + request->show(getScriptState()).then(PaymentResponseFunction::create(getScriptState(), &outValue), MockFunction::expectNoCall(getScriptState())); |
| + |
| + static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response)); |
| + v8::MicrotasksScope::PerformCheckpoint(getScriptState()->isolate()); |
| + PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(getScriptState()->isolate(), outValue.v8Value()); |
| + |
| + EXPECT_TRUE(pr->payerPhone().isNull()); |
| +} |
| + |
| +TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneFalseAndPayerPhoneExistsInResponse) |
| +{ |
| + ScriptState::Scope scope(getScriptState()); |
| + PaymentOptions options; |
| + options.setRequestPayerPhone(false); |
| + PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState()); |
| + EXPECT_FALSE(getExceptionState().hadException()); |
| + mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New(); |
| + response->payer_phone = "0123"; |
| + |
| + request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptState()), MockFunction::expectCall(getScriptState())); |
| + |
| + static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response)); |
| +} |
| + |
| } // namespace |
| } // namespace blink |