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 static com.android.settings.ui.testutils.SettingsTestUtils.SETTINGS_PACKAGE; 20 import static com.android.settings.ui.testutils.SettingsTestUtils.TIMEOUT; 21 22 import android.os.RemoteException; 23 import android.platform.test.annotations.Presubmit; 24 import android.provider.Settings; 25 import android.support.test.uiautomator.By; 26 import android.support.test.uiautomator.Direction; 27 import android.support.test.uiautomator.UiDevice; 28 import android.support.test.uiautomator.UiObject2; 29 import android.support.test.uiautomator.Until; 30 import android.system.helpers.SettingsHelper; 31 32 import androidx.test.InstrumentationRegistry; 33 import androidx.test.filters.MediumTest; 34 import androidx.test.runner.AndroidJUnit4; 35 36 import com.android.settings.ui.testutils.SettingsTestUtils; 37 38 import org.junit.After; 39 import org.junit.Before; 40 import org.junit.Test; 41 import org.junit.runner.RunWith; 42 43 @MediumTest 44 @RunWith(AndroidJUnit4.class) 45 public class HomepageDisplayTests { 46 47 private static final String[] HOMEPAGE_ITEMS = { 48 "Network & internet", 49 "Connected devices", 50 "Apps & notifications", 51 "Battery", 52 "Display", 53 "Sound", 54 "Storage", 55 "Security", 56 "Location", 57 "Privacy", 58 "Accounts", 59 "Accessibility", 60 "System" 61 }; 62 63 private UiDevice mDevice; 64 65 @Before setUp()66 public void setUp() throws Exception { 67 mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); 68 try { 69 mDevice.setOrientationNatural(); 70 } catch (RemoteException e) { 71 throw new RuntimeException("failed to freeze device orientaion", e); 72 } 73 } 74 75 @After tearDown()76 public void tearDown() throws Exception { 77 // Need to finish settings activity 78 mDevice.pressHome(); 79 } 80 81 @Presubmit 82 @Test testHomepageCategory()83 public void testHomepageCategory() throws Exception { 84 // Launch Settings 85 SettingsHelper.launchSettingsPage( 86 InstrumentationRegistry.getContext(), Settings.ACTION_SETTINGS); 87 88 // Scroll to top 89 final UiObject2 view = mDevice.wait( 90 Until.findObject(By.res(SETTINGS_PACKAGE, "main_content")), 91 TIMEOUT); 92 view.scroll(Direction.UP, 100f); 93 94 // Inspect each item 95 for (String item : HOMEPAGE_ITEMS) { 96 SettingsTestUtils.assertTitleMatch(mDevice, item); 97 } 98 } 99 } 100