| Index: chrome/android/javatests/src/org/chromium/chrome/browser/tab/SadTabTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/tab/SadTabTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/tab/SadTabTest.java
|
| index 98802ab6ba6c7876d178e6c44e1fa263e550e7df..37b4647c86a1a7b41bd6a9effb9640b97d83e5ab 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/tab/SadTabTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/tab/SadTabTest.java
|
| @@ -5,10 +5,12 @@
|
| package org.chromium.chrome.browser.tab;
|
|
|
| import android.test.suitebuilder.annotation.SmallTest;
|
| +import android.widget.Button;
|
|
|
| import org.chromium.base.ThreadUtils;
|
| import org.chromium.base.test.util.Feature;
|
| import org.chromium.base.test.util.RetryOnFailure;
|
| +import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.ChromeActivity;
|
| import org.chromium.chrome.test.ChromeActivityTestCaseBase;
|
|
|
| @@ -36,14 +38,7 @@ public class SadTabTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| final Tab tab = getActivity().getActivityTab();
|
|
|
| assertFalse(tab.isShowingSadTab());
|
| -
|
| - ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - tab.simulateRendererKilledForTesting(true);
|
| - }
|
| - });
|
| -
|
| + simulateRendererKilled(tab, true);
|
| assertTrue(tab.isShowingSadTab());
|
| }
|
|
|
| @@ -57,14 +52,91 @@ public class SadTabTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| final Tab tab = getActivity().getActivityTab();
|
|
|
| assertFalse(tab.isShowingSadTab());
|
| + simulateRendererKilled(tab, false);
|
| + assertFalse(tab.isShowingSadTab());
|
| + }
|
| +
|
| + /**
|
| + * Confirm that after a successive refresh of a failed tab that failed to load, change the
|
| + * button from "Reload" to "Send Feedback".
|
| + */
|
| + @SmallTest
|
| + @Feature({"SadTab"})
|
| + public void testChangeSadButtonToFeedbackAfterFailedRefresh() {
|
| + final Tab tab = getActivity().getActivityTab();
|
| +
|
| + assertFalse(tab.isShowingSadTab());
|
| + simulateRendererKilled(tab, true);
|
| + assertTrue(tab.isShowingSadTab());
|
| + String actualText = getSadTabButton(tab).getText().toString();
|
| + assertEquals("Expected the sad tab button to have the reload label",
|
| + getActivity().getString(R.string.sad_tab_reload_label), actualText);
|
| +
|
| + reloadSadTab(tab);
|
| + assertTrue(tab.isShowingSadTab());
|
| + actualText = getSadTabButton(tab).getText().toString();
|
| + assertEquals(
|
| + "Expected the sad tab button to have the feedback label after the tab button "
|
| + + "crashes twice in a row.",
|
| + getActivity().getString(R.string.sad_tab_send_feedback_label), actualText);
|
| + }
|
| +
|
| + /**
|
| + * Confirm after two failures, if we refresh a third time and it's successful, and then we
|
| + * crash again, we do not show the "Send Feedback" button and instead show the "Reload" tab.
|
| + */
|
| + @SmallTest
|
| + @Feature({"SadTab"})
|
| + public void testSadButtonRevertsBackToReloadAfterSuccessfulLoad() {
|
| + final Tab tab = getActivity().getActivityTab();
|
|
|
| + simulateRendererKilled(tab, true);
|
| + reloadSadTab(tab);
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - tab.simulateRendererKilledForTesting(false);
|
| + tab.reload(); // Erases the sad tab page
|
| + tab.didFinishPageLoad(); // Resets the tab counter to 0
|
| }
|
| });
|
| + simulateRendererKilled(tab, true);
|
| + String actualText = getSadTabButton(tab).getText().toString();
|
| + assertEquals(getActivity().getString(R.string.sad_tab_reload_label), actualText);
|
| + }
|
|
|
| - assertFalse(tab.isShowingSadTab());
|
| + /**
|
| + * Helper method that kills the renderer on a UI thread.
|
| + */
|
| + private void simulateRendererKilled(final Tab tab, final boolean wasOomProtected) {
|
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + tab.simulateRendererKilledForTesting(wasOomProtected);
|
| + }
|
| + });
|
| }
|
| +
|
| + /**
|
| + * Helper method that reloads a tab with a SadTabView currently displayed.
|
| + */
|
| + private void reloadSadTab(final Tab tab) {
|
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + tab.reloadSadTabForTesting();
|
| + }
|
| + });
|
| + }
|
| +
|
| + /**
|
| + * If there is a SadTabView, this method will get the button for the sad tab.
|
| + * @param tab The tab that needs to contain a SadTabView.
|
| + * @return Returns the button that is on the SadTabView, null if SadTabView.
|
| + * doesn't exist.
|
| + */
|
| + private Button getSadTabButton(Tab tab) {
|
| + return (Button) tab.getContentViewCore().getContainerView()
|
| + .findViewById(R.id.sad_tab_reload_button);
|
| + }
|
| +
|
| }
|
|
|