| 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 1e444e7b89d3c1dc5dead2eb55c230c44757af92..1074fbb2274578515b960d879a26278318564854 100644
|
| --- a/third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp
|
| +++ b/third_party/WebKit/Source/modules/payments/PaymentRequestTest.cpp
|
| @@ -4,47 +4,23 @@
|
|
|
| #include "modules/payments/PaymentRequest.h"
|
|
|
| -#include "bindings/core/v8/ExceptionState.h"
|
| #include "bindings/core/v8/JSONValuesForV8.h"
|
| +#include "bindings/core/v8/ScriptFunction.h"
|
| #include "bindings/core/v8/ScriptState.h"
|
| #include "bindings/modules/v8/V8PaymentResponse.h"
|
| #include "core/dom/ExceptionCode.h"
|
| -#include "core/testing/DummyPageHolder.h"
|
| -#include "modules/payments/CurrencyAmount.h"
|
| +#include "modules/payments/MockFunction.h"
|
| #include "modules/payments/PaymentAddress.h"
|
| #include "modules/payments/PaymentDetailsTestHelper.h"
|
| -#include "modules/payments/PaymentItem.h"
|
| -#include "modules/payments/ShippingOption.h"
|
| +#include "modules/payments/PaymentRequestTestBase.h"
|
| #include "platform/heap/HeapAllocator.h"
|
| -#include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| -#include "wtf/OwnPtr.h"
|
| #include <utility>
|
|
|
| namespace blink {
|
| namespace {
|
|
|
| -class PaymentRequestTest : public testing::Test {
|
| -public:
|
| - PaymentRequestTest()
|
| - : m_page(DummyPageHolder::create())
|
| - {
|
| - setSecurityOrigin("https://www.example.com/");
|
| - }
|
| -
|
| - ~PaymentRequestTest() override {}
|
| -
|
| - ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->document().frame()); }
|
| - ExceptionState& getExceptionState() { return m_exceptionState; }
|
| -
|
| - void setSecurityOrigin(const String& securityOrigin)
|
| - {
|
| - m_page->document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(), securityOrigin)));
|
| - }
|
| -
|
| -private:
|
| - OwnPtr<DummyPageHolder> m_page;
|
| - TrackExceptionState m_exceptionState;
|
| +class PaymentRequestTest : public PaymentRequestTestBase {
|
| };
|
|
|
| TEST_F(PaymentRequestTest, NoExceptionWithValidData)
|
| @@ -192,47 +168,6 @@ TEST_F(PaymentRequestTest, SelectLastSelectedShippingOptionWhenShippingRequested
|
| EXPECT_EQ("express", request->shippingOption());
|
| }
|
|
|
| -TEST_F(PaymentRequestTest, AbortWithoutShowShouldThrow)
|
| -{
|
| - PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState());
|
| - EXPECT_FALSE(getExceptionState().hadException());
|
| -
|
| - request->abort(getExceptionState());
|
| - EXPECT_TRUE(getExceptionState().hadException());
|
| -}
|
| -
|
| -class MockFunction : public ScriptFunction {
|
| -public:
|
| - static v8::Local<v8::Function> noExpectations(ScriptState* scriptState)
|
| - {
|
| - MockFunction* self = new MockFunction(scriptState);
|
| - return self->bindToV8Function();
|
| - }
|
| -
|
| - static v8::Local<v8::Function> expectCall(ScriptState* scriptState)
|
| - {
|
| - MockFunction* self = new MockFunction(scriptState);
|
| - EXPECT_CALL(*self, call(testing::_));
|
| - return self->bindToV8Function();
|
| - }
|
| -
|
| - static v8::Local<v8::Function> expectNoCall(ScriptState* scriptState)
|
| - {
|
| - MockFunction* self = new MockFunction(scriptState);
|
| - EXPECT_CALL(*self, call(testing::_)).Times(0);
|
| - return self->bindToV8Function();
|
| - }
|
| -
|
| -private:
|
| - explicit MockFunction(ScriptState* scriptState)
|
| - : ScriptFunction(scriptState)
|
| - {
|
| - ON_CALL(*this, call(testing::_)).WillByDefault(testing::ReturnArg<0>());
|
| - }
|
| -
|
| - MOCK_METHOD1(call, ScriptValue(ScriptValue));
|
| -};
|
| -
|
| class PaymentResponseFunction : public ScriptFunction {
|
| public:
|
| static v8::Local<v8::Function> create(ScriptState* scriptState, ScriptValue* outValue)
|
| @@ -259,18 +194,6 @@ private:
|
| ScriptValue* m_value;
|
| };
|
|
|
| -TEST_F(PaymentRequestTest, CanAbortAfterShow)
|
| -{
|
| - ScriptState::Scope scope(getScriptState());
|
| - PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), getExceptionState());
|
| - EXPECT_FALSE(getExceptionState().hadException());
|
| -
|
| - request->show(getScriptState()).then(MockFunction::expectNoCall(getScriptState()), MockFunction::noExpectations(getScriptState()));
|
| - request->abort(getExceptionState());
|
| -
|
| - EXPECT_FALSE(getExceptionState().hadException());
|
| -}
|
| -
|
| TEST_F(PaymentRequestTest, RejectShowPromiseOnInvalidShippingAddress)
|
| {
|
| ScriptState::Scope scope(getScriptState());
|
| @@ -318,14 +241,15 @@ TEST_F(PaymentRequestTest, RejectShowPromiseWithRequestShippingFalseAndShippingA
|
| options.setRequestShipping(false);
|
| PaymentRequest* request = PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), buildPaymentDetailsForTest(), options, getExceptionState());
|
| EXPECT_FALSE(getExceptionState().hadException());
|
| - mojom::blink::PaymentAddressPtr shippingAddress = mojom::blink::PaymentAddress::New();
|
| - shippingAddress->country = "US";
|
| - shippingAddress->language_code = "en";
|
| - shippingAddress->script_code = "Latn";
|
| + 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(getScriptState()).then(MockFunction::expectNoCall(getScriptState()), MockFunction::expectCall(getScriptState()));
|
|
|
| - static_cast<mojom::blink::PaymentRequestClient*>(request)->OnShippingAddressChange(std::move(shippingAddress));
|
| + static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(std::move(response));
|
| }
|
|
|
| TEST_F(PaymentRequestTest, ResolveShowPromiseWithRequestShippingTrueAndValidShippingAddressInResponse)
|
|
|