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.os.RemoteException; 26 import android.support.test.InstrumentationRegistry; 27 import android.support.test.filters.FlakyTest; 28 import android.support.test.runner.AndroidJUnit4; 29 import android.support.test.uiautomator.UiDevice; 30 31 import junit.framework.Assert; 32 33 import org.junit.Before; 34 import org.junit.Test; 35 import org.junit.runner.RunWith; 36 37 @RunWith(AndroidJUnit4.class) 38 public class CellBroadcastSettingsTest { 39 private Instrumentation mInstrumentation; 40 private Context mContext; 41 private UiDevice mDevice; 42 43 @Before 44 public void setUp() { 45 mInstrumentation = InstrumentationRegistry.getInstrumentation(); 46 mContext = mInstrumentation.getTargetContext(); 47 mDevice = UiDevice.getInstance(mInstrumentation); 48 } 49 50 @FlakyTest 51 @Test 52 public void testRotate_alertReminderDialogOpen_shouldNotCrash() { 53 try { 54 mDevice.wakeUp(); 55 mDevice.pressMenu(); 56 } catch (RemoteException exception) { 57 Assert.fail("Exception " + exception); 58 } 59 60 mInstrumentation.startActivitySync(createActivityIntent()); 61 62 openAlertReminderDialog(); 63 64 try { 65 mDevice.setOrientationLeft(); 66 mDevice.setOrientationNatural(); 67 mDevice.setOrientationRight(); 68 } catch (Exception e) { 69 Assert.fail("Exception " + e); 70 } 71 } 72 73 private Intent createActivityIntent() { 74 Intent intent = new Intent(mContext, CellBroadcastSettings.class); 75 intent.setPackage("com.android.cellbroadcastreceiver"); 76 intent.setAction("android.intent.action.MAIN"); 77 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 78 return intent; 79 } 80 81 private void openAlertReminderDialog() { 82 onView(withText(mContext.getString(R.string.alert_reminder_interval_title))) 83 .perform(click()); 84 } 85 } 86