Commit b1e3e182 authored by Vaclav Brozek's avatar Vaclav Brozek Committed by Commit Bot

Control viewing feature in EG tests through ScopedFeatureList

Currently, the passwords settings EG tests enable the "viewing passwords"
feature through NSDefaults (=experimental flags). Since recently, controlling
through a base::Feature is also possible.

This CL gets rid of the NSDefaults code, which needs to reset the state
manually with a simpler ScopedFeatureList, which limits the boilerplate.

Bug: 744058
Change-Id: I594fb4bbd3f90dd81a1f0f35c7f1ccb70aee965c
Reviewed-on: https://chromium-review.googlesource.com/573023Reviewed-by: default avatarLouis Romero <lpromero@chromium.org>
Commit-Queue: Vaclav Brozek <vabr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487168}
parent c36f566d
...@@ -333,6 +333,7 @@ source_set("eg_tests") { ...@@ -333,6 +333,7 @@ source_set("eg_tests") {
deps = [ deps = [
":settings", ":settings",
"//base", "//base",
"//base/test:test_support",
"//components/autofill/core/common", "//components/autofill/core/common",
"//components/browsing_data/core", "//components/browsing_data/core",
"//components/content_settings/core/browser", "//components/content_settings/core/browser",
......
...@@ -8,10 +8,12 @@ ...@@ -8,10 +8,12 @@
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h" #include "base/time/time.h"
#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_features.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.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"
...@@ -273,29 +275,6 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() { ...@@ -273,29 +275,6 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
[super tearDown]; [super tearDown];
} }
// Restores the experimental flag for viewing passwords.
- (void)passwordsTearDown:(NSString*)oldExperiment {
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:oldExperiment forKey:@"EnableViewCopyPasswords"];
}
// Activates the flag to use the new UI for viewing passwords in settings.
// Also, ensures that original state is restored after the test ends.
- (void)scopedEnablePasswordManagementAndViewingUI {
// Retrieve the experiment setting.
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSString* oldSetting = [defaults stringForKey:@"EnableViewCopyPasswords"];
// Ensure restoring that on tear-down.
__weak PasswordsSettingsTestCase* weakSelf = self;
[self setTearDownHandler:^{
[weakSelf passwordsTearDown:oldSetting];
}];
// Enable viewing passwords in settings.
[defaults setObject:@"Enabled" forKey:@"EnableViewCopyPasswords"];
}
- (scoped_refptr<password_manager::PasswordStore>)passwordStore { - (scoped_refptr<password_manager::PasswordStore>)passwordStore {
// ServiceAccessType governs behaviour in Incognito: only modifications with // ServiceAccessType governs behaviour in Incognito: only modifications with
// EXPLICIT_ACCESS, which correspond to user's explicit gesture, succeed. // EXPLICIT_ACCESS, which correspond to user's explicit gesture, succeed.
...@@ -359,7 +338,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() { ...@@ -359,7 +338,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// passwords), where in settings_egtest.mm the default (old) UI is tested. // passwords), where in settings_egtest.mm the default (old) UI is tested.
// Once the new is the default, just remove the test in settings_egtest.mm. // Once the new is the default, just remove the test in settings_egtest.mm.
- (void)testAccessibilityOnPasswords { - (void)testAccessibilityOnPasswords {
[self scopedEnablePasswordManagementAndViewingUI]; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
password_manager::features::kViewPasswords);
// Saving a form is needed for using the "password details" view. // Saving a form is needed for using the "password details" view.
[self saveExamplePasswordForm]; [self saveExamplePasswordForm];
...@@ -387,7 +368,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() { ...@@ -387,7 +368,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that attempts to copy a password provide appropriate feedback, // Checks that attempts to copy a password provide appropriate feedback,
// both when reauthentication succeeds and when it fails. // both when reauthentication succeeds and when it fails.
- (void)testCopyPasswordToast { - (void)testCopyPasswordToast {
[self scopedEnablePasswordManagementAndViewingUI]; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
password_manager::features::kViewPasswords);
// Saving a form is needed for using the "password details" view. // Saving a form is needed for using the "password details" view.
[self saveExamplePasswordForm]; [self saveExamplePasswordForm];
...@@ -440,7 +423,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() { ...@@ -440,7 +423,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that attempts to copy a username provide appropriate feedback. // Checks that attempts to copy a username provide appropriate feedback.
- (void)testCopyUsernameToast { - (void)testCopyUsernameToast {
[self scopedEnablePasswordManagementAndViewingUI]; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
password_manager::features::kViewPasswords);
// Saving a form is needed for using the "password details" view. // Saving a form is needed for using the "password details" view.
[self saveExamplePasswordForm]; [self saveExamplePasswordForm];
...@@ -474,7 +459,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() { ...@@ -474,7 +459,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that attempts to copy a site URL provide appropriate feedback. // Checks that attempts to copy a site URL provide appropriate feedback.
- (void)testCopySiteToast { - (void)testCopySiteToast {
[self scopedEnablePasswordManagementAndViewingUI]; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
password_manager::features::kViewPasswords);
// Saving a form is needed for using the "password details" view. // Saving a form is needed for using the "password details" view.
[self saveExamplePasswordForm]; [self saveExamplePasswordForm];
...@@ -509,7 +496,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() { ...@@ -509,7 +496,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that deleting a password from password details view goes back to the // Checks that deleting a password from password details view goes back to the
// list-of-passwords view. // list-of-passwords view.
- (void)testDeletion { - (void)testDeletion {
[self scopedEnablePasswordManagementAndViewingUI]; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
password_manager::features::kViewPasswords);
// Save form to be deleted later. // Save form to be deleted later.
[self saveExamplePasswordForm]; [self saveExamplePasswordForm];
...@@ -557,7 +546,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() { ...@@ -557,7 +546,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that deleting a password from password details can be cancelled. // Checks that deleting a password from password details can be cancelled.
- (void)testCancelDeletion { - (void)testCancelDeletion {
[self scopedEnablePasswordManagementAndViewingUI]; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
password_manager::features::kViewPasswords);
// Save form to be deleted later. // Save form to be deleted later.
[self saveExamplePasswordForm]; [self saveExamplePasswordForm];
...@@ -606,7 +597,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() { ...@@ -606,7 +597,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that if the list view is in edit mode, then the details password view // Checks that if the list view is in edit mode, then the details password view
// is not accessible on tapping the entries. // is not accessible on tapping the entries.
- (void)testEditMode { - (void)testEditMode {
[self scopedEnablePasswordManagementAndViewingUI]; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
password_manager::features::kViewPasswords);
// Save a form to have something to tap on. // Save a form to have something to tap on.
[self saveExamplePasswordForm]; [self saveExamplePasswordForm];
...@@ -631,7 +624,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() { ...@@ -631,7 +624,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that blacklisted credentials only have the Site section. // Checks that blacklisted credentials only have the Site section.
- (void)testBlacklisted { - (void)testBlacklisted {
[self scopedEnablePasswordManagementAndViewingUI]; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
password_manager::features::kViewPasswords);
PasswordForm blacklisted; PasswordForm blacklisted;
blacklisted.origin = GURL("https://example.com"); blacklisted.origin = GURL("https://example.com");
...@@ -672,7 +667,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() { ...@@ -672,7 +667,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that attempts to copy the site via the context menu item provide an // Checks that attempts to copy the site via the context menu item provide an
// appropriate feedback. // appropriate feedback.
- (void)testCopySiteMenuItem { - (void)testCopySiteMenuItem {
[self scopedEnablePasswordManagementAndViewingUI]; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
password_manager::features::kViewPasswords);
// Saving a form is needed for using the "password details" view. // Saving a form is needed for using the "password details" view.
[self saveExamplePasswordForm]; [self saveExamplePasswordForm];
...@@ -714,7 +711,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() { ...@@ -714,7 +711,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that attempts to copy the username via the context menu item provide // Checks that attempts to copy the username via the context menu item provide
// an appropriate feedback. // an appropriate feedback.
- (void)testCopyUsernameMenuItem { - (void)testCopyUsernameMenuItem {
[self scopedEnablePasswordManagementAndViewingUI]; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
password_manager::features::kViewPasswords);
// Saving a form is needed for using the "password details" view. // Saving a form is needed for using the "password details" view.
[self saveExamplePasswordForm]; [self saveExamplePasswordForm];
...@@ -757,7 +756,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() { ...@@ -757,7 +756,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that attempts to copy the password via the context menu item provide // Checks that attempts to copy the password via the context menu item provide
// an appropriate feedback. // an appropriate feedback.
- (void)testCopyPasswordMenuItem { - (void)testCopyPasswordMenuItem {
[self scopedEnablePasswordManagementAndViewingUI]; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
password_manager::features::kViewPasswords);
// Saving a form is needed for using the "password details" view. // Saving a form is needed for using the "password details" view.
[self saveExamplePasswordForm]; [self saveExamplePasswordForm];
...@@ -807,7 +808,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() { ...@@ -807,7 +808,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that attempts to show and hide the password via the context menu item // Checks that attempts to show and hide the password via the context menu item
// provide an appropriate feedback. // provide an appropriate feedback.
- (void)testShowHidePasswordMenuItem { - (void)testShowHidePasswordMenuItem {
[self scopedEnablePasswordManagementAndViewingUI]; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
password_manager::features::kViewPasswords);
// Saving a form is needed for using the "password details" view. // Saving a form is needed for using the "password details" view.
[self saveExamplePasswordForm]; [self saveExamplePasswordForm];
...@@ -874,7 +877,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() { ...@@ -874,7 +877,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that federated credentials have no password but show the federation. // Checks that federated credentials have no password but show the federation.
- (void)testFederated { - (void)testFederated {
[self scopedEnablePasswordManagementAndViewingUI]; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
password_manager::features::kViewPasswords);
PasswordForm federated; PasswordForm federated;
federated.username_value = base::ASCIIToUTF16("federated username"); federated.username_value = base::ASCIIToUTF16("federated username");
......
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