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

Unified Diff: third_party/WebKit/Source/modules/credentialmanager/CredentialsContainerTest.cpp

Issue 2850813004: Add a nullptr check in blink::RequestCallbacks::onSuccess to fix crash. (Closed)
Patch Set: rebase Created 3 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/modules/credentialmanager/CredentialsContainer.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/credentialmanager/CredentialsContainerTest.cpp
diff --git a/third_party/WebKit/Source/modules/credentialmanager/CredentialsContainerTest.cpp b/third_party/WebKit/Source/modules/credentialmanager/CredentialsContainerTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..20bcc9eeb95e1b458438c44f7ab20e0a8c4908ad
--- /dev/null
+++ b/third_party/WebKit/Source/modules/credentialmanager/CredentialsContainerTest.cpp
@@ -0,0 +1,73 @@
+// Copyright 2017 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.
+
+#include "modules/credentialmanager/CredentialsContainer.h"
+
+#include <memory>
+
+#include "bindings/core/v8/V8BindingForTesting.h"
+#include "bindings/core/v8/V8GCController.h"
+#include "core/dom/Document.h"
+#include "modules/credentialmanager/CredentialManagerClient.h"
+#include "modules/credentialmanager/CredentialRequestOptions.h"
+#include "public/platform/WebCredential.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+using ::testing::_;
+using ::testing::SaveArg;
+
+namespace {
+
+class MockCredentialManagerClient : public WebCredentialManagerClient {
+ public:
+ MOCK_METHOD2(DispatchFailedSignIn,
+ void(const WebCredential&, NotificationCallbacks*));
+ MOCK_METHOD2(DispatchStore,
+ void(const WebCredential&, NotificationCallbacks*));
+ MOCK_METHOD1(DispatchRequireUserMediation, void(NotificationCallbacks*));
+ MOCK_METHOD4(DispatchGet,
+ void(bool,
+ bool,
+ const WebVector<WebURL>& federations,
+ RequestCallbacks*));
+};
+
+} // namespace
+
+// Make a call to CredentialsContainer::get(). Destroy v8::Context.
+// Make sure that the renderer doesn't crash if got a credential.
+TEST(CredentialsContainerTest, TestGetWithDocumentDestroyed) {
+ CredentialsContainer* credential_container = CredentialsContainer::Create();
+ std::unique_ptr<WebCredentialManagerClient::RequestCallbacks> get_callback;
+ {
+ // Set up.
+ V8TestingScope scope;
+ scope.GetDocument().SetSecurityOrigin(
+ SecurityOrigin::CreateFromString("https://example.test"));
+ testing::StrictMock<MockCredentialManagerClient> mock_client;
+ ProvideCredentialManagerClientTo(scope.GetPage(),
+ new CredentialManagerClient(&mock_client));
+
+ // Request a credential.
+ WebCredentialManagerClient::RequestCallbacks* callback = nullptr;
+ EXPECT_CALL(mock_client, DispatchGet(_, _, _, _))
+ .WillOnce(SaveArg<3>(&callback));
+ credential_container->get(scope.GetScriptState(),
+ CredentialRequestOptions());
+
+ ASSERT_TRUE(callback);
+ get_callback.reset(callback);
+ }
+
+ // Garbage collect v8::Context.
+ V8GCController::CollectAllGarbageForTesting(v8::Isolate::GetCurrent());
+
+ // Invoking the callback shouldn't crash.
+ get_callback->OnSuccess(std::unique_ptr<WebCredential>());
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/credentialmanager/CredentialsContainer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698