Home | History | Annotate | Download | only in cts
      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 android.preference2.cts;
     18 
     19 import android.content.Intent;
     20 import android.support.test.InstrumentationRegistry;
     21 import android.support.test.filters.LargeTest;
     22 import android.support.test.rule.ActivityTestRule;
     23 import android.support.test.runner.AndroidJUnit4;
     24 
     25 import org.junit.Before;
     26 import org.junit.Rule;
     27 import org.junit.Test;
     28 import org.junit.runner.RunWith;
     29 
     30 /**
     31  * Landscape tests setup for {@link PreferenceActivityFlowTest}
     32  */
     33 @LargeTest
     34 @RunWith(AndroidJUnit4.class)
     35 public class PreferenceActivityFlowLandscapeTest extends PreferenceActivityFlowTest {
     36 
     37     @Rule
     38     public ActivityTestRule<PreferenceWithHeadersLandscape> mActivityRule =
     39             new ActivityTestRule<>(PreferenceWithHeadersLandscape.class, true, false);
     40 
     41     @Before
     42     public void setup() {
     43         mTestUtils = new TestUtils();
     44     }
     45 
     46     /**
     47      * Landscape setup of {@link #switchHeadersInner}.
     48      */
     49     @Test
     50     public void switchHeadersLandscapeTest() {
     51         switchHeadersInner();
     52     }
     53 
     54     /**
     55      * Landscape setup of {@link #smallScreenNoHighlightInHeadersListInner}.
     56      */
     57     @Test
     58     public void smallScreenNoHighlightInHeadersListTest() {
     59         smallScreenNoHighlightInHeadersListInner();
     60     }
     61 
     62     /**
     63      * Landscape setup of {@link #backPressToExitInner}.
     64      */
     65     @Test
     66     public void backPressToExitLandscapeTest() {
     67         backPressToExitInner();
     68     }
     69 
     70     /**
     71      * Landscape setup of {@link #goToFragmentInner}.
     72      */
     73     @Test
     74     public void goToFragmentLandscapeTest() {
     75         goToFragmentInner();
     76     }
     77 
     78     /**
     79      * Landscape setup of {@link #startWithFragmentInner}.
     80      */
     81     @Test
     82     public void startWithFragmentLandscapeTest() {
     83         startWithFragmentInner();
     84     }
     85 
     86     /**
     87      * Landscape setup of {@link #startWithFragmentAndRecreateInner}.
     88      */
     89     @Test
     90     public void startWithFragmentAndRecreateLandscapeTest() {
     91         startWithFragmentAndRecreateInner();
     92     }
     93 
     94 
     95     /**
     96      * Landscape setup of {@link #startWithFragmentAndInitTitleInner}.
     97      */
     98     @Test
     99     public void startWithFragmentAndInitTitleLandscapeTest() {
    100         startWithFragmentAndInitTitleInner();
    101     }
    102 
    103     /**
    104      * Landscape setup of {@link #startWithFragmentAndInitTitleMultiWindowInner}.
    105      */
    106     @Test
    107     public void startWithFragmentAndInitTitleMultiWindowLandscapeTest() {
    108         startWithFragmentAndInitTitleMultiWindowInner();
    109     }
    110 
    111     /**
    112      * Landscape setup of {@link #startWithFragmentNoHeadersInner}.
    113      */
    114     @Test
    115     public void startWithFragmentNoHeadersLandscapeTest() {
    116         startWithFragmentNoHeadersInner();
    117     }
    118 
    119     /**
    120      * Landscape setup of {@link #startWithFragmentNoHeadersButInitTitleInner}.
    121      */
    122     @Test
    123     public void startWithFragmentNoHeadersButInitTitleLandscapeTest() {
    124         startWithFragmentNoHeadersButInitTitleInner();
    125     }
    126 
    127     /**
    128      * Landscape setup of {@link #startWithFragmentNoHeadersMultiWindowTest}.
    129      */
    130     @Test
    131     public void startWithFragmentNoHeadersMultiWindowLandscapeTest() {
    132         startWithFragmentNoHeadersMultiWindowTest();
    133     }
    134 
    135     /**
    136      * Landscape setup of {@link #listDialogTest}.
    137      */
    138     @Test
    139     public void listDialogLandscapeTest() {
    140         listDialogTest();
    141     }
    142 
    143     /**
    144      * Landscape setup of {@link #recreateTest}.
    145      */
    146     @Test
    147     public void recreateLandscapeTest() {
    148         recreateTest();
    149     }
    150 
    151     /**
    152      * Landscape setup of {@link #recreateInnerFragmentTest}.
    153      */
    154     @Test
    155     public void recreateInnerFragmentLandscapeTest() {
    156         recreateInnerFragmentTest();
    157     }
    158 
    159     /**
    160      * Landscape setup of {@link #multiWindowInOutTest}.
    161      */
    162     @Test
    163     public void multiWindowInOutLandscapeTest() {
    164         multiWindowInOutTest();
    165     }
    166 
    167     /**
    168      * Landscape setup of {@link #multiWindowInnerFragmentInOutTest}.
    169      */
    170     @Test
    171     public void multiWindowInnerFragmentInOutLandscapeTest() {
    172         multiWindowInnerFragmentInOutTest();
    173     }
    174 
    175     /**
    176      * Landscape setup of {@link #multiWindowInitialHeaderOnBackTest}.
    177      */
    178     @Test
    179     public void multiWindowInitialHeaderOnBackLandscapeTest() {
    180         multiWindowInitialHeaderOnBackTest();
    181     }
    182 
    183     /**
    184      * Landscape setup of {@link #multiWindowHistoryPreserveTest}.
    185      */
    186     @Test
    187     public void multiWindowHistoryPreserveLandscapeTest() {
    188         multiWindowHistoryPreserveTest();
    189     }
    190 
    191     @Override
    192     protected PreferenceWithHeaders launchActivity(Intent intent) {
    193         if (intent != null) {
    194             intent.setClass(InstrumentationRegistry.getTargetContext(),
    195                     PreferenceWithHeadersLandscape.class);
    196         }
    197         return mActivityRule.launchActivity(intent);
    198     }
    199 
    200     @Override
    201     protected void runOnUiThread(final Runnable runnable) {
    202         try {
    203             mActivityRule.runOnUiThread(() -> {
    204                 runnable.run();
    205             });
    206         } catch (Throwable ex) {
    207             throw new RuntimeException("Failure on the UI thread", ex);
    208         }
    209     }
    210 
    211 }
    212