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 com.android.settings.core.InstrumentedPreferenceFragment; 33 import com.android.settings.core.SubSettingLauncher; 34 35 import org.junit.Before; 36 import org.junit.BeforeClass; 37 import org.junit.Rule; 38 import org.junit.Test; 39 import org.junit.runner.RunWith; 40 41 @RunWith(AndroidJUnit4.class) 42 public class ToggleFeaturePreferenceFragmentTest { 43 private static final String SUMMARY_TEXT = "Here's some summary text"; 44 45 @Rule 46 public final ActivityTestRule<AccessibilitySettingsActivity> mActivityRule = 47 new ActivityTestRule<>(AccessibilitySettingsActivity.class, true); 48 49 private final Instrumentation mInstrumentation = InstrumentationRegistry.getInstrumentation(); 50 51 @BeforeClass 52 public static void oneTimeSetup() { 53 if (Looper.myLooper() == null) { 54 Looper.prepare(); 55 } 56 } 57 58 @Before 59 public void setUp() { 60 mInstrumentation.runOnMainSync(() -> { 61 MyToggleFeaturePreferenceFragment fragment = new MyToggleFeaturePreferenceFragment(); 62 Bundle args = new Bundle(); 63 args.putString(AccessibilitySettings.EXTRA_SUMMARY, SUMMARY_TEXT); 64 fragment.setArguments(args); 65 new SubSettingLauncher(mActivityRule.getActivity()) 66 .setDestination(MyToggleFeaturePreferenceFragment.class.getName()) 67 .setArguments(args) 68 .setSourceMetricsCategory( 69 InstrumentedPreferenceFragment.METRICS_CATEGORY_UNKNOWN) 70 .launch(); 71 }); 72 } 73 74 @Test 75 public void testSummaryTestDisplayed() { 76 onView(withText(SUMMARY_TEXT)).check(matches(isDisplayed())); 77 } 78 79 public static class MyToggleFeaturePreferenceFragment extends ToggleFeaturePreferenceFragment { 80 @Override 81 protected void onPreferenceToggled(String preferenceKey, boolean enabled) { 82 } 83 84 @Override 85 public int getMetricsCategory() { 86 return 0; 87 } 88 } 89 }