1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.accessibility;
18 
19 import static com.android.settings.accessibility.TextReadingPreferenceFragment.EXTRA_LAUNCHED_FROM;
20 import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.ACCESSIBILITY_SETTINGS;
21 import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.UNKNOWN_ENTRY;
22 
23 import static com.google.common.truth.Truth.assertThat;
24 
25 import android.content.Context;
26 
27 import androidx.preference.Preference;
28 import androidx.test.core.app.ApplicationProvider;
29 
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.robolectric.RobolectricTestRunner;
33 
34 /**
35  * Tests for {@link TextReadingFragmentBaseController}.
36  */
37 @RunWith(RobolectricTestRunner.class)
38 public class TextReadingFragmentBaseControllerTest {
39     private static final String FRAGMENT_PREF_KEY = "FRAGMENT_PREF_KEY";
40     private final Context mContext = ApplicationProvider.getApplicationContext();
41 
42     @Test
handlePreferenceClick_getExtraWithA11ySettingsEntryPoint()43     public void handlePreferenceClick_getExtraWithA11ySettingsEntryPoint() {
44         final Preference a11ySettingsPreference = new Preference(mContext);
45         a11ySettingsPreference.setKey(FRAGMENT_PREF_KEY);
46         final TextReadingFragmentBaseController mA11ySettingsFragmentController =
47                 new TextReadingFragmentBaseController(mContext, FRAGMENT_PREF_KEY,
48                         ACCESSIBILITY_SETTINGS);
49 
50         mA11ySettingsFragmentController.handlePreferenceTreeClick(a11ySettingsPreference);
51 
52         assertThat(a11ySettingsPreference.getExtras().getInt(EXTRA_LAUNCHED_FROM,
53                 UNKNOWN_ENTRY)).isEqualTo(ACCESSIBILITY_SETTINGS);
54     }
55 }
56