Chromium Code Reviews| Index: third_party/WebKit/Source/modules/payments/PaymentResponseTest.cpp |
| diff --git a/third_party/WebKit/Source/modules/payments/PaymentResponseTest.cpp b/third_party/WebKit/Source/modules/payments/PaymentResponseTest.cpp |
| index ff3660416f96cc0eba2e2a4828fbb03816773dc0..6b6e3fd5974e5ac0b87f545a96b785e5ba80d053 100644 |
| --- a/third_party/WebKit/Source/modules/payments/PaymentResponseTest.cpp |
| +++ b/third_party/WebKit/Source/modules/payments/PaymentResponseTest.cpp |
| @@ -6,16 +6,15 @@ |
| #include "bindings/core/v8/ExceptionState.h" |
| #include "bindings/core/v8/ScriptState.h" |
| +#include "bindings/core/v8/ScriptValue.h" |
| #include "core/testing/DummyPageHolder.h" |
| #include "modules/payments/PaymentCompleter.h" |
| -#include "modules/payments/PaymentDetailsTestHelper.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "wtf/OwnPtr.h" |
| #include <utility> |
| namespace blink { |
| -namespace { |
|
Marijn Kruisselbrink
2016/05/02 18:04:58
Any particular reason you got rid of the anonymous
please use gerrit instead
2016/05/02 18:17:24
`git cl format` kept trying to indent anonymous na
Marijn Kruisselbrink
2016/05/02 18:53:48
Ah, yeah, git cl format on blink code never seems
|
| class MockPaymentCompleter : public GarbageCollectedFinalized<MockPaymentCompleter>, public PaymentCompleter { |
| USING_GARBAGE_COLLECTED_MIXIN(MockPaymentCompleter); |
| @@ -43,7 +42,6 @@ public: |
| PaymentResponseTest() |
| : m_page(DummyPageHolder::create()) |
| { |
| - m_page->document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(), "https://www.example.com/"))); |
| } |
| ~PaymentResponseTest() override {} |
| @@ -58,6 +56,7 @@ private: |
| TEST_F(PaymentResponseTest, DataCopiedOver) |
| { |
| + ScriptState::Scope scope(getScriptState()); |
| mojom::blink::PaymentResponsePtr input = mojom::blink::PaymentResponse::New(); |
| input->method_name = "foo"; |
| input->stringified_details = "{\"transactionId\": 123}"; |
| @@ -65,12 +64,21 @@ TEST_F(PaymentResponseTest, DataCopiedOver) |
| PaymentResponse output(std::move(input), completeCallback); |
| - // TODO(rouslan): Verify that output.details() contains parsed input->stringified_details. |
| - EXPECT_FALSE(getExceptionState().hadException()); |
| + ASSERT_FALSE(getExceptionState().hadException()); |
|
Marijn Kruisselbrink
2016/05/02 18:04:58
This assert seems a bit unnecessary? At this point
please use gerrit instead
2016/05/02 18:17:24
Removed. Not sure why it was here.
|
| EXPECT_EQ("foo", output.methodName()); |
| + |
| + ScriptValue details = output.details(getScriptState(), getExceptionState()); |
| + |
| + ASSERT_FALSE(getExceptionState().hadException()); |
| + ASSERT_TRUE(details.v8Value()->IsObject()); |
| + |
| + ScriptValue transactionId(getScriptState(), details.v8Value().As<v8::Object>()->Get(v8String(getScriptState()->isolate(), "transactionId"))); |
| + |
| + ASSERT_TRUE(transactionId.v8Value()->IsNumber()); |
| + EXPECT_EQ(123, transactionId.v8Value().As<v8::Number>()->Value()); |
| } |
| -TEST_F(PaymentResponseTest, CompleteCalled) |
| +TEST_F(PaymentResponseTest, CompleteCalledWithSuccess) |
| { |
| mojom::blink::PaymentResponsePtr input = mojom::blink::PaymentResponse::New(); |
| input->method_name = "foo"; |
| @@ -84,5 +92,18 @@ TEST_F(PaymentResponseTest, CompleteCalled) |
| output.complete(getScriptState(), true); |
| } |
| -} // namespace |
| +TEST_F(PaymentResponseTest, CompleteCalledWithFailure) |
| +{ |
| + mojom::blink::PaymentResponsePtr input = mojom::blink::PaymentResponse::New(); |
| + input->method_name = "foo"; |
| + input->stringified_details = "{\"transactionId\": 123}"; |
| + MockPaymentCompleter* completeCallback = new MockPaymentCompleter; |
| + PaymentResponse output(std::move(input), completeCallback); |
| + |
| + EXPECT_FALSE(getExceptionState().hadException()); |
| + EXPECT_CALL(*completeCallback, complete(getScriptState(), false)); |
| + |
| + output.complete(getScriptState(), false); |
| +} |
| + |
| } // namespace blink |