Commit 60f45119 authored by Luca Hunkeler's avatar Luca Hunkeler Committed by Commit Bot

[Autofill Assistant] Move autofill assistant pref to sync prefs

Print screen:
https://screenshot.googleplex.com/xnR0bvVCEhQ

Bug: b/146145185
Change-Id: I44c5c87906d6f2755a6bd0c3370f0306c5b0d6c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1969344Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarNatalie Chouinard <chouinard@chromium.org>
Reviewed-by: default avatarMathias Carlen <mcarlen@chromium.org>
Commit-Queue: Luca Hunkeler <hluca@google.com>
Cr-Commit-Position: refs/heads/master@{#729724}
parent 541c3be3
......@@ -1394,7 +1394,6 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/settings/autofill/AutofillServerCardEditor.java",
"java/src/org/chromium/chrome/browser/settings/autofill/AutofillServerProfileFragment.java",
"java/src/org/chromium/chrome/browser/settings/autofill/CreditCardNumberFormattingTextWatcher.java",
"java/src/org/chromium/chrome/browser/settings/autofill_assistant/AutofillAssistantSettings.java",
"java/src/org/chromium/chrome/browser/settings/datareduction/DataReductionDataUseItem.java",
"java/src/org/chromium/chrome/browser/settings/datareduction/DataReductionPreferenceFragment.java",
"java/src/org/chromium/chrome/browser/settings/datareduction/DataReductionSiteBreakdownView.java",
......
......@@ -411,7 +411,6 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/settings/accessibility/AccessibilitySettingsTest.java",
"javatests/src/org/chromium/chrome/browser/settings/autofill/AutofillProfilesFragmentTest.java",
"javatests/src/org/chromium/chrome/browser/settings/autofill/AutofillTestRule.java",
"javatests/src/org/chromium/chrome/browser/settings/autofill_assistant/AutofillAssistantSettingsTest.java",
"javatests/src/org/chromium/chrome/browser/settings/datareduction/DataReductionStatsPreferenceTest.java",
"javatests/src/org/chromium/chrome/browser/settings/developer/TracingSettingsTest.java",
"javatests/src/org/chromium/chrome/browser/settings/notifications/NotificationsSettingsTest.java",
......
......@@ -16,7 +16,7 @@ import org.chromium.chrome.autofill_assistant.R;
import org.chromium.chrome.browser.autofill_assistant.carousel.AssistantChip;
import org.chromium.chrome.browser.autofill_assistant.carousel.AssistantChipViewHolder;
import org.chromium.chrome.browser.settings.SettingsLauncher;
import org.chromium.chrome.browser.settings.autofill_assistant.AutofillAssistantSettings;
import org.chromium.chrome.browser.settings.sync.SyncAndServicesPreferences;
import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
......@@ -142,7 +142,7 @@ class AssistantHeaderViewBinder
int itemId = item.getItemId();
if (itemId == R.id.settings) {
SettingsLauncher.launchSettingsPage(
view.mHeader.getContext(), AutofillAssistantSettings.class);
view.mHeader.getContext(), SyncAndServicesPreferences.class);
return true;
} else if (itemId == R.id.send_feedback) {
if (feedbackCallback != null) {
......
......@@ -7,9 +7,10 @@ package org.chromium.chrome.browser.autofill_assistant;
import androidx.annotation.VisibleForTesting;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.browser.settings.autofill_assistant.AutofillAssistantSettings;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
/** Autofill Assistant related preferences util class. */
@SuppressWarnings("UseSharedPreferencesManagerFromChromeCheck")
class AutofillAssistantPreferencesUtil {
// Avoid instatiation by accident.
private AutofillAssistantPreferencesUtil() {}
......@@ -26,7 +27,7 @@ class AutofillAssistantPreferencesUtil {
/** Checks whether the Autofill Assistant switch preference in settings is on. */
static boolean isAutofillAssistantSwitchOn() {
return ContextUtils.getAppSharedPreferences().getBoolean(
AutofillAssistantSettings.PREF_AUTOFILL_ASSISTANT_SWITCH, true);
ChromePreferenceKeys.AUTOFILL_ASSISTANT_ENABLED, true);
}
/** Checks whether the Autofill Assistant onboarding has been accepted. */
......@@ -53,7 +54,7 @@ class AutofillAssistantPreferencesUtil {
static void setInitialPreferences(boolean accept) {
ContextUtils.getAppSharedPreferences()
.edit()
.putBoolean(AutofillAssistantSettings.PREF_AUTOFILL_ASSISTANT_SWITCH, accept)
.putBoolean(ChromePreferenceKeys.AUTOFILL_ASSISTANT_ENABLED, accept)
.apply();
ContextUtils.getAppSharedPreferences()
.edit()
......
......@@ -45,70 +45,65 @@
android:key="autofill_addresses"
android:order="7"
android:title="@string/autofill_addresses_settings_title"/>
<org.chromium.chrome.browser.settings.ChromeBasePreference
android:fragment="org.chromium.chrome.browser.settings.autofill_assistant.AutofillAssistantSettings"
android:key="autofill_assistant"
android:order="8"
android:title="@string/prefs_autofill_assistant_title"/>
<Preference
android:fragment="org.chromium.chrome.browser.settings.notifications.NotificationsSettings"
android:key="notifications"
android:order="9"
android:order="8"
android:title="@string/prefs_notifications"/>
<Preference
android:fragment="org.chromium.chrome.browser.settings.homepage.HomepageSettings"
android:key="homepage"
android:order="10"
android:order="9"
android:title="@string/options_homepage_title"/>
<Preference
android:fragment="org.chromium.chrome.browser.settings.themes.ThemeSettingsFragment"
android:key="ui_theme"
android:order="11"
android:order="10"
android:title="@string/theme_settings" />
<PreferenceCategory
android:key="advanced_section"
android:order="12"
android:order="11"
android:title="@string/prefs_section_advanced"/>
<Preference
android:fragment="org.chromium.chrome.browser.settings.privacy.PrivacySettings"
android:key="privacy"
android:order="13"
android:order="12"
android:title="@string/prefs_privacy"/>
<Preference
android:fragment="org.chromium.chrome.browser.settings.accessibility.AccessibilitySettings"
android:key="accessibility"
android:order="14"
android:order="13"
android:title="@string/prefs_accessibility"/>
<Preference
android:fragment="org.chromium.chrome.browser.settings.website.SiteSettings"
android:key="content_settings"
android:order="15"
android:order="14"
android:title="@string/prefs_site_settings"/>
<Preference
android:fragment="org.chromium.chrome.browser.settings.languages.LanguageSettings"
android:key="languages"
android:order="16"
android:order="15"
android:title="@string/language_settings"/>
<org.chromium.chrome.browser.settings.ChromeBasePreference
android:fragment="org.chromium.chrome.browser.settings.datareduction.DataReductionPreferenceFragment"
android:key="data_reduction"
android:order="17"
android:order="16"
android:title="@string/data_reduction_title_lite_mode"/>
<org.chromium.chrome.browser.settings.ChromeBasePreference
android:fragment="org.chromium.chrome.browser.settings.download.DownloadSettings"
android:key="downloads"
android:order="18"
android:order="17"
android:title="@string/menu_downloads"/>
<Preference
android:fragment="org.chromium.chrome.browser.settings.developer.DeveloperSettings"
android:key="developer"
android:order="19"
android:order="18"
android:title="Developer options"/>
<Preference
android:fragment="org.chromium.chrome.browser.settings.about.AboutChromeSettings"
android:key="about_chrome"
android:order="20"
android:order="19"
android:title="@string/prefs_about_chrome"/>
</PreferenceScreen>
......@@ -79,6 +79,11 @@
android:title="@string/url_keyed_anonymized_data_title"
android:summary="@string/url_keyed_anonymized_data_summary"
android:persistent="false"/>
<org.chromium.chrome.browser.settings.ChromeSwitchPreference
android:key="autofill_assistant"
android:title="@string/prefs_autofill_assistant_title"
android:summary="@string/prefs_autofill_assistant_summary"
android:persistent="false"/>
<org.chromium.chrome.browser.settings.ChromeBasePreference
android:key="contextual_search"
android:title="@string/contextual_search_title"
......
......@@ -26,7 +26,6 @@ import org.chromium.chrome.browser.partnercustomizations.HomepageManager;
import org.chromium.chrome.browser.password_manager.ManagePasswordsReferrer;
import org.chromium.chrome.browser.password_manager.PasswordManagerLauncher;
import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory;
import org.chromium.chrome.browser.settings.autofill_assistant.AutofillAssistantSettings;
import org.chromium.chrome.browser.settings.datareduction.DataReductionPreferenceFragment;
import org.chromium.chrome.browser.settings.developer.DeveloperSettings;
import org.chromium.chrome.browser.settings.sync.SignInPreference;
......@@ -58,7 +57,6 @@ public class MainPreferences extends PreferenceFragmentCompat
public static final String PREF_LANGUAGES = "languages";
public static final String PREF_DOWNLOADS = "downloads";
public static final String PREF_DEVELOPER = "developer";
public static final String PREF_AUTOFILL_ASSISTANT = "autofill_assistant";
public static final String AUTOFILL_GUID = "guid";
// Needs to be in sync with kSettingsOrigin[] in
......@@ -170,14 +168,6 @@ public class MainPreferences extends PreferenceFragmentCompat
if (!ChromeFeatureList.isEnabled(ChromeFeatureList.DOWNLOADS_LOCATION_CHANGE)) {
getPreferenceScreen().removePreference(findPreference(PREF_DOWNLOADS));
}
// This checks whether Autofill Assistant is enabled and was shown at least once (only then
// will the AA switch be assigned a value).
if (!ChromeFeatureList.isEnabled(ChromeFeatureList.AUTOFILL_ASSISTANT)
|| !ContextUtils.getAppSharedPreferences().contains(
AutofillAssistantSettings.PREF_AUTOFILL_ASSISTANT_SWITCH)) {
getPreferenceScreen().removePreference(findPreference(PREF_AUTOFILL_ASSISTANT));
}
}
/**
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.settings.autofill_assistant;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.preference.PreferenceFragmentCompat;
import android.support.v7.preference.PreferenceScreen;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.settings.ChromeSwitchPreference;
/** The "Autofill Assistant" Settings screen. */
public class AutofillAssistantSettings extends PreferenceFragmentCompat {
/** Autofill Assistant switch preference key name. */
public static final String PREF_AUTOFILL_ASSISTANT_SWITCH = "autofill_assistant_switch";
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
getActivity().setTitle(R.string.prefs_autofill_assistant_title);
PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(getStyledContext());
setPreferenceScreen(screen);
createAutofillAssistantSwitch();
}
private void createAutofillAssistantSwitch() {
ChromeSwitchPreference autofillAssistantSwitch =
new ChromeSwitchPreference(getStyledContext(), null);
autofillAssistantSwitch.setKey(PREF_AUTOFILL_ASSISTANT_SWITCH);
autofillAssistantSwitch.setTitle(R.string.prefs_autofill_assistant_switch);
autofillAssistantSwitch.setSummaryOn(R.string.text_on);
autofillAssistantSwitch.setSummaryOff(R.string.text_off);
autofillAssistantSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
ContextUtils.getAppSharedPreferences()
.edit()
.putBoolean(PREF_AUTOFILL_ASSISTANT_SWITCH, (boolean) newValue)
.apply();
return true;
});
getPreferenceScreen().addPreference(autofillAssistantSwitch);
// Note: setting the switch state before the preference is added to the screen results in
// some odd behavior where the switch state doesn't always match the internal enabled state
// (e.g. the switch will say "On" when it is really turned off), so .setChecked() should be
// called after .addPreference()
autofillAssistantSwitch.setChecked(ContextUtils.getAppSharedPreferences().getBoolean(
PREF_AUTOFILL_ASSISTANT_SWITCH, true));
}
private Context getStyledContext() {
return getPreferenceManager().getContext();
}
}
file://components/autofill_assistant/OWNERS
\ No newline at end of file
......@@ -42,8 +42,10 @@ import org.chromium.chrome.browser.contextualsearch.ContextualSearchFieldTrial;
import org.chromium.chrome.browser.contextualsearch.ContextualSearchManager;
import org.chromium.chrome.browser.help.HelpAndFeedback;
import org.chromium.chrome.browser.metrics.UmaSessionStats;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.safe_browsing.SafeBrowsingBridge;
import org.chromium.chrome.browser.settings.ChromeBasePreference;
......@@ -111,6 +113,8 @@ public class SyncAndServicesPreferences extends PreferenceFragmentCompat
private static final String PREF_USAGE_AND_CRASH_REPORTING = "usage_and_crash_reports";
private static final String PREF_URL_KEYED_ANONYMIZED_DATA = "url_keyed_anonymized_data";
private static final String PREF_CONTEXTUAL_SEARCH = "contextual_search";
@VisibleForTesting
public static final String PREF_AUTOFILL_ASSISTANT = "autofill_assistant";
@IntDef({SyncError.NO_ERROR, SyncError.ANDROID_SYNC_DISABLED, SyncError.AUTH_ERROR,
SyncError.PASSPHRASE_REQUIRED, SyncError.CLIENT_OUT_OF_DATE,
......@@ -134,6 +138,8 @@ public class SyncAndServicesPreferences extends PreferenceFragmentCompat
PrivacyPreferencesManager.getInstance();
private final ManagedPreferenceDelegate mManagedPreferenceDelegate =
createManagedPreferenceDelegate();
private final SharedPreferencesManager mSharedPreferencesManager =
SharedPreferencesManager.getInstance();
private boolean mIsFromSigninScreen;
......@@ -153,6 +159,7 @@ public class SyncAndServicesPreferences extends PreferenceFragmentCompat
private ChromeSwitchPreference mSafeBrowsingReporting;
private ChromeSwitchPreference mUsageAndCrashReporting;
private ChromeSwitchPreference mUrlKeyedAnonymizedData;
private @Nullable ChromeSwitchPreference mAutofillAssistant;
private @Nullable Preference mContextualSearch;
private ProfileSyncService.SyncSetupInProgressHandle mSyncSetupInProgressHandle;
......@@ -246,6 +253,15 @@ public class SyncAndServicesPreferences extends PreferenceFragmentCompat
mUrlKeyedAnonymizedData.setOnPreferenceChangeListener(this);
mUrlKeyedAnonymizedData.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
mAutofillAssistant = (ChromeSwitchPreference) findPreference(PREF_AUTOFILL_ASSISTANT);
if (shouldShowAutofillAssistantPreference()) {
mAutofillAssistant.setOnPreferenceChangeListener(this);
mAutofillAssistant.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
} else {
removePreference(servicesCategory, mAutofillAssistant);
mAutofillAssistant = null;
}
mContextualSearch = findPreference(PREF_CONTEXTUAL_SEARCH);
if (!ContextualSearchFieldTrial.isEnabled()) {
removePreference(servicesCategory, mContextualSearch);
......@@ -383,6 +399,8 @@ public class SyncAndServicesPreferences extends PreferenceFragmentCompat
} else if (PREF_URL_KEYED_ANONYMIZED_DATA.equals(key)) {
UnifiedConsentServiceBridge.setUrlKeyedAnonymizedDataCollectionEnabled(
(boolean) newValue);
} else if (PREF_AUTOFILL_ASSISTANT.equals(key)) {
setAutofillAssistantSwitchValue((boolean) newValue);
}
return true;
}
......@@ -610,6 +628,9 @@ public class SyncAndServicesPreferences extends PreferenceFragmentCompat
mUrlKeyedAnonymizedData.setChecked(
UnifiedConsentServiceBridge.isUrlKeyedAnonymizedDataCollectionEnabled());
if (mAutofillAssistant != null) {
mAutofillAssistant.setChecked(isAutofillAssistantSwitchOn());
}
if (mContextualSearch != null) {
boolean isContextualSearchEnabled =
!ContextualSearchManager.isContextualSearchDisabled();
......@@ -783,4 +804,24 @@ public class SyncAndServicesPreferences extends PreferenceFragmentCompat
fragment.cancelSync();
}
}
/**
* This checks whether Autofill Assistant is enabled and was shown at least once (only then
* will the AA switch be assigned a value).
*/
private boolean shouldShowAutofillAssistantPreference() {
return ChromeFeatureList.isEnabled(ChromeFeatureList.AUTOFILL_ASSISTANT)
&& mSharedPreferencesManager.contains(
ChromePreferenceKeys.AUTOFILL_ASSISTANT_ENABLED);
}
public boolean isAutofillAssistantSwitchOn() {
return mSharedPreferencesManager.readBoolean(
ChromePreferenceKeys.AUTOFILL_ASSISTANT_ENABLED, false);
}
public void setAutofillAssistantSwitchValue(boolean newValue) {
mSharedPreferencesManager.writeBoolean(
ChromePreferenceKeys.AUTOFILL_ASSISTANT_ENABLED, newValue);
}
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.settings.autofill_assistant;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.intent.rule.IntentsTestRule;
import android.support.test.filters.SmallTest;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import org.chromium.base.ContextUtils;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.history.HistoryActivity;
import org.chromium.chrome.browser.settings.ChromeSwitchPreference;
import org.chromium.chrome.browser.settings.MainPreferences;
import org.chromium.chrome.browser.settings.SettingsActivity;
import org.chromium.chrome.browser.settings.SettingsActivityTest;
import org.chromium.chrome.test.ChromeBrowserTestRule;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.Features.DisableFeatures;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
/**
* Tests for the "Autofill Assisatnt" settings screen.
*/
@RunWith(BaseJUnit4ClassRunner.class)
public class AutofillAssistantSettingsTest {
@Rule
public final ChromeBrowserTestRule mBrowserTestRule = new ChromeBrowserTestRule();
@Rule
public TestRule mProcessor = new Features.InstrumentationProcessor();
@Rule
public IntentsTestRule<HistoryActivity> mHistoryActivityTestRule =
new IntentsTestRule<>(HistoryActivity.class, false, false);
/**
* Set the |PREF_AUTOFILL_ASSISTANT_SWITCH| shared preference to the given |value|.
* @param value The value to set the preference to.
*/
private void setAutofillAssistantSwitch(boolean value) {
ContextUtils.getAppSharedPreferences()
.edit()
.putBoolean(AutofillAssistantSettings.PREF_AUTOFILL_ASSISTANT_SWITCH, value)
.apply();
}
/**
* Get the |PREF_AUTOFILL_ASSISTANT_SWITCH| shared preference.
* @param defaultValue The default value to use if the preference does not exist.
* @return The value of the shared preference.
*/
private boolean getAutofillAssistantSwitch(boolean defaultValue) {
return ContextUtils.getAppSharedPreferences().getBoolean(
AutofillAssistantSettings.PREF_AUTOFILL_ASSISTANT_SWITCH, defaultValue);
}
/**
* Ensure that the on/off switch in "Autofill Assistant" settings works.
*/
@Test
@SmallTest
@Feature({"Preferences"})
@EnableFeatures(ChromeFeatureList.AUTOFILL_ASSISTANT)
public void testAutofillAssistantSwitch() {
TestThreadUtils.runOnUiThreadBlocking(() -> { setAutofillAssistantSwitch(true); });
final SettingsActivity settingsActivity = SettingsActivityTest.startSettingsActivity(
InstrumentationRegistry.getInstrumentation(),
AutofillAssistantSettings.class.getName());
TestThreadUtils.runOnUiThreadBlocking(() -> {
AutofillAssistantSettings autofillAssistantPrefs =
(AutofillAssistantSettings) settingsActivity.getMainFragment();
ChromeSwitchPreference onOffSwitch =
(ChromeSwitchPreference) autofillAssistantPrefs.findPreference(
AutofillAssistantSettings.PREF_AUTOFILL_ASSISTANT_SWITCH);
Assert.assertTrue(onOffSwitch.isChecked());
onOffSwitch.performClick();
Assert.assertFalse(getAutofillAssistantSwitch(true));
onOffSwitch.performClick();
Assert.assertTrue(getAutofillAssistantSwitch(false));
settingsActivity.finish();
setAutofillAssistantSwitch(false);
});
final SettingsActivity settingsActivity2 = SettingsActivityTest.startSettingsActivity(
InstrumentationRegistry.getInstrumentation(),
AutofillAssistantSettings.class.getName());
TestThreadUtils.runOnUiThreadBlocking(() -> {
AutofillAssistantSettings autofillAssistantPrefs =
(AutofillAssistantSettings) settingsActivity2.getMainFragment();
ChromeSwitchPreference onOffSwitch =
(ChromeSwitchPreference) autofillAssistantPrefs.findPreference(
AutofillAssistantSettings.PREF_AUTOFILL_ASSISTANT_SWITCH);
Assert.assertFalse(onOffSwitch.isChecked());
});
}
/**
* Test: if the onboarding was never shown, the AA chrome preference should not exist.
*
* Note: presence of the |PREF_AUTOFILL_ASSISTANT_SWITCH| shared preference indicates whether
* onboarding was shown or not.
*/
@Test
@SmallTest
@Feature({"Preferences"})
@EnableFeatures(ChromeFeatureList.AUTOFILL_ASSISTANT)
public void testAutofillAssistantNoPreferenceIfOnboardingNeverShown() {
// Note: |PREF_AUTOFILL_ASSISTANT_SWITCH| is cleared in setUp().
final SettingsActivity settingsActivity = SettingsActivityTest.startSettingsActivity(
InstrumentationRegistry.getInstrumentation(), MainPreferences.class.getName());
TestThreadUtils.runOnUiThreadBlocking(() -> {
MainPreferences mainPrefs = (MainPreferences) settingsActivity.getMainFragment();
Assert.assertThat(mainPrefs.findPreference(MainPreferences.PREF_AUTOFILL_ASSISTANT),
is(nullValue()));
});
}
/**
* Test: if the onboarding was shown at least once, the AA chrome preference should also exist.
*
* Note: presence of the |PREF_AUTOFILL_ASSISTANT_SWITCH| shared preference indicates whether
* onboarding was shown or not.
*/
@Test
@SmallTest
@Feature({"Preferences"})
@EnableFeatures(ChromeFeatureList.AUTOFILL_ASSISTANT)
public void testAutofillAssistantPreferenceShownIfOnboardingShown() {
setAutofillAssistantSwitch(false);
final SettingsActivity settingsActivity = SettingsActivityTest.startSettingsActivity(
InstrumentationRegistry.getInstrumentation(), MainPreferences.class.getName());
TestThreadUtils.runOnUiThreadBlocking(() -> {
MainPreferences mainPrefs = (MainPreferences) settingsActivity.getMainFragment();
Assert.assertThat(mainPrefs.findPreference(MainPreferences.PREF_AUTOFILL_ASSISTANT),
is(not(nullValue())));
});
}
/**
* Ensure that the "Autofill Assistant" setting is not shown when the feature is disabled.
*/
@Test
@SmallTest
@Feature({"Preferences"})
@DisableFeatures(ChromeFeatureList.AUTOFILL_ASSISTANT)
public void testAutofillAssistantNoPreferenceIfFeatureDisabled() {
final SettingsActivity settingsActivity = SettingsActivityTest.startSettingsActivity(
InstrumentationRegistry.getInstrumentation(), MainPreferences.class.getName());
TestThreadUtils.runOnUiThreadBlocking(() -> {
MainPreferences mainPrefs = (MainPreferences) settingsActivity.getMainFragment();
Assert.assertThat(mainPrefs.findPreference(MainPreferences.PREF_AUTOFILL_ASSISTANT),
is(nullValue()));
});
}
}
file://components/autofill_assistant/OWNERS
\ No newline at end of file
......@@ -9,6 +9,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.LargeTest;
import android.support.test.filters.SmallTest;
import android.support.test.uiautomator.UiDevice;
import android.support.v4.app.FragmentTransaction;
......@@ -24,13 +25,18 @@ import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.settings.ChromeSwitchPreference;
import org.chromium.chrome.browser.settings.SettingsActivity;
import org.chromium.chrome.browser.settings.SettingsLauncher;
import org.chromium.chrome.browser.settings.sync.SyncAndServicesPreferences;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ApplicationTestUtils;
import org.chromium.chrome.test.util.browser.Features.DisableFeatures;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
import org.chromium.components.sync.AndroidSyncSettings;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
......@@ -256,6 +262,106 @@ public class SyncAndServicesPreferencesTest {
Assert.assertNotNull("Sync error card should be shown", getSyncErrorCard(fragment));
}
/**
* Test: if the onboarding was never shown, the AA chrome preference should not exist.
*
* Note: presence of the {@link SyncAndServicesPreferences.PREF_AUTOFILL_ASSISTANT}
* shared preference indicates whether onboarding was shown or not.
*/
@Test
@LargeTest
@Feature({"Sync"})
@EnableFeatures(ChromeFeatureList.AUTOFILL_ASSISTANT)
public void testAutofillAssistantNoPreferenceIfOnboardingNeverShown() {
final SyncAndServicesPreferences syncPrefs = startSyncAndServicesPreferences();
TestThreadUtils.runOnUiThreadBlocking(() -> {
Assert.assertNull(
syncPrefs.findPreference(SyncAndServicesPreferences.PREF_AUTOFILL_ASSISTANT));
});
}
/**
* Test: if the onboarding was shown at least once, the AA chrome preference should also exist.
*
* Note: presence of the {@link SyncAndServicesPreferences.PREF_AUTOFILL_ASSISTANT}
* shared preference indicates whether onboarding was shown or not.
*/
@Test
@LargeTest
@Feature({"Sync"})
@EnableFeatures(ChromeFeatureList.AUTOFILL_ASSISTANT)
public void testAutofillAssistantPreferenceShownIfOnboardingShown() {
setAutofillAssistantSwitchValue(true);
final SyncAndServicesPreferences syncPrefs = startSyncAndServicesPreferences();
TestThreadUtils.runOnUiThreadBlocking(() -> {
Assert.assertNotNull(
syncPrefs.findPreference(SyncAndServicesPreferences.PREF_AUTOFILL_ASSISTANT));
});
}
/**
* Ensure that the "Autofill Assistant" setting is not shown when the feature is disabled.
*/
@Test
@LargeTest
@Feature({"Sync"})
@DisableFeatures(ChromeFeatureList.AUTOFILL_ASSISTANT)
public void testAutofillAssistantNoPreferenceIfFeatureDisabled() {
setAutofillAssistantSwitchValue(true);
final SyncAndServicesPreferences syncPrefs = startSyncAndServicesPreferences();
TestThreadUtils.runOnUiThreadBlocking(() -> {
Assert.assertNull(
syncPrefs.findPreference(SyncAndServicesPreferences.PREF_AUTOFILL_ASSISTANT));
});
}
/**
* Ensure that the "Autofill Assistant" on/off switch works.
*/
@Test
@LargeTest
@Feature({"Sync"})
@EnableFeatures(ChromeFeatureList.AUTOFILL_ASSISTANT)
public void testAutofillAssistantSwitchOn() {
TestThreadUtils.runOnUiThreadBlocking(() -> { setAutofillAssistantSwitchValue(true); });
final SyncAndServicesPreferences syncAndServicesPreferences =
startSyncAndServicesPreferences();
TestThreadUtils.runOnUiThreadBlocking(() -> {
ChromeSwitchPreference autofillAssistantSwitch =
(ChromeSwitchPreference) syncAndServicesPreferences.findPreference(
SyncAndServicesPreferences.PREF_AUTOFILL_ASSISTANT);
Assert.assertTrue(autofillAssistantSwitch.isChecked());
autofillAssistantSwitch.performClick();
Assert.assertFalse(syncAndServicesPreferences.isAutofillAssistantSwitchOn());
autofillAssistantSwitch.performClick();
Assert.assertTrue(syncAndServicesPreferences.isAutofillAssistantSwitchOn());
});
}
@Test
@LargeTest
@Feature({"Sync"})
@EnableFeatures(ChromeFeatureList.AUTOFILL_ASSISTANT)
public void testAutofillAssistantSwitchOff() {
TestThreadUtils.runOnUiThreadBlocking(() -> { setAutofillAssistantSwitchValue(false); });
final SyncAndServicesPreferences syncAndServicesPreferences =
startSyncAndServicesPreferences();
TestThreadUtils.runOnUiThreadBlocking(() -> {
ChromeSwitchPreference autofillAssistantSwitch =
(ChromeSwitchPreference) syncAndServicesPreferences.findPreference(
SyncAndServicesPreferences.PREF_AUTOFILL_ASSISTANT);
Assert.assertFalse(autofillAssistantSwitch.isChecked());
});
}
private void setAutofillAssistantSwitchValue(boolean newValue) {
SharedPreferencesManager.getInstance().writeBoolean(
ChromePreferenceKeys.AUTOFILL_ASSISTANT_ENABLED, newValue);
}
// TODO(crbug.com/1030725): SyncTestRule should support overriding ProfileSyncService.
private FakeProfileSyncService overrideProfileSyncService() {
return TestThreadUtils.runOnUiThreadBlockingNoException(() -> {
......
......@@ -46,6 +46,9 @@ public final class ChromePreferenceKeys {
*/
public static final String ACCESSIBILITY_TAB_SWITCHER = "accessibility_tab_switcher";
/** Whether Autofill Assistant is enabled */
public static final String AUTOFILL_ASSISTANT_ENABLED = "autofill_assistant_switch";
public static final String BOOKMARKS_LAST_USED_URL = "enhanced_bookmark_last_used_url";
public static final String BOOKMARKS_LAST_USED_PARENT =
"enhanced_bookmark_last_used_parent_folder";
......@@ -569,6 +572,7 @@ public final class ChromePreferenceKeys {
// clang-format off
return Arrays.asList(
ACCESSIBILITY_TAB_SWITCHER,
AUTOFILL_ASSISTANT_ENABLED,
BOOKMARKS_LAST_USED_URL,
BOOKMARKS_LAST_USED_PARENT,
CHROME_DEFAULT_BROWSER,
......
......@@ -3890,6 +3890,9 @@ The site does NOT gain access to the camera. The camera images are only visible
<message name="IDS_PREFS_AUTOFILL_ASSISTANT_SWITCH" desc="Title for the switch toggling whether Autofill Assistant is enabled. [CHAR-LIMIT=32]">
Assistant Triggered Checkout
</message>
<message name="IDS_PREFS_AUTOFILL_ASSISTANT_SUMMARY" desc="Description for the Autofill Assistant toggle.">
To complete tasks on the web via Google Assistant, Chrome sends a site's URL, site content, and relevant personal information to Google
</message>
<!-- Usage Stats strings -->
<message name="IDS_USAGE_STATS_CONSENT_TITLE" desc="Title for activity authorizing Digital Wellbeing to access Chrome usage data">
Show your Chrome activity in Digital Wellbeing?
......
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