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

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

Issue 2192413002: Timeout if website never completes the transaction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Marijn's comments Created 4 years, 5 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/CompleteTest.cpp
diff --git a/third_party/WebKit/Source/modules/payments/CompleteTest.cpp b/third_party/WebKit/Source/modules/payments/CompleteTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..362c8e1dd814b2f5ca07272d89d557fbfb6c9a13
--- /dev/null
+++ b/third_party/WebKit/Source/modules/payments/CompleteTest.cpp
@@ -0,0 +1,117 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Tests for PaymentRequest::complete().
+
+#include "bindings/core/v8/V8BindingForTesting.h"
+#include "modules/payments/PaymentRequest.h"
+#include "modules/payments/PaymentTestHelper.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+namespace {
+
+TEST(CompleteTest, CannotCallCompleteTwice)
+{
+ V8TestingScope scope;
+ PaymentRequestMockFunctionScope funcs(scope.getScriptState());
+ makePaymentRequestOriginSecure(scope.document());
+ PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionState());
+ EXPECT_FALSE(scope.getExceptionState().hadException());
+ request->show(scope.getScriptState());
+ static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(buildPaymentResponseForTest());
+ request->complete(scope.getScriptState(), PaymentCompleter::Fail);
+
+ request->complete(scope.getScriptState(), PaymentCompleter::Success).then(funcs.expectNoCall(), funcs.expectCall());
+}
+
+TEST(CompleteTest, RejectCompletePromiseOnError)
+{
+ V8TestingScope scope;
+ PaymentRequestMockFunctionScope funcs(scope.getScriptState());
+ makePaymentRequestOriginSecure(scope.document());
+ PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionState());
+ EXPECT_FALSE(scope.getExceptionState().hadException());
+ request->show(scope.getScriptState());
+ static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(buildPaymentResponseForTest());
+
+ String errorMessage;
+ request->complete(scope.getScriptState(), PaymentCompleter::Success).then(funcs.expectNoCall(), funcs.expectCall(&errorMessage));
+
+ static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(mojom::blink::PaymentErrorReason::UNKNOWN);
+
+ v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate());
+ EXPECT_EQ("UnknownError: Request failed", errorMessage);
+}
+
+// If user cancels the transaction during processing, the complete() promise
+// should be rejected.
+TEST(CompleteTest, RejectCompletePromiseAfterError)
+{
+ V8TestingScope scope;
+ PaymentRequestMockFunctionScope funcs(scope.getScriptState());
+ makePaymentRequestOriginSecure(scope.document());
+ PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionState());
+ EXPECT_FALSE(scope.getExceptionState().hadException());
+ request->show(scope.getScriptState());
+ static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(buildPaymentResponseForTest());
+ static_cast<mojom::blink::PaymentRequestClient*>(request)->OnError(mojom::blink::PaymentErrorReason::USER_CANCEL);
+
+ request->complete(scope.getScriptState(), PaymentCompleter::Success).then(funcs.expectNoCall(), funcs.expectCall());
+}
+
+TEST(CompleteTest, ResolvePromiseOnComplete)
+{
+ V8TestingScope scope;
+ PaymentRequestMockFunctionScope funcs(scope.getScriptState());
+ makePaymentRequestOriginSecure(scope.document());
+ PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionState());
+ EXPECT_FALSE(scope.getExceptionState().hadException());
+ request->show(scope.getScriptState());
+ static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(buildPaymentResponseForTest());
+
+ request->complete(scope.getScriptState(), PaymentCompleter::Success).then(funcs.expectCall(), funcs.expectNoCall());
+
+ static_cast<mojom::blink::PaymentRequestClient*>(request)->OnComplete();
+}
+
+TEST(CompleteTest, RejectCompletePromiseOnUpdateDetailsFailure)
+{
+ V8TestingScope scope;
+ PaymentRequestMockFunctionScope funcs(scope.getScriptState());
+ makePaymentRequestOriginSecure(scope.document());
+ PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionState());
+ EXPECT_FALSE(scope.getExceptionState().hadException());
+ request->show(scope.getScriptState()).then(funcs.expectCall(), funcs.expectNoCall());
+ static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(buildPaymentResponseForTest());
+
+ String errorMessage;
+ request->complete(scope.getScriptState(), PaymentCompleter::Success).then(funcs.expectNoCall(), funcs.expectCall(&errorMessage));
+
+ request->onUpdatePaymentDetailsFailure("oops");
+
+ v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate());
+ EXPECT_EQ("AbortError: oops", errorMessage);
+}
+
+TEST(CompleteTest, RejectCompletePromiseAfterTimeout)
+{
+ V8TestingScope scope;
+ PaymentRequestMockFunctionScope funcs(scope.getScriptState());
+ makePaymentRequestOriginSecure(scope.document());
+ PaymentRequest* request = PaymentRequest::create(scope.getScriptState(), buildPaymentMethodDataForTest(), buildPaymentDetailsForTest(), scope.getExceptionState());
+ EXPECT_FALSE(scope.getExceptionState().hadException());
+ request->show(scope.getScriptState()).then(funcs.expectCall(), funcs.expectNoCall());
+ static_cast<mojom::blink::PaymentRequestClient*>(request)->OnPaymentResponse(buildPaymentResponseForTest());
+ request->onCompleteTimeoutForTesting();
+
+ String errorMessage;
+ request->complete(scope.getScriptState(), PaymentCompleter::Success).then(funcs.expectNoCall(), funcs.expectCall(&errorMessage));
+
+ v8::MicrotasksScope::PerformCheckpoint(scope.getScriptState()->isolate());
+ EXPECT_EQ("InvalidStateError: Timed out after 60 seconds, complete() called too late", errorMessage);
+}
+
+} // namespace
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/modules.gypi ('k') | third_party/WebKit/Source/modules/payments/PaymentCompleter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698