Commit 2a103d18 authored by Rebekah Potter's avatar Rebekah Potter Committed by Commit Bot

Revert "Add MainSettingsFragmentTest"

This reverts commit 8aee0918.

Reason for revert: Test being added is flaky. See
https://bugs.chromium.org/p/chromium/issues/detail?id=1066619

Original change's description:
> Add MainSettingsFragmentTest
> 
> MainSettings.java have bit less test coverage over some of the
> preferences, for example, the HomepageSettings at this moment. Adding
> MainSettingsFragmentTest is aiming for more test coverage for the
> list of preferences on the settings screen.
> 
> Bug: 1052060, 1066362
> Change-Id: Ib51c133f2a73f4ec85cc185c4101833bc3fa0b58
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2124729
> Commit-Queue: Wenyu Fu <wenyufu@chromium.org>
> Reviewed-by: Theresa  <twellington@chromium.org>
> Reviewed-by: Natalie Chouinard <chouinard@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#754957}

TBR=twellington@chromium.org,wychen@chromium.org,chouinard@chromium.org,wenyufu@chromium.org

Change-Id: If15e22de962484fc87b3b5dc5eb1cfcf550cf024
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1052060, 1066362
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2131017Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755115}
parent 2a53ea0e
......@@ -428,7 +428,6 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/searchwidget/SearchActivityTest.java",
"javatests/src/org/chromium/chrome/browser/searchwidget/SearchWidgetProviderTest.java",
"javatests/src/org/chromium/chrome/browser/services/GoogleServicesManagerIntegrationTest.java",
"javatests/src/org/chromium/chrome/browser/settings/MainSettingsFragmentTest.java",
"javatests/src/org/chromium/chrome/browser/settings/SettingsActivityTest.java",
"javatests/src/org/chromium/chrome/browser/settings/homepage/HomepageSettingsFragmentTest.java",
"javatests/src/org/chromium/chrome/browser/settings/homepage/HomepageSettingsFragmentWithEditorTest.java",
......
......@@ -56,6 +56,7 @@ public class MainSettings extends PreferenceFragmentCompat
public static final String PREF_UI_THEME = "ui_theme";
public static final String PREF_DATA_REDUCTION = "data_reduction";
public static final String PREF_NOTIFICATIONS = "notifications";
public static final String PREF_LANGUAGES = "languages";
public static final String PREF_DOWNLOADS = "downloads";
public static final String PREF_DEVELOPER = "developer";
......
......@@ -6,7 +6,6 @@ package org.chromium.chrome.browser.tracing.settings;
import android.os.Bundle;
import androidx.annotation.VisibleForTesting;
import androidx.preference.PreferenceFragmentCompat;
import org.chromium.chrome.R;
......@@ -26,13 +25,9 @@ public class DeveloperSettings extends PreferenceFragmentCompat {
// Non-translated strings:
private static final String MSG_DEVELOPER_OPTIONS_TITLE = "Developer options";
private static Boolean sIsEnabledForTests;
public static boolean shouldShowDeveloperSettings() {
// Always enabled on canary, dev and local builds, otherwise can be enabled by tapping the
// Chrome version in Settings>About multiple times.
if (sIsEnabledForTests != null) return sIsEnabledForTests;
if (VersionConstants.CHANNEL <= Channel.DEV) return true;
return SharedPreferencesManager.getInstance().readBoolean(
ChromePreferenceKeys.SETTINGS_DEVELOPER_ENABLED, false);
......@@ -43,11 +38,6 @@ public class DeveloperSettings extends PreferenceFragmentCompat {
ChromePreferenceKeys.SETTINGS_DEVELOPER_ENABLED, true);
}
@VisibleForTesting
public static void setIsEnabledForTests(Boolean isEnabled) {
sIsEnabledForTests = isEnabled;
}
@Override
public void onCreatePreferences(Bundle savedInstanceState, String s) {
getActivity().setTitle(MSG_DEVELOPER_OPTIONS_TITLE);
......
// Copyright 2020 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;
import android.accounts.Account;
import android.content.Context;
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.rule.ActivityTestRule;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.about_settings.AboutChromeSettings;
import org.chromium.chrome.browser.accessibility.settings.AccessibilitySettings;
import org.chromium.chrome.browser.autofill.settings.AutofillPaymentMethodsFragment;
import org.chromium.chrome.browser.autofill.settings.AutofillProfilesFragment;
import org.chromium.chrome.browser.datareduction.settings.DataReductionPreferenceFragment;
import org.chromium.chrome.browser.download.settings.DownloadSettings;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.homepage.HomepageTestRule;
import org.chromium.chrome.browser.language.settings.LanguageSettings;
import org.chromium.chrome.browser.night_mode.NightModeUtils;
import org.chromium.chrome.browser.night_mode.settings.ThemeSettingsFragment;
import org.chromium.chrome.browser.notifications.settings.NotificationSettings;
import org.chromium.chrome.browser.password_manager.settings.PasswordSettings;
import org.chromium.chrome.browser.privacy.settings.PrivacySettings;
import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory;
import org.chromium.chrome.browser.search_engines.settings.SearchEngineSettings;
import org.chromium.chrome.browser.settings.homepage.HomepageSettings;
import org.chromium.chrome.browser.site_settings.SiteSettings;
import org.chromium.chrome.browser.sync.SyncTestRule;
import org.chromium.chrome.browser.sync.settings.SignInPreference;
import org.chromium.chrome.browser.sync.settings.SignInPreference.State;
import org.chromium.chrome.browser.sync.settings.SyncAndServicesSettings;
import org.chromium.chrome.browser.tracing.settings.DeveloperSettings;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
import org.chromium.components.search_engines.TemplateUrl;
import org.chromium.components.search_engines.TemplateUrlService;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
/**
* Test for {@link MainSettings}. Main purpose is to have a sanity check on the xml.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, "show-autofill-signatures"})
public class MainSettingsFragmentTest {
private static final String SEARCH_ENGINE_SHORT_NAME = "Google";
@Rule
public HomepageTestRule mHomepageTestRule = new HomepageTestRule();
@Rule
public SyncTestRule mSyncTestRule = new SyncTestRule();
@Rule
public ActivityTestRule<SettingsActivity> mSettingsActivityTestRule =
new ActivityTestRule<>(SettingsActivity.class);
@Mock
public TemplateUrlService mMockTemplateUrlService;
@Mock
public TemplateUrl mMockSearchEngine;
private @Nullable TemplateUrlService mActualTemplateUrlService;
private MainSettings mMainSettings;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
DeveloperSettings.setIsEnabledForTests(true);
}
@After
public void tearDown() {
DeveloperSettings.setIsEnabledForTests(null);
if (mActualTemplateUrlService != null) {
// Reset the actual service if the mock is used.
TemplateUrlServiceFactory.setInstanceForTesting(mActualTemplateUrlService);
}
}
private void launchSettingsActivity() {
Context context = InstrumentationRegistry.getInstrumentation().getContext();
Intent intent = SettingsLauncher.getInstance().createIntentForSettingsPage(
context, MainSettings.class.getName());
SettingsActivity activity = mSettingsActivityTestRule.launchActivity(intent);
mMainSettings = (MainSettings) activity.getMainFragment();
Assert.assertNotNull("SettingsActivity failed to launch.", mMainSettings);
}
private void configureMockSearchEngine() {
// Cache the actual Url Service, so the test can put it back after tests.
TestThreadUtils.runOnUiThreadBlocking(
() -> { mActualTemplateUrlService = TemplateUrlServiceFactory.get(); });
TemplateUrlServiceFactory.setInstanceForTesting(mMockTemplateUrlService);
Mockito.doReturn(mMockSearchEngine)
.when(mMockTemplateUrlService)
.getDefaultSearchEngineTemplateUrl();
Mockito.doReturn(SEARCH_ENGINE_SHORT_NAME).when(mMockSearchEngine).getShortName();
}
/**
* Test for the "Account" section.
*/
@Test
@SmallTest
public void testStartup() {
launchSettingsActivity();
// For non-signed-in users, the section contains the generic header.
assertSettingsExists(MainSettings.PREF_SIGN_IN, null);
assertSettingsExists(MainSettings.PREF_SYNC_AND_SERVICES, SyncAndServicesSettings.class);
// SignInPreference status check.
// As the user is not signed in, sign in promo will show, section header will be hidden.
Assert.assertNull("Account section header should be hidden.",
mMainSettings.findPreference(MainSettings.PREF_ACCOUNT_SECTION));
// Assert for "Basics" section
assertSettingsExists(MainSettings.PREF_SEARCH_ENGINE, SearchEngineSettings.class);
assertSettingsExists(MainSettings.PREF_PASSWORDS, PasswordSettings.class);
assertSettingsExists("autofill_payment_methods", AutofillPaymentMethodsFragment.class);
assertSettingsExists("autofill_addresses", AutofillProfilesFragment.class);
assertSettingsExists(MainSettings.PREF_NOTIFICATIONS, NotificationSettings.class);
assertSettingsExists(MainSettings.PREF_HOMEPAGE, HomepageSettings.class);
assertSettingsExists(MainSettings.PREF_UI_THEME, ThemeSettingsFragment.class);
// Verification for summary for the search engine and the homepage
Assert.assertEquals("Homepage summary is different than homepage state",
mMainSettings.getString(R.string.text_on),
mMainSettings.findPreference(MainSettings.PREF_HOMEPAGE).getSummary().toString());
// Assert for advanced section
assertSettingsExists("privacy", PrivacySettings.class);
assertSettingsExists("accessibility", AccessibilitySettings.class);
assertSettingsExists("content_settings", SiteSettings.class);
assertSettingsExists("languages", LanguageSettings.class);
assertSettingsExists(
MainSettings.PREF_DATA_REDUCTION, DataReductionPreferenceFragment.class);
assertSettingsExists(MainSettings.PREF_DOWNLOADS, DownloadSettings.class);
assertSettingsExists(MainSettings.PREF_DEVELOPER, DeveloperSettings.class);
assertSettingsExists("about_chrome", AboutChromeSettings.class);
}
@Test
@SmallTest
public void testHomepageOff() {
mHomepageTestRule.disableHomepageForTest();
launchSettingsActivity();
// Verification for summary for the search engine and the homepage
Assert.assertEquals("Homepage summary is different than homepage state",
mMainSettings.getString(R.string.text_off),
mMainSettings.findPreference(MainSettings.PREF_HOMEPAGE).getSummary().toString());
}
@Test
@SmallTest
public void testSearchEngineDisabled() {
Mockito.doReturn(false).when(mMockTemplateUrlService).isLoaded();
configureMockSearchEngine();
launchSettingsActivity();
Preference searchEngineSettings =
assertSettingsExists(MainSettings.PREF_SEARCH_ENGINE, SearchEngineSettings.class);
// Verification for summary for the search engine and the homepage
Assert.assertFalse("Search Engine preference should be disabled when service is not ready.",
searchEngineSettings.isEnabled());
Assert.assertTrue("Search Engine preference should be disabled when service is not ready.",
TextUtils.isEmpty(searchEngineSettings.getSummary()));
}
/**
* Test when the sign-in preference is the promo. The section header should be hidden.
*/
@Test
@SmallTest
public void testAccountSignIn() throws InterruptedException {
Account account = mSyncTestRule.setUpTestAccountAndSignIn();
mSyncTestRule.signOut();
launchSettingsActivity();
SignInPreference signInPreference =
(SignInPreference) assertSettingsExists(MainSettings.PREF_SIGN_IN, null);
Assert.assertEquals("SignInPreference should be at the personalized promo state. ",
signInPreference.getState(), State.PERSONALIZED_PROMO);
Assert.assertNull("Account section header should be hidden when promo is shown.",
mMainSettings.findPreference(MainSettings.PREF_ACCOUNT_SECTION));
// SignIn to see the changes
mSyncTestRule.signinAndEnableSync(account);
SyncTestUtil.waitForSyncActive();
Assert.assertEquals("SignInPreference should be at the personalized promo state. ",
signInPreference.getState(), State.SIGNED_IN);
Assert.assertNotNull("Account section header should appear when user signed in.",
mMainSettings.findPreference(MainSettings.PREF_ACCOUNT_SECTION));
}
@Test
@SmallTest
public void testRemoveSettings() {
// Disable night mode
NightModeUtils.setNightModeSupportedForTesting(false);
// Disable developer option
DeveloperSettings.setIsEnabledForTests(false);
launchSettingsActivity();
Assert.assertNull("Preference should be disabled: " + MainSettings.PREF_UI_THEME,
mMainSettings.findPreference(MainSettings.PREF_UI_THEME));
Assert.assertNull("Preference should be disabled: " + MainSettings.PREF_DEVELOPER,
mMainSettings.findPreference(MainSettings.PREF_DEVELOPER));
}
/**
* Assert the target preference exists in the main settings and creates the expected fragment,
* then return that preference.
*
* @param prefKey preference key for {@link
* androidx.preference.PreferenceFragmentCompat#findPreference(CharSequence)}
* @param settingsFragmentClass class name that the target preference is holding
* @return the target preference if exists, raise {@link AssertionError} otherwise.
*/
private Preference assertSettingsExists(String prefKey, @Nullable Class settingsFragmentClass) {
Preference pref = mMainSettings.findPreference(prefKey);
Assert.assertNotNull("Preference is missing: " + prefKey, pref);
if (settingsFragmentClass == null) return pref;
try {
Assert.assertNotNull(
"Fragment attached to the preference is null.", pref.getFragment());
Assert.assertEquals("Preference class is different.", settingsFragmentClass,
Class.forName(pref.getFragment()));
} catch (ClassNotFoundException e) {
throw new AssertionError("Pref fragment <" + pref.getFragment() + "> is not found.");
}
return pref;
}
}
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