| 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 import android.widget.Button; |
| 9 | 9 |
| 10 import org.chromium.base.ThreadUtils; | 10 import org.chromium.base.ThreadUtils; |
| 11 import org.chromium.base.test.util.DisabledTest; | |
| 12 import org.chromium.base.test.util.Feature; | 11 import org.chromium.base.test.util.Feature; |
| 13 import org.chromium.base.test.util.RetryOnFailure; | 12 import org.chromium.base.test.util.RetryOnFailure; |
| 14 import org.chromium.chrome.R; | 13 import org.chromium.chrome.R; |
| 15 import org.chromium.chrome.browser.ChromeActivity; | 14 import org.chromium.chrome.browser.ChromeActivity; |
| 16 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 15 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
| 17 | 16 |
| 18 /** | 17 /** |
| 19 * Tests related to the sad tab logic. | 18 * Tests related to the sad tab logic. |
| 20 */ | 19 */ |
| 21 @RetryOnFailure | 20 @RetryOnFailure |
| (...skipping 30 matching lines...) Expand all Loading... |
| 52 public void testSadTabNotShownWhenRendererProcessKilledInBackround() { | 51 public void testSadTabNotShownWhenRendererProcessKilledInBackround() { |
| 53 final Tab tab = getActivity().getActivityTab(); | 52 final Tab tab = getActivity().getActivityTab(); |
| 54 | 53 |
| 55 assertFalse(tab.isShowingSadTab()); | 54 assertFalse(tab.isShowingSadTab()); |
| 56 simulateRendererKilled(tab, false); | 55 simulateRendererKilled(tab, false); |
| 57 assertFalse(tab.isShowingSadTab()); | 56 assertFalse(tab.isShowingSadTab()); |
| 58 } | 57 } |
| 59 | 58 |
| 60 /** | 59 /** |
| 61 * Confirm that after a successive refresh of a failed tab that failed to lo
ad, change the | 60 * Confirm that after a successive refresh of a failed tab that failed to lo
ad, change the |
| 62 * button from "Reload" to "Send Feedback". | 61 * button from "Reload" to "Send Feedback". If reloaded a third time and it
is successful it |
| 62 * reverts from "Send Feedback" to "Reload". |
| 63 * @throws InterruptedException |
| 64 * @throws IllegalArgumentException |
| 63 */ | 65 */ |
| 64 @SmallTest | 66 @SmallTest |
| 65 @Feature({"SadTab"}) | 67 @Feature({"SadTab"}) |
| 66 @DisabledTest(message = "crbug.com/670920") | 68 public void testSadTabPageButtonText() throws IllegalArgumentException, Inte
rruptedException { |
| 67 public void testChangeSadButtonToFeedbackAfterFailedRefresh() { | |
| 68 final Tab tab = getActivity().getActivityTab(); | 69 final Tab tab = getActivity().getActivityTab(); |
| 69 | 70 |
| 70 assertFalse(tab.isShowingSadTab()); | 71 assertFalse(tab.isShowingSadTab()); |
| 71 simulateRendererKilled(tab, true); | 72 simulateRendererKilled(tab, true); |
| 72 assertTrue(tab.isShowingSadTab()); | 73 assertTrue(tab.isShowingSadTab()); |
| 73 String actualText = getSadTabButton(tab).getText().toString(); | 74 String actualText = getSadTabButton(tab).getText().toString(); |
| 74 assertEquals("Expected the sad tab button to have the reload label", | 75 assertEquals("Expected the sad tab button to have the reload label", |
| 75 getActivity().getString(R.string.sad_tab_reload_label), actualTe
xt); | 76 getActivity().getString(R.string.sad_tab_reload_label), actualTe
xt); |
| 76 | 77 |
| 77 reloadSadTab(tab); | 78 reloadSadTab(tab); |
| 78 assertTrue(tab.isShowingSadTab()); | 79 assertTrue(tab.isShowingSadTab()); |
| 79 actualText = getSadTabButton(tab).getText().toString(); | 80 actualText = getSadTabButton(tab).getText().toString(); |
| 80 assertEquals( | 81 assertEquals( |
| 81 "Expected the sad tab button to have the feedback label after th
e tab button " | 82 "Expected the sad tab button to have the feedback label after th
e tab button " |
| 82 + "crashes twice in a row.", | 83 + "crashes twice in a row.", |
| 83 getActivity().getString(R.string.sad_tab_send_feedback_label), a
ctualText); | 84 getActivity().getString(R.string.sad_tab_send_feedback_label), a
ctualText); |
| 85 loadUrl("about:blank"); |
| 86 assertFalse("Expected about:blank to destroy the sad tab however the sad
tab is still in " |
| 87 + "view", tab.isShowingSadTab()); |
| 88 simulateRendererKilled(tab, true); |
| 89 actualText = getSadTabButton(tab).getText().toString(); |
| 90 assertEquals("Expected the sad tab button to have the reload label after
a successful load", |
| 91 getActivity().getString(R.string.sad_tab_reload_label), actualTe
xt); |
| 84 } | 92 } |
| 85 | 93 |
| 86 /** | 94 /** |
| 87 * Confirm after two failures, if we refresh a third time and it's successfu
l, and then we | |
| 88 * crash again, we do not show the "Send Feedback" button and instead show t
he "Reload" tab. | |
| 89 */ | |
| 90 @SmallTest | |
| 91 @Feature({"SadTab"}) | |
| 92 @DisabledTest(message = "crbug.com/670920") | |
| 93 public void testSadButtonRevertsBackToReloadAfterSuccessfulLoad() { | |
| 94 final Tab tab = getActivity().getActivityTab(); | |
| 95 | |
| 96 simulateRendererKilled(tab, true); | |
| 97 reloadSadTab(tab); | |
| 98 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
| 99 @Override | |
| 100 public void run() { | |
| 101 tab.reload(); // Erases the sad tab page | |
| 102 tab.didFinishPageLoad(); // Resets the tab counter to 0 | |
| 103 } | |
| 104 }); | |
| 105 simulateRendererKilled(tab, true); | |
| 106 String actualText = getSadTabButton(tab).getText().toString(); | |
| 107 assertEquals(getActivity().getString(R.string.sad_tab_reload_label), act
ualText); | |
| 108 } | |
| 109 | |
| 110 /** | |
| 111 * Helper method that kills the renderer on a UI thread. | 95 * Helper method that kills the renderer on a UI thread. |
| 112 */ | 96 */ |
| 113 private void simulateRendererKilled(final Tab tab, final boolean wasOomProte
cted) { | 97 private void simulateRendererKilled(final Tab tab, final boolean wasOomProte
cted) { |
| 114 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 98 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 115 @Override | 99 @Override |
| 116 public void run() { | 100 public void run() { |
| 117 tab.simulateRendererKilledForTesting(wasOomProtected); | 101 tab.simulateRendererKilledForTesting(wasOomProtected); |
| 118 } | 102 } |
| 119 }); | 103 }); |
| 120 } | 104 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 136 * @param tab The tab that needs to contain a SadTabView. | 120 * @param tab The tab that needs to contain a SadTabView. |
| 137 * @return Returns the button that is on the SadTabView, null if SadTabView. | 121 * @return Returns the button that is on the SadTabView, null if SadTabView. |
| 138 * doesn't exist. | 122 * doesn't exist. |
| 139 */ | 123 */ |
| 140 private Button getSadTabButton(Tab tab) { | 124 private Button getSadTabButton(Tab tab) { |
| 141 return (Button) tab.getContentViewCore().getContainerView() | 125 return (Button) tab.getContentViewCore().getContainerView() |
| 142 .findViewById(R.id.sad_tab_reload_button); | 126 .findViewById(R.id.sad_tab_reload_button); |
| 143 } | 127 } |
| 144 | 128 |
| 145 } | 129 } |
| OLD | NEW |