Commit 096c1762 authored by Ali Juma's avatar Ali Juma Committed by Commit Bot

[iOS] Make password leak checks toggleable when Safe Browsing is not available

This CL fixes a regression from http://crrev.com/c/2174995
that prevents users who do not yet have Safe Browsing
rolled out to them from toggling the password leak check setting.

This CL ensures that the value of the Safe Browsing opt-out
pref is always initialized in GoogleServicesSettingsMediator,
regardless of whether Safe Browsing has been rolled out. With
this change, the other logic changes in
http://crrev.com/c/2174995 work as expected, whether or not
Safe Browsing is available.

Bug: 1090406
Change-Id: I901f04faad60f136b89161091eeb6504415718a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2237716
Commit-Queue: Ali Juma <ajuma@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#776646}
parent 7f46a6ca
......@@ -104,6 +104,9 @@ source_set("eg_tests") {
":constants",
":test_support",
"//base/test:test_support",
"//components/password_manager/core/common",
"//components/safe_browsing/core:features",
"//components/safe_browsing/core/common:safe_browsing_prefs",
"//ios/chrome/app/strings",
"//ios/chrome/browser/tabs",
"//ios/chrome/browser/ui:feature_flags",
......@@ -177,6 +180,9 @@ source_set("eg2_tests") {
":eg_test_support+eg2",
"//base",
"//base/test:test_support",
"//components/password_manager/core/common",
"//components/safe_browsing/core:features",
"//components/safe_browsing/core/common:safe_browsing_prefs",
"//ios/chrome/app/strings",
"//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/authentication:eg_test_support+eg2",
......
......@@ -16,4 +16,10 @@ extern NSString* const kManageSyncCellAccessibilityIdentifier;
// Accessibility identifier for the account list cell.
extern NSString* const kAccountListItemAccessibilityIdentifier;
// Accessibility identifier for the password leak check cell.
extern NSString* const kPasswordLeakCheckItemAccessibilityIdentifier;
// Accessibility identifier for the Safe Browsing cell.
extern NSString* const kSafeBrowsingItemAccessibilityIdentifier;
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_GOOGLE_SERVICES_GOOGLE_SERVICES_SETTINGS_CONSTANTS_H_
......@@ -16,3 +16,9 @@ NSString* const kManageSyncCellAccessibilityIdentifier =
NSString* const kAccountListItemAccessibilityIdentifier =
@"AccountListItemAccessibilityIdentifier";
NSString* const kPasswordLeakCheckItemAccessibilityIdentifier =
@"PasswordLeakCheckItemAccessibilityIdentifier";
NSString* const kSafeBrowsingItemAccessibilityIdentifier =
@"SafeBrowsingItemAccessibilityIdentifier";
......@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/safe_browsing/core/features.h"
#import "ios/chrome/browser/ui/authentication/signin_earl_grey_ui.h"
#import "ios/chrome/browser/ui/authentication/signin_earlgrey_utils.h"
#import "ios/chrome/browser/ui/settings/google_services/google_services_settings_app_interface.h"
......@@ -9,10 +12,12 @@
#import "ios/chrome/browser/ui/settings/google_services/manage_sync_settings_constants.h"
#include "ios/chrome/grit/ios_chromium_strings.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/earl_grey/chrome_actions.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/testing/earl_grey/app_launch_manager.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#import "ui/base/l10n/l10n_util.h"
......@@ -159,6 +164,128 @@ using chrome_test_util::SettingsDoneButton;
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
}
// Tests that password leak detection can be toggled when Safe Browsing isn't
// available.
- (void)testTogglePasswordLeakCheckWhenSafeBrowsingNotAvailable {
AppLaunchConfiguration config;
config.features_disabled.push_back(
safe_browsing::kSafeBrowsingAvailableOnIOS);
[[AppLaunchManager sharedManager] ensureAppLaunchedWithConfiguration:config];
// Ensure that Safe Browsing and password leak detection opt-outs start in
// their default (opted-in) state.
[ChromeEarlGrey setBoolValue:YES forUserPref:prefs::kSafeBrowsingEnabled];
[ChromeEarlGrey
setBoolValue:YES
forUserPref:password_manager::prefs::kPasswordLeakDetectionEnabled];
// Sign in.
FakeChromeIdentity* fakeIdentity = [SigninEarlGreyUtils fakeIdentity1];
[SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity];
// Open "Google Services" settings.
[self openGoogleServicesSettings];
// Check that the password leak check toggle is enabled, and toggle it off.
[[EarlGrey selectElementWithMatcher:
chrome_test_util::SettingsSwitchCell(
kPasswordLeakCheckItemAccessibilityIdentifier,
/*is_toggled_on=*/YES,
/*enabled=*/YES)]
performAction:chrome_test_util::TurnSettingsSwitchOn(NO)];
// Check the underlying pref value.
GREYAssertFalse(
[ChromeEarlGrey userBooleanPref:password_manager::prefs::
kPasswordLeakDetectionEnabled],
@"Failed to toggle-off password leak checks");
// Toggle it back on.
[[EarlGrey selectElementWithMatcher:
chrome_test_util::SettingsSwitchCell(
kPasswordLeakCheckItemAccessibilityIdentifier,
/*is_toggled_on=*/NO,
/*enabled=*/YES)]
performAction:chrome_test_util::TurnSettingsSwitchOn(YES)];
// Check the underlying pref value.
GREYAssertTrue(
[ChromeEarlGrey userBooleanPref:password_manager::prefs::
kPasswordLeakDetectionEnabled],
@"Failed to toggle-on password leak checks");
}
// Tests that when Safe Browsing is available, password leak detection can only
// be toggled if Safe Browsing is enabled.
- (void)testTogglePasswordLeakCheckWhenSafeBrowsingAvailable {
AppLaunchConfiguration config;
config.features_enabled.push_back(safe_browsing::kSafeBrowsingAvailableOnIOS);
[[AppLaunchManager sharedManager] ensureAppLaunchedWithConfiguration:config];
// Ensure that Safe Browsing and password leak detection opt-outs start in
// their default (opted-in) state.
[ChromeEarlGrey setBoolValue:YES forUserPref:prefs::kSafeBrowsingEnabled];
[ChromeEarlGrey
setBoolValue:YES
forUserPref:password_manager::prefs::kPasswordLeakDetectionEnabled];
// Sign in.
FakeChromeIdentity* fakeIdentity = [SigninEarlGreyUtils fakeIdentity1];
[SigninEarlGreyUI signinWithFakeIdentity:fakeIdentity];
// Open "Google Services" settings.
[self openGoogleServicesSettings];
// Check that Safe Browsing is enabled, and toggle it off.
[[EarlGrey
selectElementWithMatcher:chrome_test_util::SettingsSwitchCell(
kSafeBrowsingItemAccessibilityIdentifier,
/*is_toggled_on=*/YES,
/*enabled=*/YES)]
performAction:chrome_test_util::TurnSettingsSwitchOn(NO)];
// Check that the password leak check toggle is both toggled off and disabled.
[[EarlGrey selectElementWithMatcher:
chrome_test_util::SettingsSwitchCell(
kPasswordLeakCheckItemAccessibilityIdentifier,
/*is_toggled_on=*/NO,
/*enabled=*/NO)] assertWithMatcher:grey_notNil()];
// Toggle Safe Browsing on.
[[EarlGrey
selectElementWithMatcher:chrome_test_util::SettingsSwitchCell(
kSafeBrowsingItemAccessibilityIdentifier,
/*is_toggled_on=*/NO,
/*enabled=*/YES)]
performAction:chrome_test_util::TurnSettingsSwitchOn(YES)];
// Check that the password leak check toggle is enabled, and toggle it off.
[[EarlGrey selectElementWithMatcher:
chrome_test_util::SettingsSwitchCell(
kPasswordLeakCheckItemAccessibilityIdentifier,
/*is_toggled_on=*/YES,
/*enabled=*/YES)]
performAction:chrome_test_util::TurnSettingsSwitchOn(NO)];
// Check the underlying pref value.
GREYAssertFalse(
[ChromeEarlGrey userBooleanPref:password_manager::prefs::
kPasswordLeakDetectionEnabled],
@"Failed to toggle-off password leak checks");
// Toggle password leak check detection back on.
[[EarlGrey selectElementWithMatcher:
chrome_test_util::SettingsSwitchCell(
kPasswordLeakCheckItemAccessibilityIdentifier,
/*is_toggled_on=*/NO,
/*enabled=*/YES)]
performAction:chrome_test_util::TurnSettingsSwitchOn(YES)];
// Check the underlying pref value.
GREYAssertTrue(
[ChromeEarlGrey userBooleanPref:password_manager::prefs::
kPasswordLeakDetectionEnabled],
@"Failed to toggle-on password leak checks");
}
#pragma mark - Helpers
// Opens the Google services settings.
......
......@@ -187,12 +187,10 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
initWithPrefService:userPrefService
prefName:prefs::kSearchSuggestEnabled];
_autocompleteSearchPreference.observer = self;
if (base::FeatureList::IsEnabled(kSafeBrowsingAvailableOnIOS)) {
_safeBrowsingPreference = [[PrefBackedBoolean alloc]
initWithPrefService:userPrefService
prefName:prefs::kSafeBrowsingEnabled];
_safeBrowsingPreference.observer = self;
}
_safeBrowsingPreference = [[PrefBackedBoolean alloc]
initWithPrefService:userPrefService
prefName:prefs::kSafeBrowsingEnabled];
_safeBrowsingPreference.observer = self;
_sendDataUsagePreference = [[PrefBackedBoolean alloc]
initWithPrefService:localPrefService
prefName:metrics::prefs::kMetricsReportingEnabled];
......@@ -599,6 +597,8 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
detailStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_SAFE_BROWSING_DETAIL
dataType:0];
safeBrowsingItem.accessibilityIdentifier =
kSafeBrowsingItemAccessibilityIdentifier;
[items addObject:safeBrowsingItem];
}
[items addObject:self.passwordLeakCheckItem];
......@@ -633,7 +633,7 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
l10n_util::GetNSString(IDS_IOS_LEAK_CHECK_SWITCH);
passwordLeakCheckItem.on = [self passwordLeakCheckItemOnState];
passwordLeakCheckItem.accessibilityIdentifier =
@"passwordLeakCheckItem_switch";
kPasswordLeakCheckItemAccessibilityIdentifier;
passwordLeakCheckItem.enabled = self.isAuthenticated;
_passwordLeakCheckItem = passwordLeakCheckItem;
}
......
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