|
| 1 | +/* Copyright (c) 2025 The Brave Authors. All rights reserved. |
| 2 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | + * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| 4 | + * You can obtain one at https://mozilla.org/MPL/2.0/. */ |
| 5 | + |
| 6 | +package org.chromium.chrome.browser.settings; |
| 7 | + |
| 8 | +import static org.junit.Assert.assertTrue; |
| 9 | + |
| 10 | +import android.os.Looper; |
| 11 | + |
| 12 | +import androidx.annotation.Nullable; |
| 13 | +import androidx.preference.Preference; |
| 14 | +import androidx.test.filters.SmallTest; |
| 15 | + |
| 16 | +import org.junit.After; |
| 17 | +import org.junit.Assert; |
| 18 | +import org.junit.Before; |
| 19 | +import org.junit.Test; |
| 20 | +import org.junit.runner.RunWith; |
| 21 | + |
| 22 | +import org.chromium.base.test.util.DoNotBatch; |
| 23 | +import org.chromium.chrome.browser.tracing.settings.DeveloperSettings; |
| 24 | +import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
| 25 | + |
| 26 | +/** Test for {@link MainSettings}. Main purpose is to have a quick confidence check on the xml. */ |
| 27 | +@RunWith(ChromeJUnit4ClassRunner.class) |
| 28 | +@DoNotBatch(reason = "Tests cannot run batched because they launch a Settings activity.") |
| 29 | +public class BraveMainSettingsFragmentTest { |
| 30 | + private final SettingsActivityTestRule<MainSettings> mSettingsActivityTestRule = |
| 31 | + new SettingsActivityTestRule<>(MainSettings.class); |
| 32 | + private MainSettings mMainSettings; |
| 33 | + |
| 34 | + @Before |
| 35 | + public void setup() { |
| 36 | + Looper.prepare(); |
| 37 | + DeveloperSettings.setIsEnabledForTests(true); |
| 38 | + } |
| 39 | + |
| 40 | + @After |
| 41 | + public void tearDown() {} |
| 42 | + |
| 43 | + private static final String[] sSortedPrefKeys = { |
| 44 | + "features_section", |
| 45 | + "brave_shields_and_privacy", |
| 46 | + "brave_news_v2", |
| 47 | + "brave_wallet", |
| 48 | + "brave_vpn", |
| 49 | + "brave_leo", |
| 50 | + "general_section", |
| 51 | + "brave_search_engines", |
| 52 | + "homepage", |
| 53 | + "passwords", |
| 54 | + "brave_sync_layout", |
| 55 | + "brave_stats", |
| 56 | + "content_settings", |
| 57 | + "brave_downloads", |
| 58 | + "closing_all_tabs_closes_brave", |
| 59 | + "use_custom_tabs", |
| 60 | + "display_section", |
| 61 | + "tabs", |
| 62 | + "media", |
| 63 | + "appearance", |
| 64 | + "background_images", |
| 65 | + "accessibility", |
| 66 | + "brave_languages", |
| 67 | + // Somehow this is the key for Autofill section |
| 68 | + "online_checkout_section", |
| 69 | + "autofill_payment_methods", |
| 70 | + "autofill_addresses", |
| 71 | + "autofill_private_window", |
| 72 | + "support_section", |
| 73 | + "rate_brave", |
| 74 | + "about_section", |
| 75 | + "developer", |
| 76 | + "about_chrome" |
| 77 | + }; |
| 78 | + |
| 79 | + // This test is intended to check the issue where prefs order was wrong |
| 80 | + // when app language was switched to some other than default English, |
| 81 | + // like French. The test infrastructure does not support switching app |
| 82 | + // interface language. So the test may help to catch order violation |
| 83 | + // with English. |
| 84 | + @Test |
| 85 | + @SmallTest |
| 86 | + public void testMainSettingsPrefsOrder() { |
| 87 | + startSettings(); |
| 88 | + |
| 89 | + @Nullable Preference prevPref = null; |
| 90 | + for (int i = 0; i < sSortedPrefKeys.length; ++i) { |
| 91 | + Preference pref = mMainSettings.findPreference(sSortedPrefKeys[i]); |
| 92 | + |
| 93 | + if (prevPref == null) { // Skip first pref. |
| 94 | + prevPref = pref; |
| 95 | + continue; |
| 96 | + } |
| 97 | + assertTrue( |
| 98 | + prevPref.getTitle() + " should precede " + pref.getTitle(), |
| 99 | + pref.getOrder() > prevPref.getOrder()); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + private void startSettings() { |
| 104 | + mSettingsActivityTestRule.startSettingsActivity(); |
| 105 | + mMainSettings = mSettingsActivityTestRule.getFragment(); |
| 106 | + Assert.assertNotNull("SettingsActivity failed to launch.", mMainSettings); |
| 107 | + } |
| 108 | +} |
0 commit comments