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.os.RemoteException; 20 import android.provider.Settings; 21 import android.support.test.uiautomator.By; 22 import android.support.test.uiautomator.UiDevice; 23 import android.support.test.uiautomator.Until; 24 import android.system.helpers.SettingsHelper; 25 import android.test.InstrumentationTestCase; 26 import android.test.suitebuilder.annotation.MediumTest; 27 28 public class DataUsageSettingsTests extends InstrumentationTestCase { 29 30 private static final String SETTINGS_PACKAGE = "com.android.settings"; 31 private static final int TIMEOUT = 2000; 32 private UiDevice mDevice; 33 34 @Override setUp()35 public void setUp() throws Exception { 36 super.setUp(); 37 mDevice = UiDevice.getInstance(getInstrumentation()); 38 try { 39 mDevice.setOrientationNatural(); 40 } catch (RemoteException e) { 41 throw new RuntimeException("failed to freeze device orientaion", e); 42 } 43 } 44 45 @Override tearDown()46 protected void tearDown() throws Exception { 47 // Need to finish settings activity 48 mDevice.pressBack(); 49 mDevice.pressHome(); 50 super.tearDown(); 51 } 52 53 @MediumTest testElementsOnDataUsageScreen()54 public void testElementsOnDataUsageScreen() throws Exception { 55 launchDataUsageSettings(); 56 assertNotNull("Data usage element not found", 57 mDevice.wait(Until.findObject(By.text("Usage")), 58 TIMEOUT)); 59 assertNotNull("Data usage bar not found", 60 mDevice.wait(Until.findObject(By.res(SETTINGS_PACKAGE, 61 "color_bar")), TIMEOUT)); 62 assertNotNull("WiFi Data usage element not found", 63 mDevice.wait(Until.findObject(By.text("Wi-Fi data usage")), 64 TIMEOUT)); 65 assertNotNull("Network restrictions element not found", 66 mDevice.wait(Until.findObject(By.text("Network restrictions")), 67 TIMEOUT)); 68 } 69 launchDataUsageSettings()70 public void launchDataUsageSettings() throws Exception { 71 SettingsHelper.launchSettingsPage(getInstrumentation().getContext(), 72 Settings.ACTION_SETTINGS); 73 mDevice.wait(Until 74 .findObject(By.text("Network & Internet")), TIMEOUT) 75 .click(); 76 Thread.sleep(TIMEOUT * 2); 77 assertNotNull("Network & internet screen not loaded", mDevice.wait( 78 Until.findObject(By.text("Data usage")), TIMEOUT)); 79 mDevice.wait(Until 80 .findObject(By.text("Data usage")), TIMEOUT) 81 .click(); 82 } 83 } 84