1 /*
2  * Copyright (C) 2019 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.google.common.truth.Truth.assertThat;
20 
21 import android.content.Context;
22 import android.text.method.MovementMethod;
23 import android.view.LayoutInflater;
24 import android.view.View;
25 import android.widget.TextView;
26 
27 import androidx.preference.PreferenceViewHolder;
28 
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.robolectric.RobolectricTestRunner;
33 import org.robolectric.RuntimeEnvironment;
34 
35 /** Tests for {@link AccessibilityFooterPreference} */
36 @RunWith(RobolectricTestRunner.class)
37 public final class AccessibilityFooterPreferenceTest {
38 
39     private AccessibilityFooterPreference mAccessibilityFooterPreference;
40     private PreferenceViewHolder mPreferenceViewHolder;
41 
42     @Before
setUp()43     public void setUp() {
44         final Context context = RuntimeEnvironment.application;
45         mAccessibilityFooterPreference = new AccessibilityFooterPreference(context);
46 
47         final LayoutInflater inflater = LayoutInflater.from(context);
48         final View view =
49                 inflater.inflate(com.android.settingslib.widget.preference.footer.R.layout.preference_footer, null);
50         mPreferenceViewHolder = PreferenceViewHolder.createInstanceForTests(view);
51     }
52 
53     @Test
onBindViewHolder_LinkDisabledByDefault_notReturnLinkMovement()54     public void onBindViewHolder_LinkDisabledByDefault_notReturnLinkMovement() {
55         mAccessibilityFooterPreference.onBindViewHolder(mPreferenceViewHolder);
56 
57         final TextView summaryView = (TextView) mPreferenceViewHolder.findViewById(
58                 android.R.id.title);
59         assertThat(summaryView.getMovementMethod()).isNull();
60     }
61 
62     @Test
onBindViewHolder_setLinkEnabled_returnLinkMovement()63     public void onBindViewHolder_setLinkEnabled_returnLinkMovement() {
64         mAccessibilityFooterPreference.setLinkEnabled(true);
65 
66         mAccessibilityFooterPreference.onBindViewHolder(mPreferenceViewHolder);
67 
68         final TextView summaryView = (TextView) mPreferenceViewHolder.findViewById(
69                 android.R.id.title);
70         assertThat(summaryView.getMovementMethod()).isInstanceOf(MovementMethod.class);
71     }
72 
73     @Test
onBindViewHolder_setLinkEnabled_expectSummaryViewIsNonFocusable()74     public void onBindViewHolder_setLinkEnabled_expectSummaryViewIsNonFocusable() {
75         mAccessibilityFooterPreference.setLinkEnabled(true);
76 
77         mAccessibilityFooterPreference.onBindViewHolder(mPreferenceViewHolder);
78 
79         final TextView summaryView = (TextView) mPreferenceViewHolder.findViewById(
80                 android.R.id.title);
81         assertThat(summaryView.isFocusable()).isFalse();
82     }
83 }
84