1 /* 2 * Copyright (C) 2018 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.ui; 18 19 import android.content.Intent; 20 import android.os.RemoteException; 21 import android.support.test.uiautomator.UiDevice; 22 import android.system.helpers.SettingsHelper; 23 24 import androidx.test.InstrumentationRegistry; 25 import androidx.test.filters.MediumTest; 26 import androidx.test.runner.AndroidJUnit4; 27 28 import com.android.settings.ui.testutils.SettingsTestUtils; 29 30 import org.junit.After; 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 35 @MediumTest 36 @RunWith(AndroidJUnit4.class) 37 public class BatterySettingsUITest { 38 // Items we really want to always show 39 private static final String[] CATEGORIES = new String[] { 40 "Battery Saver", 41 "Battery percentage", 42 "Battery usage data is approximate and can change based on usage", 43 }; 44 45 private UiDevice mDevice; 46 private SettingsHelper mHelper; 47 48 @Before setUp()49 public void setUp() throws Exception { 50 mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); 51 mHelper = SettingsHelper.getInstance(); 52 try { 53 mDevice.setOrientationNatural(); 54 } catch (RemoteException e) { 55 throw new RuntimeException("failed to freeze device orientaion", e); 56 } 57 } 58 59 @After tearDown()60 public void tearDown() throws Exception { 61 // Go back to home for next test. 62 mDevice.pressHome(); 63 } 64 65 @Test launchSecuritySettings()66 public void launchSecuritySettings() throws Exception { 67 // Launch Settings 68 SettingsHelper.launchSettingsPage( 69 InstrumentationRegistry.getTargetContext(), Intent.ACTION_POWER_USAGE_SUMMARY); 70 mHelper.scrollVert(false); 71 for (String category : CATEGORIES) { 72 SettingsTestUtils.assertTitleMatch(mDevice, category); 73 } 74 } 75 } 76