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

Side by Side 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, 7 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/credentialmanager/CredentialsContainer.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "modules/credentialmanager/CredentialsContainer.h"
6
7 #include <memory>
8
9 #include "bindings/core/v8/V8BindingForTesting.h"
10 #include "bindings/core/v8/V8GCController.h"
11 #include "core/dom/Document.h"
12 #include "modules/credentialmanager/CredentialManagerClient.h"
13 #include "modules/credentialmanager/CredentialRequestOptions.h"
14 #include "public/platform/WebCredential.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace blink {
19
20 using ::testing::_;
21 using ::testing::SaveArg;
22
23 namespace {
24
25 class MockCredentialManagerClient : public WebCredentialManagerClient {
26 public:
27 MOCK_METHOD2(DispatchFailedSignIn,
28 void(const WebCredential&, NotificationCallbacks*));
29 MOCK_METHOD2(DispatchStore,
30 void(const WebCredential&, NotificationCallbacks*));
31 MOCK_METHOD1(DispatchRequireUserMediation, void(NotificationCallbacks*));
32 MOCK_METHOD4(DispatchGet,
33 void(bool,
34 bool,
35 const WebVector<WebURL>& federations,
36 RequestCallbacks*));
37 };
38
39 } // namespace
40
41 // Make a call to CredentialsContainer::get(). Destroy v8::Context.
42 // Make sure that the renderer doesn't crash if got a credential.
43 TEST(CredentialsContainerTest, TestGetWithDocumentDestroyed) {
44 CredentialsContainer* credential_container = CredentialsContainer::Create();
45 std::unique_ptr<WebCredentialManagerClient::RequestCallbacks> get_callback;
46 {
47 // Set up.
48 V8TestingScope scope;
49 scope.GetDocument().SetSecurityOrigin(
50 SecurityOrigin::CreateFromString("https://example.test"));
51 testing::StrictMock<MockCredentialManagerClient> mock_client;
52 ProvideCredentialManagerClientTo(scope.GetPage(),
53 new CredentialManagerClient(&mock_client));
54
55 // Request a credential.
56 WebCredentialManagerClient::RequestCallbacks* callback = nullptr;
57 EXPECT_CALL(mock_client, DispatchGet(_, _, _, _))
58 .WillOnce(SaveArg<3>(&callback));
59 credential_container->get(scope.GetScriptState(),
60 CredentialRequestOptions());
61
62 ASSERT_TRUE(callback);
63 get_callback.reset(callback);
64 }
65
66 // Garbage collect v8::Context.
67 V8GCController::CollectAllGarbageForTesting(v8::Isolate::GetCurrent());
68
69 // Invoking the callback shouldn't crash.
70 get_callback->OnSuccess(std::unique_ptr<WebCredential>());
71 }
72
73 } // namespace blink
OLDNEW
« 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