Home | History | Annotate | Download | only in cellbroadcastreceiver
      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 package com.android.cellbroadcastreceiver;
     17 
     18 import static android.support.test.espresso.Espresso.onView;
     19 import static android.support.test.espresso.action.ViewActions.click;
     20 import static android.support.test.espresso.matcher.ViewMatchers.withText;
     21 
     22 import android.app.Instrumentation;
     23 import android.content.Context;
     24 import android.content.Intent;
     25 import android.support.test.InstrumentationRegistry;
     26 import android.support.test.runner.AndroidJUnit4;
     27 import android.support.test.uiautomator.UiDevice;
     28 
     29 import junit.framework.Assert;
     30 
     31 import org.junit.Before;
     32 import org.junit.Test;
     33 import org.junit.runner.RunWith;
     34 
     35 @RunWith(AndroidJUnit4.class)
     36 public class CellBroadcastSettingsTest {
     37     private Instrumentation mInstrumentation;
     38     private Context mContext;
     39     private UiDevice mDevice;
     40 
     41     @Before
     42     public void setUp() {
     43         mInstrumentation = InstrumentationRegistry.getInstrumentation();
     44         mContext = mInstrumentation.getTargetContext();
     45         mDevice = UiDevice.getInstance(mInstrumentation);
     46     }
     47 
     48     @Test
     49     public void testRotate_alertReminderDialogOpen_shouldNotCrash() {
     50         mInstrumentation.startActivitySync(createActivityIntent());
     51 
     52         openAlertReminderDialog();
     53 
     54         try {
     55             mDevice.setOrientationLeft();
     56             mDevice.setOrientationNatural();
     57             mDevice.setOrientationRight();
     58         } catch (Exception e) {
     59             Assert.fail("Exception " + e);
     60         }
     61     }
     62 
     63     private Intent createActivityIntent() {
     64         Intent intent = new Intent(mContext, CellBroadcastSettings.class);
     65         intent.setPackage("com.android.cellbroadcastreceiver");
     66         intent.setAction("android.intent.action.MAIN");
     67         return intent;
     68     }
     69 
     70     private void openAlertReminderDialog() {
     71         onView(withText(mContext.getString(R.string.alert_reminder_interval_title)))
     72                 .perform(click());
     73     }
     74 }
     75