OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/password_manager/core/browser/credential_manager_password_f orm_manager.h" | 5 #include "components/password_manager/core/browser/credential_manager_password_f orm_manager.h" |
6 #include <base/memory/ref_counted.h> | |
vasilii
2017/05/29 13:15:48
Improper place and style for the include (no <>)
kolos1
2017/05/29 15:47:06
Done.
| |
6 | 7 |
7 #include <memory> | 8 #include <memory> |
8 | 9 |
9 #include "base/macros.h" | 10 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
13 #include "components/autofill/core/common/password_form.h" | 14 #include "components/autofill/core/common/password_form.h" |
14 #include "components/password_manager/core/browser/fake_form_fetcher.h" | 15 #include "components/password_manager/core/browser/fake_form_fetcher.h" |
15 #include "components/password_manager/core/browser/stub_form_saver.h" | 16 #include "components/password_manager/core/browser/stub_form_saver.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
43 StubPasswordManagerClient client_; | 44 StubPasswordManagerClient client_; |
44 StubPasswordManagerDriver driver_; | 45 StubPasswordManagerDriver driver_; |
45 | 46 |
46 DISALLOW_COPY_AND_ASSIGN(CredentialManagerPasswordFormManagerTest); | 47 DISALLOW_COPY_AND_ASSIGN(CredentialManagerPasswordFormManagerTest); |
47 }; | 48 }; |
48 | 49 |
49 // Test that aborting early does not cause use after free. | 50 // Test that aborting early does not cause use after free. |
50 TEST_F(CredentialManagerPasswordFormManagerTest, AbortEarly) { | 51 TEST_F(CredentialManagerPasswordFormManagerTest, AbortEarly) { |
51 PasswordForm observed_form; | 52 PasswordForm observed_form; |
52 MockDelegate delegate; | 53 MockDelegate delegate; |
53 auto form_manager = base::MakeUnique<CredentialManagerPasswordFormManager>( | 54 auto form_manager = |
54 &client_, driver_.AsWeakPtr(), observed_form, | 55 base::MakeRefCounted<CredentialManagerPasswordFormManager>( |
55 base::MakeUnique<PasswordForm>(observed_form), &delegate, | 56 &client_, driver_.AsWeakPtr(), observed_form, |
56 base::MakeUnique<StubFormSaver>(), base::MakeUnique<FakeFormFetcher>()); | 57 base::MakeUnique<PasswordForm>(observed_form), &delegate, |
58 base::MakeUnique<StubFormSaver>(), | |
59 base::MakeUnique<FakeFormFetcher>()); | |
57 | 60 |
58 auto deleter = [&form_manager]() { form_manager.reset(); }; | 61 auto deleter = [&form_manager]() { form_manager = nullptr; }; |
59 | 62 |
60 // Simulate that the PasswordStore responded to the FormFetcher. As a result, | 63 // Simulate that the PasswordStore responded to the FormFetcher. As a result, |
61 // |form_manager| should call the delegate's OnProvisionalSaveComplete, which | 64 // |form_manager| should call the delegate's OnProvisionalSaveComplete, which |
62 // in turn should delete |form_fetcher|. | 65 // in turn should delete |form_fetcher|. |
63 EXPECT_CALL(delegate, OnProvisionalSaveComplete()).WillOnce(Invoke(deleter)); | 66 EXPECT_CALL(delegate, OnProvisionalSaveComplete()).WillOnce(Invoke(deleter)); |
64 static_cast<FakeFormFetcher*>(form_manager->form_fetcher()) | 67 static_cast<FakeFormFetcher*>(form_manager->form_fetcher()) |
65 ->SetNonFederated(std::vector<const PasswordForm*>(), 0u); | 68 ->SetNonFederated(std::vector<const PasswordForm*>(), 0u); |
66 // Check that |form_manager| was not deleted yet; doing so would have caused | 69 // Check that |form_manager| was not deleted yet; doing so would have caused |
67 // use after free during SetNonFederated. | 70 // use after free during SetNonFederated. |
68 EXPECT_TRUE(form_manager); | 71 EXPECT_TRUE(form_manager); |
69 | 72 |
70 base::RunLoop().RunUntilIdle(); | 73 base::RunLoop().RunUntilIdle(); |
71 | 74 |
72 // Ultimately, |form_fetcher| should have been deleted. It just should happen | 75 // Ultimately, |form_fetcher| should have been deleted. It just should happen |
73 // after it finishes executing. | 76 // after it finishes executing. |
74 EXPECT_FALSE(form_manager); | 77 EXPECT_FALSE(form_manager); |
75 } | 78 } |
76 | 79 |
77 } // namespace password_manager | 80 } // namespace password_manager |
OLD | NEW |