OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/password_form_manager.h" | 5 #include "components/password_manager/core/browser/password_form_manager.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 2975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2986 // consumed before, the PasswordFormManager does not add itself as a consumer | 2986 // consumed before, the PasswordFormManager does not add itself as a consumer |
2987 // again. | 2987 // again. |
2988 TEST_F(PasswordFormManagerTest, GrabFetcher_Same) { | 2988 TEST_F(PasswordFormManagerTest, GrabFetcher_Same) { |
2989 auto fetcher = base::MakeUnique<MockFormFetcher>(); | 2989 auto fetcher = base::MakeUnique<MockFormFetcher>(); |
2990 fetcher->Fetch(); | 2990 fetcher->Fetch(); |
2991 PasswordFormManager form_manager( | 2991 PasswordFormManager form_manager( |
2992 password_manager(), client(), client()->driver(), *observed_form(), | 2992 password_manager(), client(), client()->driver(), *observed_form(), |
2993 base::MakeUnique<MockFormSaver>(), fetcher.get()); | 2993 base::MakeUnique<MockFormSaver>(), fetcher.get()); |
2994 | 2994 |
2995 EXPECT_CALL(*fetcher, AddConsumer(_)).Times(0); | 2995 EXPECT_CALL(*fetcher, AddConsumer(_)).Times(0); |
| 2996 EXPECT_CALL(*fetcher, RemoveConsumer(_)).Times(0); |
2996 form_manager.GrabFetcher(std::move(fetcher)); | 2997 form_manager.GrabFetcher(std::move(fetcher)); |
| 2998 // There will be a RemoveConsumer call as soon as form_manager goes out of |
| 2999 // scope, but the test needs to ensure that there is none as a result of |
| 3000 // GrabFetcher. |
| 3001 Mock::VerifyAndClearExpectations(form_manager.form_fetcher()); |
| 3002 } |
| 3003 |
| 3004 // Check that if asked to take ownership of a different FormFetcher than which |
| 3005 // it had consumed before, the PasswordFormManager adds itself as a consumer |
| 3006 // and replaces the references to the old results. |
| 3007 TEST_F(PasswordFormManagerTest, GrabFetcher_Different) { |
| 3008 PasswordForm old_match = *observed_form(); |
| 3009 old_match.username_value = ASCIIToUTF16("user1"); |
| 3010 old_match.password_value = ASCIIToUTF16("pass"); |
| 3011 fake_form_fetcher()->SetNonFederated({&old_match}, 0u); |
| 3012 EXPECT_EQ(1u, form_manager()->best_matches().size()); |
| 3013 EXPECT_EQ(&old_match, form_manager()->best_matches().begin()->second); |
| 3014 |
| 3015 // |form_manager()| uses |fake_form_fetcher()|, which is an instance different |
| 3016 // from |fetcher| below. |
| 3017 auto fetcher = base::MakeUnique<MockFormFetcher>(); |
| 3018 fetcher->Fetch(); |
| 3019 fetcher->SetNonFederated(std::vector<const PasswordForm*>(), 0u); |
| 3020 EXPECT_CALL(*fetcher, AddConsumer(form_manager())); |
| 3021 form_manager()->GrabFetcher(std::move(fetcher)); |
| 3022 |
| 3023 EXPECT_EQ(0u, form_manager()->best_matches().size()); |
| 3024 } |
| 3025 |
| 3026 // Check that on changing FormFetcher, the PasswordFormManager removes itself |
| 3027 // from consuming the old one. |
| 3028 TEST_F(PasswordFormManagerTest, GrabFetcher_Remove) { |
| 3029 MockFormFetcher old_fetcher; |
| 3030 FormFetcher::Consumer* added_consumer = nullptr; |
| 3031 EXPECT_CALL(old_fetcher, AddConsumer(_)) |
| 3032 .WillOnce(SaveArg<0>(&added_consumer)); |
| 3033 PasswordFormManager form_manager( |
| 3034 password_manager(), client(), client()->driver(), *observed_form(), |
| 3035 base::MakeUnique<MockFormSaver>(), &old_fetcher); |
| 3036 EXPECT_EQ(&form_manager, added_consumer); |
| 3037 |
| 3038 auto new_fetcher = base::MakeUnique<MockFormFetcher>(); |
| 3039 EXPECT_CALL(*new_fetcher, AddConsumer(&form_manager)); |
| 3040 EXPECT_CALL(old_fetcher, RemoveConsumer(&form_manager)); |
| 3041 form_manager.GrabFetcher(std::move(new_fetcher)); |
2997 } | 3042 } |
2998 | 3043 |
2999 } // namespace password_manager | 3044 } // namespace password_manager |
OLD | NEW |