Home | History | Annotate | Download | only in accessibility
      1 /*
      2  * Copyright (C) 2017 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 android.support.test.espresso.Espresso.onView;
     20 import static android.support.test.espresso.assertion.ViewAssertions.matches;
     21 import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
     22 import static android.support.test.espresso.matcher.ViewMatchers.withText;
     23 
     24 import android.app.Instrumentation;
     25 import android.os.Bundle;
     26 import android.os.Looper;
     27 import android.support.test.InstrumentationRegistry;
     28 import android.support.test.rule.ActivityTestRule;
     29 import android.support.test.runner.AndroidJUnit4;
     30 
     31 import com.android.settings.Settings.AccessibilitySettingsActivity;
     32 import org.junit.Before;
     33 import org.junit.BeforeClass;
     34 import org.junit.Rule;
     35 import org.junit.Test;
     36 import org.junit.runner.RunWith;
     37 
     38 @RunWith(AndroidJUnit4.class)
     39 public class ToggleFeaturePreferenceFragmentTest {
     40     private static final String SUMMARY_TEXT = "Here's some summary text";
     41 
     42     @Rule
     43     public final ActivityTestRule<AccessibilitySettingsActivity> mActivityRule =
     44             new ActivityTestRule<>(AccessibilitySettingsActivity.class, true);
     45 
     46     private final Instrumentation mInstrumentation = InstrumentationRegistry.getInstrumentation();
     47 
     48     @BeforeClass
     49     public static void oneTimeSetup() {
     50         if (Looper.myLooper() == null) {
     51             Looper.prepare();
     52         }
     53     }
     54 
     55     @Before
     56     public void setUp() {
     57         mInstrumentation.runOnMainSync(() -> {
     58             MyToggleFeaturePreferenceFragment fragment = new MyToggleFeaturePreferenceFragment();
     59             Bundle args = new Bundle();
     60             args.putString(AccessibilitySettings.EXTRA_SUMMARY, SUMMARY_TEXT);
     61             fragment.setArguments(args);
     62             mActivityRule.getActivity().startPreferenceFragment(fragment, false);
     63         });
     64     }
     65 
     66     @Test
     67     public void testSummaryTestDisplayed() {
     68         onView(withText(SUMMARY_TEXT)).check(matches(isDisplayed()));
     69     }
     70 
     71     public static class MyToggleFeaturePreferenceFragment extends ToggleFeaturePreferenceFragment {
     72         @Override
     73         protected void onPreferenceToggled(String preferenceKey, boolean enabled) {}
     74 
     75         @Override
     76         public int getMetricsCategory() {
     77             return 0;
     78         }
     79     }
     80 }