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

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: includes 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
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 "core/testing/DummyPageHolder.h"
11 #include "modules/credentialmanager/CredentialManagerClient.h"
12 #include "modules/credentialmanager/CredentialRequestOptions.h"
13 #include "public/platform/WebCredential.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace blink {
18
19 using ::testing::_;
20 using ::testing::SaveArg;
21
22 namespace {
23
24 class MockCredentialManagerClient : public WebCredentialManagerClient {
25 public:
26 MOCK_METHOD2(DispatchFailedSignIn,
27 void(const WebCredential&, NotificationCallbacks*));
28 MOCK_METHOD2(DispatchStore,
29 void(const WebCredential&, NotificationCallbacks*));
30 MOCK_METHOD1(DispatchRequireUserMediation, void(NotificationCallbacks*));
31 MOCK_METHOD4(DispatchGet,
32 void(bool,
33 bool,
34 const WebVector<WebURL>& federations,
35 RequestCallbacks*));
36 };
37
38 } // namespace
39
40 // Make a call to CredentialsContainer::get().
41 // Clear ScriptState and destroy the frame.
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 RefPtr<ScriptState> script_state;
47 {
48 // Set up.
49 V8TestingScope scope;
50 scope.GetDocument().SetSecurityOrigin(
51 SecurityOrigin::CreateFromString("https://example.test"));
52 testing::StrictMock<MockCredentialManagerClient> mock_client;
53 ProvideCredentialManagerClientTo(scope.GetPage(),
54 new CredentialManagerClient(&mock_client));
55 script_state = scope.GetScriptState();
56
57 // Request a credential.
58 WebCredentialManagerClient::RequestCallbacks* callback = nullptr;
59 EXPECT_CALL(mock_client, DispatchGet(_, _, _, _))
60 .WillOnce(SaveArg<3>(&callback));
61 credential_container->get(script_state.Get(), CredentialRequestOptions());
62
63 ASSERT_TRUE(callback);
64 get_callback.reset(callback);
65 }
66
67 // Clear ScriptState explicitly. Invoking the callback shouldn't crash.
68 script_state->ClearContext();
69 get_callback->OnSuccess(std::unique_ptr<WebCredential>());
70 }
71
72 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698