Commit 8f09df8b authored by Vaclav Brozek's avatar Vaclav Brozek Committed by Commit Bot

Don't try to enable saving password in EG tests

The password settings EG tests currently try to enable saving passwords in
PrefService. This is not necesary, because saving passwords is enabled by
default (see PasswordManager::RegisterProfilePrefs).

It is also harmful, because it:
(1) Won't catch if the default setting being "enabled" regresses, or some other
    tests start failing to clean-up.
(2) Increases the complexity of the code.

Therefore, this CL removes the code which enables the password setting in the
passwords settings EG tests.

Bug: 744058
Change-Id: I315935319cbaacb871ba6214b832c04902afffa9
Reviewed-on: https://chromium-review.googlesource.com/572903Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Vaclav Brozek <vabr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487109}
parent 8e189bf3
...@@ -12,10 +12,7 @@ ...@@ -12,10 +12,7 @@
#include "components/autofill/core/common/password_form.h" #include "components/autofill/core/common/password_form.h"
#include "components/keyed_service/core/service_access_type.h" #include "components/keyed_service/core/service_access_type.h"
#include "components/password_manager/core/browser/password_store.h" #include "components/password_manager/core/browser/password_store.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h" #include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h"
#import "ios/chrome/browser/ui/settings/password_details_collection_view_controller_for_testing.h" #import "ios/chrome/browser/ui/settings/password_details_collection_view_controller_for_testing.h"
#import "ios/chrome/browser/ui/settings/reauthentication_module.h" #import "ios/chrome/browser/ui/settings/reauthentication_module.h"
...@@ -276,32 +273,15 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() { ...@@ -276,32 +273,15 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
[super tearDown]; [super tearDown];
} }
// Return pref for saving passwords back to the passed value and restores the // Restores the experimental flag for viewing passwords.
// experimental flag for viewing passwords. - (void)passwordsTearDown:(NSString*)oldExperiment {
- (void)passwordsTearDown:(BOOL)defaultPasswordManagementSetting
:(NSString*)oldExperiment {
ios::ChromeBrowserState* browserState =
chrome_test_util::GetOriginalBrowserState();
PrefService* preferences = browserState->GetPrefs();
preferences->SetBoolean(
password_manager::prefs::kPasswordManagerSavingEnabled,
defaultPasswordManagementSetting);
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:oldExperiment forKey:@"EnableViewCopyPasswords"]; [defaults setObject:oldExperiment forKey:@"EnableViewCopyPasswords"];
} }
// Sets the preference to allow saving passwords and activates the flag to use // Activates the flag to use the new UI for viewing passwords in settings.
// the new UI for viewing passwords in settings. Also, ensures that original // Also, ensures that original state is restored after the test ends.
// state is restored after the test ends.
- (void)scopedEnablePasswordManagementAndViewingUI { - (void)scopedEnablePasswordManagementAndViewingUI {
// Retrieve the original preference state.
ios::ChromeBrowserState* browserState =
chrome_test_util::GetOriginalBrowserState();
PrefService* preferences = browserState->GetPrefs();
bool defaultPasswordManagerSavingPref = preferences->GetBoolean(
password_manager::prefs::kPasswordManagerSavingEnabled);
// Retrieve the experiment setting. // Retrieve the experiment setting.
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSString* oldSetting = [defaults stringForKey:@"EnableViewCopyPasswords"]; NSString* oldSetting = [defaults stringForKey:@"EnableViewCopyPasswords"];
...@@ -309,13 +289,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() { ...@@ -309,13 +289,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Ensure restoring that on tear-down. // Ensure restoring that on tear-down.
__weak PasswordsSettingsTestCase* weakSelf = self; __weak PasswordsSettingsTestCase* weakSelf = self;
[self setTearDownHandler:^{ [self setTearDownHandler:^{
[weakSelf passwordsTearDown:defaultPasswordManagerSavingPref:oldSetting]; [weakSelf passwordsTearDown:oldSetting];
}]; }];
// Enable saving.
preferences->SetBoolean(
password_manager::prefs::kPasswordManagerSavingEnabled, true);
// Enable viewing passwords in settings. // Enable viewing passwords in settings.
[defaults setObject:@"Enabled" forKey:@"EnableViewCopyPasswords"]; [defaults setObject:@"Enabled" forKey:@"EnableViewCopyPasswords"];
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment