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