Home | History | Annotate | Download | only in functional
      1 /*
      2  * Copyright (C) 2016 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.notification.functional;
     18 
     19 import android.app.NotificationManager;
     20 import android.content.Context;
     21 import android.os.RemoteException;
     22 import android.support.test.uiautomator.By;
     23 import android.support.test.uiautomator.Direction;
     24 import android.support.test.uiautomator.UiDevice;
     25 import android.support.test.uiautomator.UiObject2;
     26 import android.support.test.uiautomator.Until;
     27 import android.view.KeyEvent;
     28 import android.test.InstrumentationTestCase;
     29 import android.test.suitebuilder.annotation.MediumTest;
     30 import android.view.inputmethod.InputMethodManager;
     31 import android.widget.Toast;
     32 
     33 public class NotificationInlineReplyTests extends InstrumentationTestCase {
     34     private static final int SHORT_TIMEOUT = 200;
     35     private static final int LONG_TIMEOUT = 2000;
     36     private static final int NOTIFICATION_ID = 1;
     37     private static final int NOTIFICATION_ID_2 = 2;
     38     private static final String INLINE_REPLY_TITLE = "INLINE REPLY TITLE";
     39     private static final String KEY_QUICK_REPLY_TEXT = "quick_reply";
     40     private static final String RECEIVER_PKG_NAME = "com.android.systemui";
     41     private NotificationManager mNotificationManager;
     42     private UiDevice mDevice = null;
     43     private Context mContext;
     44     private NotificationHelper mHelper;
     45 
     46     @Override
     47     public void setUp() throws Exception {
     48         super.setUp();
     49         mDevice = UiDevice.getInstance(getInstrumentation());
     50         mContext = getInstrumentation().getContext();
     51         mNotificationManager = (NotificationManager) mContext
     52                 .getSystemService(Context.NOTIFICATION_SERVICE);
     53         mHelper = new NotificationHelper(mDevice, getInstrumentation(), mNotificationManager);
     54         try {
     55             mDevice.setOrientationNatural();
     56         } catch (RemoteException e) {
     57             throw new RuntimeException("failed to freeze device orientaion", e);
     58         }
     59         mDevice.pressHome();
     60         mNotificationManager.cancelAll();
     61     }
     62 
     63     @Override
     64     public void tearDown() throws Exception {
     65         mNotificationManager.cancelAll();
     66         mDevice.pressHome();
     67         super.tearDown();
     68     }
     69 
     70     @MediumTest
     71     public void testInLineNotificationWithLockScreen() throws Exception {
     72         try {
     73             mHelper.sendNotificationsWithInlineReply(NOTIFICATION_ID,false);
     74             mHelper.sleepAndWakeUpDevice();
     75             UiObject2 obj = mDevice.wait(Until.findObject(By.text("INLINE REPLY TEST")),
     76                     LONG_TIMEOUT);
     77             mDevice.swipe(obj.getVisibleBounds().centerX(), obj.getVisibleBounds().centerY(),
     78                     obj.getVisibleBounds().centerX(),
     79                     mDevice.getDisplayHeight(), 5);
     80             mDevice.wait(Until.findObject(By.text("Reply")), LONG_TIMEOUT).click();
     81             UiObject2 replyBox = mDevice.wait(
     82                     Until.findObject(By.res("com.android.systemui:id/remote_input_send")),
     83                     LONG_TIMEOUT);
     84             InputMethodManager imm = (InputMethodManager) mContext
     85                     .getSystemService(Context.INPUT_METHOD_SERVICE);
     86             if (!imm.isAcceptingText()) {
     87                 assertNotNull("Keyboard for inline reply has not loaded correctly", replyBox);
     88             }
     89         } finally {
     90             mHelper.swipeUp();
     91         }
     92     }
     93 
     94     @MediumTest
     95     public void testInLineNotificationsWithQuickSetting() throws Exception {
     96         mHelper.sendNotificationsWithInlineReply(NOTIFICATION_ID, false);
     97         Thread.sleep(SHORT_TIMEOUT);
     98         mDevice.openQuickSettings();
     99         mDevice.openNotification();
    100         mDevice.wait(Until.findObject(By.text("Reply")), LONG_TIMEOUT).click();
    101         UiObject2 replyBox = mDevice.wait(
    102                 Until.findObject(By.res("com.android.systemui:id/remote_input_send")),
    103                 LONG_TIMEOUT);
    104         InputMethodManager imm = (InputMethodManager) mContext
    105                 .getSystemService(Context.INPUT_METHOD_SERVICE);
    106         if (!imm.isAcceptingText()) {
    107             assertNotNull("Keyboard for inline reply has not loaded correctly", replyBox);
    108         }
    109     }
    110 
    111     @MediumTest
    112     public void testInlineReplyNotification() throws Exception {
    113         mHelper.sendNotificationsWithInlineReply(NOTIFICATION_ID_2, false);
    114         Thread.sleep(LONG_TIMEOUT);
    115         mDevice.openNotification();
    116         UiObject2 replyBtn = null;
    117         int count = 10;
    118         while (--count > 0) {
    119             replyBtn = mDevice.wait(Until.findObject(By.res("android:id/action0")), LONG_TIMEOUT);
    120             if (replyBtn != null) {
    121                 break;
    122             }
    123         }
    124         assertNotNull("Cant find inline reply box", replyBtn);
    125         replyBtn.click();
    126         UiObject2 replyBox = mDevice.wait(
    127         Until.findObject(By.res(RECEIVER_PKG_NAME, "remote_input_send")),
    128                 LONG_TIMEOUT);
    129         InputMethodManager imm = (InputMethodManager) mContext
    130                 .getSystemService(Context.INPUT_METHOD_SERVICE);
    131         if (!imm.isAcceptingText()) {
    132             assertNotNull("Keyboard for inline reply has not loaded correctly", replyBox);
    133         }
    134     }
    135 }
    136