| Index: android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/GmailTest.java
|
| diff --git a/android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/GmailTest.java b/android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/GmailTest.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c806b05dba2f8a098d3cd3e06890e1819c1abbc9
|
| --- /dev/null
|
| +++ b/android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/GmailTest.java
|
| @@ -0,0 +1,352 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.webview_ui_test.test;
|
| +
|
| +import android.content.Intent;
|
| +import android.os.Build;
|
| +import android.os.RemoteException;
|
| +import android.os.SystemClock;
|
| +import android.support.test.InstrumentationRegistry;
|
| +import android.support.test.runner.AndroidJUnit4;
|
| +import android.support.test.uiautomator.UiDevice;
|
| +import android.support.test.uiautomator.UiObject;
|
| +import android.support.test.uiautomator.UiObjectNotFoundException;
|
| +import android.support.test.uiautomator.UiScrollable;
|
| +import android.support.test.uiautomator.UiSelector;
|
| +
|
| +import android.support.test.filters.LargeTest;
|
| +
|
| +import com.android.volley.DefaultRetryPolicy;
|
| +import com.android.volley.Request;
|
| +import com.android.volley.RequestQueue;
|
| +import com.android.volley.Response;
|
| +import com.android.volley.VolleyError;
|
| +import com.android.volley.toolbox.StringRequest;
|
| +import com.android.volley.toolbox.Volley;
|
| +
|
| +import org.junit.After;
|
| +import org.junit.Assert;
|
| +import org.junit.Before;
|
| +import org.junit.Test;
|
| +import org.junit.runner.RunWith;
|
| +
|
| +import org.chromium.base.Log;
|
| +
|
| +@RunWith(AndroidJUnit4.class)
|
| +public class GmailTest {
|
| + private UiDevice mDevice;
|
| +
|
| + private static final int UI_TIMEOUT = 10 * 1000;
|
| + private static final int EMAIL_WAIT = 20 * 1000;
|
| + private static final int WEBVIEW_CONTENT_WAIT = 30 * 1000;
|
| + private int mCenterX;
|
| + private int mCenterY;
|
| + private String mTitleType;
|
| +
|
| + private RequestQueue mRequestQueue =
|
| + Volley.newRequestQueue(InstrumentationRegistry.getContext());
|
| +
|
| + private boolean startTracingResponse;
|
| + private boolean endTracingResponse;
|
| +
|
| + public static String UNREAD_CENTITHREAD_EMAIL_DESC = "Unread Yoland Yan about Unread Test %s.*";
|
| + public static String UNREAD_SINGLE_EMAIL_DESC =
|
| + "Unread Yoland Yan about Unread Test Single %s.*";
|
| + public static String READ_CENTITHREAD_EMAIL_DESC = " *me about Read Test %s.*";
|
| + public static String READ_SINGLE_EMAIL_DESC = " *me about Read Test Single %s.*";
|
| +
|
| + @Before
|
| + public void setUp() throws RemoteException, UiObjectNotFoundException, InterruptedException {
|
| + mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
|
| + mDevice.setOrientationNatural();
|
| + mDevice.wakeUp();
|
| + mCenterX = mDevice.getDisplayWidth() / 2;
|
| + mCenterY = mDevice.getDisplayHeight() / 2;
|
| + mDevice.swipe(mCenterX, mCenterY, mCenterX, 0, 20);
|
| + mTitleType = InstrumentationRegistry.getArguments().getString("title");
|
| + if (mTitleType == null) {
|
| + mTitleType = "Long Text";
|
| + }
|
| + mRequestQueue.start();
|
| + }
|
| +
|
| + @After
|
| + public void tearDown() throws RemoteException, UiObjectNotFoundException, InterruptedException {
|
| + closeRecentActivity();
|
| + endTracing();
|
| + Thread.sleep(3000);
|
| + mDevice.unfreezeRotation();
|
| + mRequestQueue.stop();
|
| + }
|
| +
|
| + // @Test
|
| + // public void testUnreadCentiThread() throws RemoteException, UiObjectNotFoundException {
|
| + // //STUB
|
| + // }
|
| +
|
| + // @Test
|
| + // public void testUnreadSingleThread() throws RemoteException, UiObjectNotFoundException {
|
| + // //STUB
|
| + // }
|
| +
|
| + // Test for CentiThread
|
| + @Test
|
| + @LargeTest
|
| + public void testReadCentiThread()
|
| + throws RemoteException, UiObjectNotFoundException, InterruptedException {
|
| + Log.d("#YOLAND", "open_conversation soon for " + mTitleType + " testReadCentiThread");
|
| + startTracing("testReadCentiThread");
|
| + openGmail();
|
| + clickEmail(String.format(READ_CENTITHREAD_EMAIL_DESC, mTitleType));
|
| + waitForWebView();
|
| + }
|
| +
|
| + @Test
|
| + @LargeTest
|
| + public void testReadGoBackReadAgainCentiThread()
|
| + throws RemoteException, UiObjectNotFoundException, InterruptedException {
|
| + Log.d("#YOLAND",
|
| + "open_conversation soon for " + mTitleType + " testReadGoBackReadAgainCentiThread");
|
| + startTracing("testReadGoBackReadAgainCentiThread");
|
| + openGmail();
|
| + clickEmail(String.format(READ_CENTITHREAD_EMAIL_DESC, mTitleType));
|
| + waitForWebView();
|
| + clickBack();
|
| + Thread.sleep(5000);
|
| + clickEmail(String.format(READ_CENTITHREAD_EMAIL_DESC, mTitleType));
|
| + waitForWebView();
|
| + }
|
| +
|
| + @Test
|
| + @LargeTest
|
| + public void testReadGoBackLockReadAgainCentiThread()
|
| + throws RemoteException, UiObjectNotFoundException, InterruptedException {
|
| + Log.d("#YOLAND", "open_conversation soon for " + mTitleType
|
| + + " testReadGoBackLockReadAgainCentiThread");
|
| + startTracing("testReadGoBackLockReadAgainCentiThread");
|
| + openGmail();
|
| + clickEmail(String.format(READ_CENTITHREAD_EMAIL_DESC, mTitleType));
|
| + waitForWebView();
|
| + clickBack();
|
| + mDevice.sleep();
|
| + Thread.sleep(5000);
|
| + mDevice.wakeUp();
|
| + mDevice.swipe(mCenterX, mCenterY, mCenterX, 0, 20);
|
| + clickEmail(String.format(READ_CENTITHREAD_EMAIL_DESC, mTitleType));
|
| + waitForWebView();
|
| + }
|
| +
|
| + @Test
|
| + @LargeTest
|
| + public void testReadLockReadAgainCentiThread()
|
| + throws RemoteException, UiObjectNotFoundException, InterruptedException {
|
| + Log.d("#YOLAND",
|
| + "open_conversation soon for " + mTitleType + " testReadLockReadAgainCentiThread");
|
| + startTracing("testReadLockReadAgainCentiThread");
|
| + openGmail();
|
| + clickEmail(String.format(READ_CENTITHREAD_EMAIL_DESC, mTitleType));
|
| + waitForWebView();
|
| + mDevice.sleep();
|
| + Thread.sleep(5000);
|
| + mDevice.wakeUp();
|
| + mDevice.swipe(mCenterX, mCenterY, mCenterX, 0, 20);
|
| + waitForWebView();
|
| + }
|
| +
|
| + // Test for Single Email Thread
|
| + @Test
|
| + @LargeTest
|
| + public void testReadSingleThread()
|
| + throws RemoteException, UiObjectNotFoundException, InterruptedException {
|
| + Log.d("#YOLAND", "open_conversation soon for " + mTitleType + " testReadSingleThread");
|
| + startTracing("testReadSingleThread");
|
| + openGmail();
|
| + clickEmail(String.format(READ_SINGLE_EMAIL_DESC, mTitleType));
|
| + waitForWebView();
|
| + }
|
| +
|
| + @Test
|
| + @LargeTest
|
| + public void testReadGoBackReadAgainSingleThread()
|
| + throws RemoteException, UiObjectNotFoundException, InterruptedException {
|
| + Log.d("#YOLAND", "open_conversation soon for " + mTitleType
|
| + + " testReadGoBackReadAgainSingleThread");
|
| + startTracing("testReadGoBackReadAgainSingleThread");
|
| + openGmail();
|
| + clickEmail(String.format(READ_SINGLE_EMAIL_DESC, mTitleType));
|
| + waitForWebView();
|
| + clickBack();
|
| + Thread.sleep(5000);
|
| + clickEmail(String.format(READ_SINGLE_EMAIL_DESC, mTitleType));
|
| + waitForWebView();
|
| + }
|
| +
|
| + @Test
|
| + @LargeTest
|
| + public void testReadGoBackLockReadAgainSingleThread()
|
| + throws RemoteException, UiObjectNotFoundException, InterruptedException {
|
| + Log.d("#YOLAND", "open_conversation soon for " + mTitleType
|
| + + " testReadGoBackLockReadAgainSingleThread");
|
| + startTracing("testReadGoBackLockReadAgainSingleThread");
|
| + openGmail();
|
| + clickEmail(String.format(READ_SINGLE_EMAIL_DESC, mTitleType));
|
| + waitForWebView();
|
| + clickBack();
|
| + mDevice.sleep();
|
| + Thread.sleep(5000);
|
| + mDevice.wakeUp();
|
| + mDevice.swipe(mCenterX, mCenterY, mCenterX, 0, 20);
|
| + clickEmail(String.format(READ_SINGLE_EMAIL_DESC, mTitleType));
|
| + waitForWebView();
|
| + }
|
| +
|
| + @Test
|
| + @LargeTest
|
| + public void testReadLockReadAgainSingleThread()
|
| + throws RemoteException, UiObjectNotFoundException, InterruptedException {
|
| + Log.d("#YOLAND",
|
| + "open_conversation soon for " + mTitleType + " testReadLockReadAgainSingleThread");
|
| + startTracing("testReadLockReadAgainSingleThread");
|
| + openGmail();
|
| + clickEmail(String.format(READ_SINGLE_EMAIL_DESC, mTitleType));
|
| + waitForWebView();
|
| + mDevice.sleep();
|
| + Thread.sleep(5000);
|
| + mDevice.wakeUp();
|
| + mDevice.swipe(mCenterX, mCenterY, mCenterX, 0, 20);
|
| + waitForWebView();
|
| + }
|
| +
|
| + // Private helper method from here on
|
| + private void clickBack() throws UiObjectNotFoundException {
|
| + UiObject back = mDevice.findObject(new UiSelector().descriptionMatches("Navigate up"));
|
| + Assert.assertTrue(
|
| + "Backbutton not found, wtf, check if the title is wrong, currently looking for back button",
|
| + back.waitForExists(UI_TIMEOUT));
|
| + back.click();
|
| + }
|
| +
|
| + private void lockScreen() throws UiObjectNotFoundException {}
|
| +
|
| + private void clickEmail(String descRegex) throws UiObjectNotFoundException {
|
| + UiObject emailThread = mDevice.findObject(new UiSelector().descriptionMatches(descRegex));
|
| + Assert.assertTrue(
|
| + "New email not found, wtf, check if the title is wrong, currently looking for email titled "
|
| + + descRegex,
|
| + emailThread.waitForExists(UI_TIMEOUT));
|
| + emailThread.click();
|
| + }
|
| +
|
| + private void startTracing(String name) throws InterruptedException {
|
| + // adhoc way of notifying the host side to start tracing
|
| + Log.d("#YOLAND", "start tracing");
|
| + startTracingResponse = false;
|
| + String url = "http://localhost:7777/start-tracing/" + name;
|
| +
|
| + StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
|
| + new Response.Listener<String>() {
|
| + @Override
|
| + public void onResponse(String response) {
|
| + Log.d("#YOLAND", "start tracing response: " + response);
|
| + startTracingResponse = true;
|
| + }
|
| + },
|
| + new Response.ErrorListener() {
|
| + @Override
|
| + public void onErrorResponse(VolleyError error) {
|
| + Log.d("#YOLAND", "start tracing error: " + error.getMessage());
|
| + }
|
| + });
|
| + stringRequest.setRetryPolicy(new DefaultRetryPolicy(
|
| + DefaultRetryPolicy.DEFAULT_TIMEOUT_MS, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
|
| + mRequestQueue.add(stringRequest);
|
| + }
|
| +
|
| + private void endTracing() throws InterruptedException {
|
| + // adhoc way of notifying the host side to end tracing
|
| + Log.d("#YOLAND", "end tracing");
|
| + endTracingResponse = false;
|
| + String url = "http://localhost:7777/end-tracing";
|
| + StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
|
| + new Response.Listener<String>() {
|
| + @Override
|
| + public void onResponse(String response) {
|
| + Log.d("#YOLAND", "end tracing response: " + response);
|
| + endTracingResponse = true;
|
| + }
|
| + },
|
| + new Response.ErrorListener() {
|
| + @Override
|
| + public void onErrorResponse(VolleyError error) {
|
| + Log.d("#YOLAND", "end tracing error: " + error.getMessage());
|
| + }
|
| + });
|
| + stringRequest.setRetryPolicy(new DefaultRetryPolicy(
|
| + DefaultRetryPolicy.DEFAULT_TIMEOUT_MS, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
|
| + mRequestQueue.add(stringRequest);
|
| + }
|
| +
|
| + // private void waitForNewEmail() {
|
| + // long start = SystemClock.elapsedRealtime();
|
| + // while (!mNewEmailThread.waitForExists(UI_TIMEOUT) && SystemClock.elapsedRealtime() -
|
| + // start < EMAIL_WAIT) {
|
| + // mDevice.swipe(mCenterX, mCenterY, mCenterX, mDevice.getDisplayHeight(), 10);
|
| + // }
|
| + // Assert.assertTrue("New email not found, wtf",
|
| + // mNewEmailThread.waitForExists(UI_TIMEOUT));
|
| + // }
|
| +
|
| + private void waitForWebView() throws InterruptedException {
|
| + UiObject webviewContent =
|
| + mDevice.findObject(new UiSelector().descriptionMatches("^Test content:.*"));
|
| + if (!webviewContent.waitForExists(WEBVIEW_CONTENT_WAIT)) {
|
| + Log.d("#YOLAND", "WebView Content never came up!!!!");
|
| + throw new AssertionError("Webview content never came up");
|
| + }
|
| + Thread.sleep(1000);
|
| + }
|
| +
|
| + private void openGmail() {
|
| + Intent i =
|
| + InstrumentationRegistry.getContext().getPackageManager().getLaunchIntentForPackage(
|
| + "com.google.android.gm");
|
| + i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
| + InstrumentationRegistry.getContext().startActivity(i);
|
| + }
|
| +
|
| + private void openApp(String appName) throws UiObjectNotFoundException, RemoteException {
|
| + mDevice.pressHome();
|
| + openAppsMenu();
|
| + UiScrollable appMenu = new UiScrollable(new UiSelector().resourceIdMatches(
|
| + ".*(apps_customize_pane_content|apps_list_view)"));
|
| + appMenu.setAsHorizontalList();
|
| + appMenu.getChildByText(new UiSelector().className(android.widget.TextView.class), appName)
|
| + .click();
|
| + }
|
| +
|
| + private void openAppsMenu() throws UiObjectNotFoundException {
|
| + if (Build.DEVICE.equals("sailfish")) {
|
| + // UiObject pageIndicator = mDevice.findObject(new
|
| + // UiSelector().resourceIdMatches(".*page_indicator"));
|
| + // Assert.assertTrue("Apps menu button was not found.",
|
| + // pageIndicator.waitForExists(UI_TIMEOUT));
|
| + // pageIndicator.swipeUp(10);
|
| + mDevice.swipe(mCenterX, mCenterY, mCenterX, 0, 10);
|
| + } else {
|
| + UiObject appsMenuButton = mDevice.findObject(new UiSelector().description("Apps"));
|
| + Assert.assertTrue(
|
| + "Apps menu button was not found.", appsMenuButton.waitForExists(UI_TIMEOUT));
|
| + appsMenuButton.click();
|
| + }
|
| + }
|
| +
|
| + private void closeRecentActivity()
|
| + throws UiObjectNotFoundException, RemoteException, InterruptedException {
|
| + mDevice.pressRecentApps();
|
| + Thread.sleep(500);
|
| + mDevice.swipe(mCenterX, mCenterY, mDevice.getDisplayWidth(), mCenterY, 5);
|
| + mDevice.pressHome();
|
| + }
|
| +}
|
|
|