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") {
deps = [
":settings",
"//base",
"//base/test:test_support",
"//components/autofill/core/common",
"//components/browsing_data/core",
"//components/content_settings/core/browser",
......
......@@ -8,10 +8,12 @@
#include "base/mac/foundation_util.h"
#include "base/memory/ref_counted.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "components/autofill/core/common/password_form.h"
#include "components/keyed_service/core/service_access_type.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 "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h"
#import "ios/chrome/browser/ui/settings/password_details_collection_view_controller_for_testing.h"
......@@ -273,29 +275,6 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
[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 {
// ServiceAccessType governs behaviour in Incognito: only modifications with
// EXPLICIT_ACCESS, which correspond to user's explicit gesture, succeed.
......@@ -359,7 +338,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// 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.
- (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.
[self saveExamplePasswordForm];
......@@ -387,7 +368,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that attempts to copy a password provide appropriate feedback,
// both when reauthentication succeeds and when it fails.
- (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.
[self saveExamplePasswordForm];
......@@ -440,7 +423,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that attempts to copy a username provide appropriate feedback.
- (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.
[self saveExamplePasswordForm];
......@@ -474,7 +459,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that attempts to copy a site URL provide appropriate feedback.
- (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.
[self saveExamplePasswordForm];
......@@ -509,7 +496,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that deleting a password from password details view goes back to the
// list-of-passwords view.
- (void)testDeletion {
[self scopedEnablePasswordManagementAndViewingUI];
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
password_manager::features::kViewPasswords);
// Save form to be deleted later.
[self saveExamplePasswordForm];
......@@ -557,7 +546,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that deleting a password from password details can be cancelled.
- (void)testCancelDeletion {
[self scopedEnablePasswordManagementAndViewingUI];
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
password_manager::features::kViewPasswords);
// Save form to be deleted later.
[self saveExamplePasswordForm];
......@@ -606,7 +597,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that if the list view is in edit mode, then the details password view
// is not accessible on tapping the entries.
- (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.
[self saveExamplePasswordForm];
......@@ -631,7 +624,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that blacklisted credentials only have the Site section.
- (void)testBlacklisted {
[self scopedEnablePasswordManagementAndViewingUI];
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
password_manager::features::kViewPasswords);
PasswordForm blacklisted;
blacklisted.origin = GURL("https://example.com");
......@@ -672,7 +667,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that attempts to copy the site via the context menu item provide an
// appropriate feedback.
- (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.
[self saveExamplePasswordForm];
......@@ -714,7 +711,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that attempts to copy the username via the context menu item provide
// an appropriate feedback.
- (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.
[self saveExamplePasswordForm];
......@@ -757,7 +756,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that attempts to copy the password via the context menu item provide
// an appropriate feedback.
- (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.
[self saveExamplePasswordForm];
......@@ -807,7 +808,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that attempts to show and hide the password via the context menu item
// provide an appropriate feedback.
- (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.
[self saveExamplePasswordForm];
......@@ -874,7 +877,9 @@ MockReauthenticationModule* SetUpAndReturnMockReauthenticationModule() {
// Checks that federated credentials have no password but show the federation.
- (void)testFederated {
[self scopedEnablePasswordManagementAndViewingUI];
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
password_manager::features::kViewPasswords);
PasswordForm federated;
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