OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/password_manager/chrome_password_manager_client.h" | 5 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
11 #include "base/prefs/pref_registry_simple.h" | 11 #include "base/prefs/pref_registry_simple.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/prefs/testing_pref_service.h" | 13 #include "base/prefs/testing_pref_service.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/browser/sync/profile_sync_service_factory.h" | 16 #include "chrome/browser/sync/profile_sync_service_factory.h" |
17 #include "chrome/browser/sync/profile_sync_service_mock.h" | 17 #include "chrome/browser/sync/profile_sync_service_mock.h" |
18 #include "chrome/common/channel_info.h" | 18 #include "chrome/common/channel_info.h" |
19 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 19 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
20 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
21 #include "components/autofill/content/common/autofill_messages.h" | 21 #include "components/autofill/content/common/autofill_messages.h" |
22 #include "components/password_manager/content/browser/password_manager_internals
_service_factory.h" | 22 #include "components/password_manager/content/browser/password_manager_internals
_service_factory.h" |
23 #include "components/password_manager/content/common/credential_manager_messages
.h" | 23 #include "components/password_manager/content/common/credential_manager_messages
.h" |
24 #include "components/password_manager/core/browser/credentials_filter.h" | 24 #include "components/password_manager/core/browser/credentials_filter.h" |
25 #include "components/password_manager/core/browser/log_manager.h" | 25 #include "components/password_manager/core/browser/log_manager.h" |
26 #include "components/password_manager/core/browser/log_receiver.h" | 26 #include "components/password_manager/core/browser/log_receiver.h" |
27 #include "components/password_manager/core/browser/log_router.h" | 27 #include "components/password_manager/core/browser/log_router.h" |
28 #include "components/password_manager/core/browser/password_manager_internals_se
rvice.h" | 28 #include "components/password_manager/core/browser/password_manager_internals_se
rvice.h" |
29 #include "components/password_manager/core/common/credential_manager_types.h" | 29 #include "components/password_manager/core/common/credential_manager_types.h" |
| 30 #include "components/password_manager/core/common/password_manager_features.h" |
30 #include "components/password_manager/core/common/password_manager_pref_names.h" | 31 #include "components/password_manager/core/common/password_manager_pref_names.h" |
31 #include "components/password_manager/core/common/password_manager_switches.h" | 32 #include "components/password_manager/core/common/password_manager_switches.h" |
32 #include "components/syncable_prefs/testing_pref_service_syncable.h" | 33 #include "components/syncable_prefs/testing_pref_service_syncable.h" |
33 #include "components/version_info/version_info.h" | 34 #include "components/version_info/version_info.h" |
34 #include "content/public/browser/browser_context.h" | 35 #include "content/public/browser/browser_context.h" |
35 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
36 #include "content/public/test/mock_render_process_host.h" | 37 #include "content/public/test/mock_render_process_host.h" |
37 #include "testing/gmock/include/gmock/gmock.h" | 38 #include "testing/gmock/include/gmock/gmock.h" |
38 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
39 | 40 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 EXPECT_FALSE(logging_active); | 157 EXPECT_FALSE(logging_active); |
157 } | 158 } |
158 | 159 |
159 TEST_F(ChromePasswordManagerClientTest, | 160 TEST_F(ChromePasswordManagerClientTest, |
160 IsAutomaticPasswordSavingEnabledDefaultBehaviourTest) { | 161 IsAutomaticPasswordSavingEnabledDefaultBehaviourTest) { |
161 EXPECT_FALSE(GetClient()->IsAutomaticPasswordSavingEnabled()); | 162 EXPECT_FALSE(GetClient()->IsAutomaticPasswordSavingEnabled()); |
162 } | 163 } |
163 | 164 |
164 TEST_F(ChromePasswordManagerClientTest, | 165 TEST_F(ChromePasswordManagerClientTest, |
165 IsAutomaticPasswordSavingEnabledWhenFlagIsSetTest) { | 166 IsAutomaticPasswordSavingEnabledWhenFlagIsSetTest) { |
166 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 167 // Add the enable-automatic-password-saving feature. |
167 password_manager::switches::kEnableAutomaticPasswordSaving); | 168 base::FeatureList::ClearInstanceForTesting(); |
| 169 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 170 feature_list->InitializeFromCommandLine( |
| 171 password_manager::features::kEnableAutomaticPasswordSaving.name, ""); |
| 172 base::FeatureList::SetInstance(std::move(feature_list)); |
| 173 |
168 if (chrome::GetChannel() == version_info::Channel::UNKNOWN) | 174 if (chrome::GetChannel() == version_info::Channel::UNKNOWN) |
169 EXPECT_TRUE(GetClient()->IsAutomaticPasswordSavingEnabled()); | 175 EXPECT_TRUE(GetClient()->IsAutomaticPasswordSavingEnabled()); |
170 else | 176 else |
171 EXPECT_FALSE(GetClient()->IsAutomaticPasswordSavingEnabled()); | 177 EXPECT_FALSE(GetClient()->IsAutomaticPasswordSavingEnabled()); |
172 } | 178 } |
173 | 179 |
174 TEST_F(ChromePasswordManagerClientTest, GetPasswordSyncState) { | 180 TEST_F(ChromePasswordManagerClientTest, GetPasswordSyncState) { |
175 ChromePasswordManagerClient* client = GetClient(); | 181 ChromePasswordManagerClient* client = GetClient(); |
176 | 182 |
177 ProfileSyncServiceMock* mock_sync_service = | 183 ProfileSyncServiceMock* mock_sync_service = |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile()); | 344 PasswordManagerInternalsServiceFactory::GetForBrowserContext(profile()); |
339 DummyLogReceiver log_receiver; | 345 DummyLogReceiver log_receiver; |
340 EXPECT_EQ(std::string(), log_router->RegisterReceiver(&log_receiver)); | 346 EXPECT_EQ(std::string(), log_router->RegisterReceiver(&log_receiver)); |
341 | 347 |
342 // But then navigate to a WebUI, there the logging should not be active. | 348 // But then navigate to a WebUI, there the logging should not be active. |
343 NavigateAndCommit(GURL("about:password-manager-internals")); | 349 NavigateAndCommit(GURL("about:password-manager-internals")); |
344 EXPECT_FALSE(GetClient()->GetLogManager()->IsLoggingActive()); | 350 EXPECT_FALSE(GetClient()->GetLogManager()->IsLoggingActive()); |
345 | 351 |
346 log_router->UnregisterReceiver(&log_receiver); | 352 log_router->UnregisterReceiver(&log_receiver); |
347 } | 353 } |
OLD | NEW |