Chromium Code Reviews| 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..c3030a1d8f8cbaba8ab8161db02fff534f5121f6 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,90 @@ 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 we change the button from "Reload" |
|
Theresa
2016/12/01 19:54:05
nit: ... on a tab that failed to load....
JJ
2016/12/01 22:39:40
Done.
|
| + * 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(getActivity().getString(R.string.sad_tab_send_feedback_label), actualText); |
|
Theresa
2016/12/01 19:54:05
nit: Should this have a description too, eg.. "Exp
JJ
2016/12/01 22:39:40
Done.
|
| + } |
| + |
| + /** |
| + * 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" |
|
Theresa
2016/12/01 19:54:05
git cl format messed up the wrapping again
JJ
2016/12/01 22:39:40
It's really weird how this works. Mostly because I
|
| + * button and instead show the "Reload" tab |
|
Theresa
2016/12/01 19:54:05
nit: period at the end of this sentence
JJ
2016/12/01 22:39:40
Done.
|
| + */ |
| + @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() { |
| + |
|
Theresa
2016/12/01 19:54:05
super nit: remove this blank line
JJ
2016/12/01 22:39:40
Super done.
|
| + @Override |
| + public void run() { |
| + tab.simulateRendererKilledForTesting(wasOomProtected); |
| + } |
| + }); |
| } |
| + |
| + /** |
| + * Helper method that reloads a tab with a SadTabView currently displayed |
|
Theresa
2016/12/01 19:54:05
nit: period at the end of this sentence and on the
JJ
2016/12/01 22:39:41
Added on my checklist before submit to add periods
|
| + */ |
| + 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); |
| + } |
| + |
| } |