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