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..2834ada1e3d3e5760e3e0c657d8d78c9c95a747c 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; |
| @@ -48,8 +50,8 @@ public class SadTabTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
| } |
| /** |
| - * Verify that the sad tab is not shown when the renderer crashes in the background or the |
| - * renderer was killed by the OS out-of-memory killer. |
| + * Verify that the sad tab is not shown when the renderer crashes in the |
| + * background or the renderer was killed by the OS out-of-memory killer. |
|
Theresa
2016/11/30 19:42:38
nit: change this back (this was probably a side-ef
JJ
2016/11/30 23:55:54
Done.
|
| */ |
| @SmallTest |
| @Feature({"SadTab"}) |
| @@ -67,4 +69,91 @@ public class SadTabTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
| assertFalse(tab.isShowingSadTab()); |
| } |
| + |
| + /** |
| + * Confirm that after a successive refresh of a failed tab we change the |
| + * button from "Reload" to "Send Feedback". |
|
Theresa
2016/11/30 19:42:38
nit: move some of the text from the bottom line up
JJ
2016/11/30 23:55:53
Yeah, weird. I have it set here and I thought the
Theresa
2016/12/01 16:21:21
git cl format doesn't work so well on Java files,
|
| + */ |
| + @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 feedback tab to have the reload label", actualText, |
|
Theresa
2016/11/30 19:42:38
"Expected the sad tab button to have the reload la
JJ
2016/11/30 23:55:53
Yup, done. Thanks for some reason I flip them in m
|
| + getActivity().getString(R.string.sad_tab_reload_label)); |
| + |
| + reloadSadTab(tab); |
| + assertTrue(tab.isShowingSadTab()); |
| + actualText = getSadTabButton(tab).getText().toString(); |
| + assertEquals(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() { |
| + |
|
Theresa
2016/11/30 19:42:38
nit: remove extra blank line
JJ
2016/11/30 23:55:54
Done.
|
| + @Override |
| + public void run() { |
| + tab.reload(); // Erases the sad tab page |
| + tab.didFinishPageLoad(); // Resets the tab counter to 0 |
| + } |
| + }); |
| + // Putting it in the same UI thread causes it to fail. Likely due to |
| + // race conditions. |
| + simulateRendererKilled(tab, true); |
|
JJ
2016/11/30 18:12:16
Please correct me if I'm wrong here.
Theresa
2016/11/30 19:42:38
simulateRendererKilled() below is running on the U
JJ
2016/11/30 23:55:54
Oh sorry not like that. I did try to just add tab.
Theresa
2016/12/01 16:21:21
I think it's fine to leave the test like this (I w
JJ
2016/12/01 17:54:41
I removed the comment. It's an interesting error f
|
| + String actualText = getSadTabButton(tab).getText().toString(); |
| + assertEquals(getActivity().getString(R.string.sad_tab_reload_label), actualText); |
| + } |
| + |
| + /** |
| + * Shortcut 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); |
| + } |
| + }); |
| + } |
| + |
| + /** |
| + * Shortcut method that reloads a tab with a SadTabView currently displayed |
|
Theresa
2016/11/30 19:42:38
nit: "Helper method that reloads a tab that is alr
JJ
2016/11/30 23:55:53
Done.
|
| + */ |
| + private void reloadSadTab(final Tab tab) { |
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| + |
|
Theresa
2016/11/30 19:42:38
nit: remove blank line (here and in simulateRender
JJ
2016/11/30 23:55:54
Done.
|
| + @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); |
| + } |
| + |
| } |