Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2193)

Unified Diff: third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp

Issue 2073603002: Add shippingOption to PaymentResponse (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase #2 Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 0d16400a70e297bece500960824ba5b91c26f34b..dbc425cb61b39523b10741142808797849e7999d 100644
--- a/third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp
+++ b/third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp
@@ -5,17 +5,13 @@
#include "modules/payments/PaymentRequest.h"
#include "bindings/core/v8/JSONValuesForV8.h"
-#include "bindings/core/v8/ScriptFunction.h"
#include "bindings/core/v8/V8BindingForTesting.h"
-#include "bindings/modules/v8/V8PaymentResponse.h"
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
#include "modules/payments/PaymentAddress.h"
-#include "modules/payments/PaymentResponse.h"
#include "modules/payments/PaymentTestHelper.h"
#include "platform/heap/HeapAllocator.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include <utility>
namespace blink {
namespace {
@@ -202,131 +198,6 @@ TEST(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress)
static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddressChange(mojom::blink::PaymentAddress::New());
}
-TEST(PaymentRequestTest, RejectShowPromiseWithRequestShippingTrueAndEmptyShippingAddressInResponse)
-{
- V8TestingScope scope;
- PaymentRequestMockFunctionScope funcs(scope.getScriptState());
- makePaymentRequestOriginSecure(scope.document());
- PaymentOptions options;
- options.setRequestShipping(true);
- PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getExceptionState());
- EXPECT_FALSE(scope.getExceptionState().hadException());
- mojom::blink::PaymentResponsePtr response = buildPaymentResponseForTest();
-
- request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expectCall());
-
- static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response));
-}
-
-TEST(PaymentRequestTest, RejectShowPromiseWithRequestShippingTrueAndInvalidShippingAddressInResponse)
-{
- V8TestingScope scope;
- PaymentRequestMockFunctionScope funcs(scope.getScriptState());
- makePaymentRequestOriginSecure(scope.document());
- PaymentOptions options;
- options.setRequestShipping(true);
- PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getExceptionState());
- EXPECT_FALSE(scope.getExceptionState().hadException());
- mojom::blink::PaymentResponsePtr response = buildPaymentResponseForTest();
- response->shipping_address = mojom::blink::PaymentAddress::New();
-
- request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expectCall());
-
- static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response));
-}
-
-TEST(PaymentRequestTest, RejectShowPromiseWithRequestShippingFalseAndShippingAddressExistsInResponse)
-{
- V8TestingScope scope;
- PaymentRequestMockFunctionScope funcs(scope.getScriptState());
- makePaymentRequestOriginSecure(scope.document());
- PaymentOptions options;
- options.setRequestShipping(false);
- PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getExceptionState());
- EXPECT_FALSE(scope.getExceptionState().hadException());
- mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New();
- response->shipping_address = mojom::blink::PaymentAddress::New();
- response->shipping_address->country = "US";
- response->shipping_address->language_code = "en";
- response->shipping_address->script_code = "Latn";
-
- request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expectCall());
-
- static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response));
-}
-
-class PaymentResponseFunction : public ScriptFunction {
-public:
- static v8::Local<v8::Function> create(ScriptState* scriptState, ScriptValue* outValue)
- {
- PaymentResponseFunction* self = new PaymentResponseFunction(scriptState, outValue);
- return self->bindToV8Function();
- }
-
- ScriptValue call(ScriptValue value) override
- {
- DCHECK(!value.isEmpty());
- *m_value = value;
- return value;
- }
-
-private:
- PaymentResponseFunction(ScriptState* scriptState, ScriptValue* outValue)
- : ScriptFunction(scriptState)
- , m_value(outValue)
- {
- DCHECK(m_value);
- }
-
- ScriptValue* m_value;
-};
-
-TEST(PaymentRequestTest, ResolveShowPromiseWithRequestShippingTrueAndValidShippingAddressInResponse)
-{
- V8TestingScope scope;
- PaymentRequestMockFunctionScope funcs(scope.getScriptState());
- makePaymentRequestOriginSecure(scope.document());
- PaymentOptions options;
- options.setRequestShipping(true);
- PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getExceptionState());
- EXPECT_FALSE(scope.getExceptionState().hadException());
- mojom::blink::PaymentResponsePtr response = buildPaymentResponseForTest();
- response->shipping_address = mojom::blink::PaymentAddress::New();
- response->shipping_address->country = "US";
- response->shipping_address->language_code = "en";
- response->shipping_address->script_code = "Latn";
-
- ScriptValue outValue;
- request->show(scope.getScriptState()).then(PaymentResponseFunction::create(scope.getScriptState(), &outValue), funcs.expectNoCall());
-
- static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response));
- v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
- PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate(), outValue.v8Value());
-
- EXPECT_EQ("US", pr->shippingAddress()->country());
- EXPECT_EQ("en-Latn", pr->shippingAddress()->languageCode());
-}
-
-TEST(PaymentRequestTest, ResolveShowPromiseWithRequestShippingFalseAndEmptyShippingAddressInResponse)
-{
- V8TestingScope scope;
- PaymentRequestMockFunctionScope funcs(scope.getScriptState());
- makePaymentRequestOriginSecure(scope.document());
- PaymentOptions options;
- options.setRequestShipping(false);
- PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getExceptionState());
- EXPECT_FALSE(scope.getExceptionState().hadException());
-
- ScriptValue outValue;
- request->show(scope.getScriptState()).then(PaymentResponseFunction::create(scope.getScriptState(), &outValue), funcs.expectNoCall());
-
- static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(buildPaymentResponseForTest());
- v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
- PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate(), outValue.v8Value());
-
- EXPECT_EQ(nullptr, pr->shippingAddress());
-}
-
TEST(PaymentRequestTest, OnShippingOptionChange)
{
V8TestingScope scope;
@@ -543,205 +414,5 @@ TEST(PaymentRequestTest, UseTheSelectedShippingOptionFromPaymentDetailsUpdate)
EXPECT_EQ("fast", request->shippingOption());
}
-TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailTrueAndValidPayerEmailInResponse)
-{
- V8TestingScope scope;
- PaymentRequestMockFunctionScope funcs(scope.getScriptState());
- makePaymentRequestOriginSecure(scope.document());
- PaymentOptions options;
- options.setRequestPayerEmail(true);
- PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getExceptionState());
- EXPECT_FALSE(scope.getExceptionState().hadException());
- mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New();
- response->total_amount = mojom::blink::PaymentCurrencyAmount::New();
- response->payer_email = "abc@gmail.com";
-
- ScriptValue outValue;
- request->show(scope.getScriptState()).then(PaymentResponseFunction::create(scope.getScriptState(), &outValue), funcs.expectNoCall());
-
- static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response));
- v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
- PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate(), outValue.v8Value());
-
- EXPECT_EQ("abc@gmail.com", pr->payerEmail());
-}
-
-TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailTrueAndEmptyPayerEmailInResponse)
-{
- V8TestingScope scope;
- PaymentRequestMockFunctionScope funcs(scope.getScriptState());
- makePaymentRequestOriginSecure(scope.document());
- PaymentOptions options;
- options.setRequestPayerEmail(true);
- PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getExceptionState());
- EXPECT_FALSE(scope.getExceptionState().hadException());
- mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New();
- response->total_amount = mojom::blink::PaymentCurrencyAmount::New();
- response->payer_email = "";
-
- request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expectCall());
-
- static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response));
-}
-
-TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailTrueAndNullPayerEmailInResponse)
-{
- V8TestingScope scope;
- PaymentRequestMockFunctionScope funcs(scope.getScriptState());
- makePaymentRequestOriginSecure(scope.document());
- PaymentOptions options;
- options.setRequestPayerEmail(true);
- PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getExceptionState());
- EXPECT_FALSE(scope.getExceptionState().hadException());
- mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New();
- response->total_amount = mojom::blink::PaymentCurrencyAmount::New();
- response->payer_email = String();
-
- request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expectCall());
-
- static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response));
-}
-
-TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerEmailFalseAndNonNullPayerEmailInResponse)
-{
- V8TestingScope scope;
- PaymentRequestMockFunctionScope funcs(scope.getScriptState());
- makePaymentRequestOriginSecure(scope.document());
- PaymentOptions options;
- options.setRequestPayerEmail(false);
- PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getExceptionState());
- EXPECT_FALSE(scope.getExceptionState().hadException());
- mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New();
- response->total_amount = mojom::blink::PaymentCurrencyAmount::New();
- response->payer_email = "";
-
- request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expectCall());
-
- static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response));
-}
-
-TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerEmailFalseAndNullPayerEmailInResponse)
-{
- V8TestingScope scope;
- PaymentRequestMockFunctionScope funcs(scope.getScriptState());
- makePaymentRequestOriginSecure(scope.document());
- PaymentOptions options;
- options.setRequestPayerEmail(false);
- PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getExceptionState());
- EXPECT_FALSE(scope.getExceptionState().hadException());
- mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New();
- response->total_amount = mojom::blink::PaymentCurrencyAmount::New();
- response->payer_email = String();
-
- ScriptValue outValue;
- request->show(scope.getScriptState()).then(PaymentResponseFunction::create(scope.getScriptState(), &outValue), funcs.expectNoCall());
-
- static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response));
- v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
- PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate(), outValue.v8Value());
-
- EXPECT_TRUE(pr->payerEmail().isNull());
-}
-
-TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneTrueAndValidPayerPhoneInResponse)
-{
- V8TestingScope scope;
- PaymentRequestMockFunctionScope funcs(scope.getScriptState());
- makePaymentRequestOriginSecure(scope.document());
- PaymentOptions options;
- options.setRequestPayerPhone(true);
- PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getExceptionState());
- EXPECT_FALSE(scope.getExceptionState().hadException());
- mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New();
- response->total_amount = mojom::blink::PaymentCurrencyAmount::New();
- response->payer_phone = "0123";
-
- ScriptValue outValue;
- request->show(scope.getScriptState()).then(PaymentResponseFunction::create(scope.getScriptState(), &outValue), funcs.expectNoCall());
-
- static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response));
- v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
- PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate(), outValue.v8Value());
-
- EXPECT_EQ("0123", pr->payerPhone());
-}
-
-TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndEmptyPayerPhoneInResponse)
-{
- V8TestingScope scope;
- PaymentRequestMockFunctionScope funcs(scope.getScriptState());
- makePaymentRequestOriginSecure(scope.document());
- PaymentOptions options;
- options.setRequestPayerPhone(true);
- PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getExceptionState());
- EXPECT_FALSE(scope.getExceptionState().hadException());
- mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New();
- response->total_amount = mojom::blink::PaymentCurrencyAmount::New();
- response->payer_phone = "";
-
- request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expectCall());
-
- static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response));
-}
-
-TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneTrueAndNullPayerPhoneInResponse)
-{
- V8TestingScope scope;
- PaymentRequestMockFunctionScope funcs(scope.getScriptState());
- makePaymentRequestOriginSecure(scope.document());
- PaymentOptions options;
- options.setRequestPayerPhone(true);
- PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getExceptionState());
- EXPECT_FALSE(scope.getExceptionState().hadException());
- mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New();
- response->total_amount = mojom::blink::PaymentCurrencyAmount::New();
- response->payer_phone = String();
-
- request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expectCall());
-
- static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response));
-}
-
-TEST(PaymentRequestTest, RejectShowPromiseWithRequestPayerPhoneFalseAndNonNulPayerPhoneInResponse)
-{
- V8TestingScope scope;
- PaymentRequestMockFunctionScope funcs(scope.getScriptState());
- makePaymentRequestOriginSecure(scope.document());
- PaymentOptions options;
- options.setRequestPayerPhone(false);
- PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getExceptionState());
- EXPECT_FALSE(scope.getExceptionState().hadException());
- mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New();
- response->total_amount = mojom::blink::PaymentCurrencyAmount::New();
- response->payer_phone = "";
-
- request->show(scope.getScriptState()).then(funcs.expectNoCall(), funcs.expectCall());
-
- static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response));
-}
-
-TEST(PaymentRequestTest, ResolveShowPromiseWithRequestPayerPhoneFalseAndNullPayerPhoneInResponse)
-{
- V8TestingScope scope;
- PaymentRequestMockFunctionScope funcs(scope.getScriptState());
- makePaymentRequestOriginSecure(scope.document());
- PaymentOptions options;
- options.setRequestPayerPhone(false);
- PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), options, scope.getExceptionState());
- EXPECT_FALSE(scope.getExceptionState().hadException());
- mojom::blink::PaymentResponsePtr response = mojom::blink::PaymentResponse::New();
- response->total_amount = mojom::blink::PaymentCurrencyAmount::New();
- response->payer_phone = String();
-
- ScriptValue outValue;
- request->show(scope.getScriptState()).then(PaymentResponseFunction::create(scope.getScriptState(), &outValue), funcs.expectNoCall());
-
- static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response));
- v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
- PaymentResponse* pr = V8PaymentResponse::toImplWithTypeCheck(scope.isolate(), outValue.v8Value());
-
- EXPECT_TRUE(pr->payerPhone().isNull());
-}
-
} // namespace
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698