| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.tab; | 5 package org.chromium.chrome.browser.tab; |
| 6 | 6 |
| 7 import android.test.suitebuilder.annotation.SmallTest; | 7 import android.test.suitebuilder.annotation.SmallTest; |
| 8 import android.widget.Button; |
| 8 | 9 |
| 9 import org.chromium.base.ThreadUtils; | 10 import org.chromium.base.ThreadUtils; |
| 10 import org.chromium.base.test.util.Feature; | 11 import org.chromium.base.test.util.Feature; |
| 11 import org.chromium.base.test.util.RetryOnFailure; | 12 import org.chromium.base.test.util.RetryOnFailure; |
| 13 import org.chromium.chrome.R; |
| 12 import org.chromium.chrome.browser.ChromeActivity; | 14 import org.chromium.chrome.browser.ChromeActivity; |
| 13 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 15 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
| 14 | 16 |
| 15 /** | 17 /** |
| 16 * Tests related to the sad tab logic. | 18 * Tests related to the sad tab logic. |
| 17 */ | 19 */ |
| 18 @RetryOnFailure | 20 @RetryOnFailure |
| 19 public class SadTabTest extends ChromeActivityTestCaseBase<ChromeActivity> { | 21 public class SadTabTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
| 20 | 22 |
| 21 public SadTabTest() { | 23 public SadTabTest() { |
| 22 super(ChromeActivity.class); | 24 super(ChromeActivity.class); |
| 23 } | 25 } |
| 24 | 26 |
| 25 @Override | 27 @Override |
| 26 public void startMainActivity() throws InterruptedException { | 28 public void startMainActivity() throws InterruptedException { |
| 27 startMainActivityOnBlankPage(); | 29 startMainActivityOnBlankPage(); |
| 28 } | 30 } |
| 29 | 31 |
| 30 /** | 32 /** |
| 31 * Verify that the sad tab is shown when the renderer crashes. | 33 * Verify that the sad tab is shown when the renderer crashes. |
| 32 */ | 34 */ |
| 33 @SmallTest | 35 @SmallTest |
| 34 @Feature({"SadTab"}) | 36 @Feature({"SadTab"}) |
| 35 public void testSadTabShownWhenRendererProcessKilled() { | 37 public void testSadTabShownWhenRendererProcessKilled() { |
| 36 final Tab tab = getActivity().getActivityTab(); | 38 final Tab tab = getActivity().getActivityTab(); |
| 37 | 39 |
| 38 assertFalse(tab.isShowingSadTab()); | 40 assertFalse(tab.isShowingSadTab()); |
| 39 | 41 simulateRendererKilled(tab, true); |
| 40 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
| 41 @Override | |
| 42 public void run() { | |
| 43 tab.simulateRendererKilledForTesting(true); | |
| 44 } | |
| 45 }); | |
| 46 | |
| 47 assertTrue(tab.isShowingSadTab()); | 42 assertTrue(tab.isShowingSadTab()); |
| 48 } | 43 } |
| 49 | 44 |
| 50 /** | 45 /** |
| 51 * Verify that the sad tab is not shown when the renderer crashes in the bac
kground or the | 46 * Verify that the sad tab is not shown when the renderer crashes in the bac
kground or the |
| 52 * renderer was killed by the OS out-of-memory killer. | 47 * renderer was killed by the OS out-of-memory killer. |
| 53 */ | 48 */ |
| 54 @SmallTest | 49 @SmallTest |
| 55 @Feature({"SadTab"}) | 50 @Feature({"SadTab"}) |
| 56 public void testSadTabNotShownWhenRendererProcessKilledInBackround() { | 51 public void testSadTabNotShownWhenRendererProcessKilledInBackround() { |
| 57 final Tab tab = getActivity().getActivityTab(); | 52 final Tab tab = getActivity().getActivityTab(); |
| 58 | 53 |
| 59 assertFalse(tab.isShowingSadTab()); | 54 assertFalse(tab.isShowingSadTab()); |
| 55 simulateRendererKilled(tab, false); |
| 56 assertFalse(tab.isShowingSadTab()); |
| 57 } |
| 60 | 58 |
| 59 /** |
| 60 * Confirm that after a successive refresh of a failed tab that failed to lo
ad, change the |
| 61 * button from "Reload" to "Send Feedback". |
| 62 */ |
| 63 @SmallTest |
| 64 @Feature({"SadTab"}) |
| 65 public void testChangeSadButtonToFeedbackAfterFailedRefresh() { |
| 66 final Tab tab = getActivity().getActivityTab(); |
| 67 |
| 68 assertFalse(tab.isShowingSadTab()); |
| 69 simulateRendererKilled(tab, true); |
| 70 assertTrue(tab.isShowingSadTab()); |
| 71 String actualText = getSadTabButton(tab).getText().toString(); |
| 72 assertEquals("Expected the sad tab button to have the reload label", |
| 73 getActivity().getString(R.string.sad_tab_reload_label), actualTe
xt); |
| 74 |
| 75 reloadSadTab(tab); |
| 76 assertTrue(tab.isShowingSadTab()); |
| 77 actualText = getSadTabButton(tab).getText().toString(); |
| 78 assertEquals( |
| 79 "Expected the sad tab button to have the feedback label after th
e tab button " |
| 80 + "crashes twice in a row.", |
| 81 getActivity().getString(R.string.sad_tab_send_feedback_label), a
ctualText); |
| 82 } |
| 83 |
| 84 /** |
| 85 * Confirm after two failures, if we refresh a third time and it's successfu
l, and then we |
| 86 * crash again, we do not show the "Send Feedback" button and instead show t
he "Reload" tab. |
| 87 */ |
| 88 @SmallTest |
| 89 @Feature({"SadTab"}) |
| 90 public void testSadButtonRevertsBackToReloadAfterSuccessfulLoad() { |
| 91 final Tab tab = getActivity().getActivityTab(); |
| 92 |
| 93 simulateRendererKilled(tab, true); |
| 94 reloadSadTab(tab); |
| 61 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 95 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 62 @Override | 96 @Override |
| 63 public void run() { | 97 public void run() { |
| 64 tab.simulateRendererKilledForTesting(false); | 98 tab.reload(); // Erases the sad tab page |
| 99 tab.didFinishPageLoad(); // Resets the tab counter to 0 |
| 65 } | 100 } |
| 66 }); | 101 }); |
| 102 simulateRendererKilled(tab, true); |
| 103 String actualText = getSadTabButton(tab).getText().toString(); |
| 104 assertEquals(getActivity().getString(R.string.sad_tab_reload_label), act
ualText); |
| 105 } |
| 67 | 106 |
| 68 assertFalse(tab.isShowingSadTab()); | 107 /** |
| 108 * Helper method that kills the renderer on a UI thread. |
| 109 */ |
| 110 private void simulateRendererKilled(final Tab tab, final boolean wasOomProte
cted) { |
| 111 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 112 @Override |
| 113 public void run() { |
| 114 tab.simulateRendererKilledForTesting(wasOomProtected); |
| 115 } |
| 116 }); |
| 69 } | 117 } |
| 118 |
| 119 /** |
| 120 * Helper method that reloads a tab with a SadTabView currently displayed. |
| 121 */ |
| 122 private void reloadSadTab(final Tab tab) { |
| 123 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 124 @Override |
| 125 public void run() { |
| 126 tab.reloadSadTabForTesting(); |
| 127 } |
| 128 }); |
| 129 } |
| 130 |
| 131 /** |
| 132 * If there is a SadTabView, this method will get the button for the sad tab
. |
| 133 * @param tab The tab that needs to contain a SadTabView. |
| 134 * @return Returns the button that is on the SadTabView, null if SadTabView. |
| 135 * doesn't exist. |
| 136 */ |
| 137 private Button getSadTabButton(Tab tab) { |
| 138 return (Button) tab.getContentViewCore().getContainerView() |
| 139 .findViewById(R.id.sad_tab_reload_button); |
| 140 } |
| 141 |
| 70 } | 142 } |
| OLD | NEW |