| Index: clank/test/geppetto/clanktests/src/com/google/android/apps/chrome/uiautomator/CrashReportTest.java
|
| diff --git a/clank/test/geppetto/clanktests/src/com/google/android/apps/chrome/uiautomator/CrashReportTest.java b/clank/test/geppetto/clanktests/src/com/google/android/apps/chrome/uiautomator/CrashReportTest.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..58abd26aff374c7dd691f9a949ce55243739badb
|
| --- /dev/null
|
| +++ b/clank/test/geppetto/clanktests/src/com/google/android/apps/chrome/uiautomator/CrashReportTest.java
|
| @@ -0,0 +1,131 @@
|
| +// Copyright 2015 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 com.google.android.apps.chrome.uiautomator;
|
| +
|
| +import android.support.test.uiautomator.UiObject;
|
| +import android.support.test.uiautomator.UiObjectNotFoundException;
|
| +import android.support.test.uiautomator.UiSelector;
|
| +import android.test.suitebuilder.annotation.SmallTest;
|
| +
|
| +import com.google.android.apps.chrome.uiautomator.utilities.OmniboxHelper;
|
| +import com.google.android.apps.chrome.uiautomator.utilities.OptionsMenuHelper;
|
| +import com.google.android.apps.chrome.uiautomator.utilities.PageHelper;
|
| +import com.google.android.apps.chrome.uiautomator.utilities.PrivacyHelper;
|
| +import com.google.android.apps.chrome.uiautomator.utilities.SettingsHelper;
|
| +import com.google.android.apps.uiautomator.utilities.DeviceHelper;
|
| +
|
| +import org.chromium.chrome.browser.ChromeActivity;
|
| +
|
| +/**
|
| + * Class for all Toolbar test cases.
|
| + */
|
| +public class CrashReportTest extends UiAutomatorTestCase<ChromeActivity> {
|
| +
|
| + private static final String YAHOO = "yahoo.com";
|
| + private static final String CHROME_CRASH = "chrome://crash";
|
| + private static final String CHROME_GPU_CRASH = "chrome://gpucrash";
|
| + private static final String CHROME_CRASHES = "chrome://crashes";
|
| +
|
| + private DeviceHelper mDeviceHelper;
|
| + private OmniboxHelper mOmniboxHelper;
|
| + private PageHelper mPageHelper;
|
| + private OptionsMenuHelper mOptionsMenuHelper;
|
| + private PrivacyHelper mPrivacyHelper;
|
| + private SettingsHelper mSettingsHelper;
|
| +
|
| + private UiObject mRefreshedPageContent;
|
| + private UiObject mTestPageContent;
|
| +
|
| + public CrashReportTest() {
|
| + super(ChromeActivity.class);
|
| + }
|
| +
|
| + @Override
|
| + protected void setUp() throws Exception {
|
| + super.setUp();
|
| +
|
| + mDeviceHelper = new DeviceHelper(getDevice());
|
| + mOmniboxHelper = new OmniboxHelper(getDevice());
|
| + mPageHelper = new PageHelper(getDevice());
|
| + mOptionsMenuHelper = new OptionsMenuHelper(getDevice());
|
| + mPrivacyHelper = new PrivacyHelper(getDevice());
|
| + mSettingsHelper = new SettingsHelper(getDevice());
|
| +
|
| + // Open options menu.
|
| + mOptionsMenuHelper.open();
|
| + waitHalfSecond();
|
| +
|
| + // Open settings.
|
| + mOptionsMenuHelper.openSettings();
|
| + waitHalfSecond();
|
| +
|
| + // Open privacy.
|
| + mSettingsHelper.clickOnPrivacy();
|
| + waitHalfSecond();
|
| +
|
| + // Turn on crash reporting.
|
| + mPrivacyHelper.turnOnUsageAndCrashReports();
|
| + waitHalfSecond();
|
| +
|
| + // Navigate up.
|
| + navigateUp();
|
| + }
|
| +
|
| + @Override
|
| + protected void tearDown() throws Exception {
|
| + super.tearDown();
|
| + }
|
| +
|
| + /**
|
| + * Verifies that chrome://crash will crash.
|
| + */
|
| + @SmallTest
|
| + public void testChromeCrash() throws UiObjectNotFoundException {
|
| + // Go to Yahoo first.
|
| + mOmniboxHelper.enterTextAndPressEnter(YAHOO);
|
| + mPageHelper.waitForPageLoad();
|
| +
|
| + // Get crashes count.
|
| + mOmniboxHelper.enterTextAndPressEnter(CHROME_CRASHES);
|
| + mPageHelper.waitForPageLoad();
|
| + int preCrashesCount = getCrashesCount();
|
| +
|
| + // Create chrome crash.
|
| + mOmniboxHelper.enterTextAndPressEnter(CHROME_CRASH);
|
| + mPageHelper.waitForPageLoad();
|
| +
|
| + // Get crashes count after chrome crash.
|
| + mOmniboxHelper.enterTextAndPressEnter(CHROME_CRASHES);
|
| + mPageHelper.waitForPageLoad();
|
| + int currentCrashesCount = getCrashesCount();
|
| +
|
| + // Check crashes are recorded.
|
| + assertTrue((currentCrashesCount - preCrashesCount) == 1);
|
| + }
|
| +
|
| + private void waitHalfSecond() {
|
| + try {
|
| + Thread.sleep(500);
|
| + } catch (Exception e) { }
|
| + }
|
| +
|
| + private int getCrashesCount() {
|
| + try {
|
| + String crashBannerJS = "document.getElementById('countBanner').textContent;";
|
| + String crashBanner = runJavaScriptCodeInCurrentTab(crashBannerJS);
|
| + int length = crashBanner.length();
|
| + int crashesCount = Integer.parseInt(crashBanner.substring(crashBanner.indexOf('(') + 1,
|
| + crashBanner.indexOf(')')));
|
| + return crashesCount;
|
| + } catch (Exception e) {
|
| + return -999;
|
| + }
|
| + }
|
| +
|
| + private void navigateUp() throws UiObjectNotFoundException {
|
| + getDevice().findObject(new UiSelector().description("Navigate up")
|
| + .className("android.widget.ImageButton")).click();
|
| + }
|
| +}
|
|
|