Chromium Code Reviews| 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() { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 41 @Override | 43 @Override |
| 42 public void run() { | 44 public void run() { |
| 43 tab.simulateRendererKilledForTesting(true); | 45 tab.simulateRendererKilledForTesting(true); |
| 44 } | 46 } |
| 45 }); | 47 }); |
| 46 | 48 |
| 47 assertTrue(tab.isShowingSadTab()); | 49 assertTrue(tab.isShowingSadTab()); |
| 48 } | 50 } |
| 49 | 51 |
| 50 /** | 52 /** |
| 51 * Verify that the sad tab is not shown when the renderer crashes in the bac kground or the | 53 * Verify that the sad tab is not shown when the renderer crashes in the |
| 52 * renderer was killed by the OS out-of-memory killer. | 54 * 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.
| |
| 53 */ | 55 */ |
| 54 @SmallTest | 56 @SmallTest |
| 55 @Feature({"SadTab"}) | 57 @Feature({"SadTab"}) |
| 56 public void testSadTabNotShownWhenRendererProcessKilledInBackround() { | 58 public void testSadTabNotShownWhenRendererProcessKilledInBackround() { |
| 57 final Tab tab = getActivity().getActivityTab(); | 59 final Tab tab = getActivity().getActivityTab(); |
| 58 | 60 |
| 59 assertFalse(tab.isShowingSadTab()); | 61 assertFalse(tab.isShowingSadTab()); |
| 60 | 62 |
| 61 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 63 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 62 @Override | 64 @Override |
| 63 public void run() { | 65 public void run() { |
| 64 tab.simulateRendererKilledForTesting(false); | 66 tab.simulateRendererKilledForTesting(false); |
|
Theresa
2016/11/30 19:42:38
Change this to use the new helper method (same abo
JJ
2016/12/01 17:54:41
Done.
| |
| 65 } | 67 } |
| 66 }); | 68 }); |
| 67 | 69 |
| 68 assertFalse(tab.isShowingSadTab()); | 70 assertFalse(tab.isShowingSadTab()); |
| 69 } | 71 } |
| 72 | |
| 73 /** | |
| 74 * Confirm that after a successive refresh of a failed tab we change the | |
| 75 * 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,
| |
| 76 */ | |
| 77 @SmallTest | |
| 78 @Feature({"SadTab"}) | |
| 79 public void testChangeSadButtonToFeedbackAfterFailedRefresh() { | |
| 80 final Tab tab = getActivity().getActivityTab(); | |
| 81 | |
| 82 assertFalse(tab.isShowingSadTab()); | |
| 83 simulateRendererKilled(tab, true); | |
| 84 assertTrue(tab.isShowingSadTab()); | |
| 85 String actualText = getSadTabButton(tab).getText().toString(); | |
| 86 assertEquals("Expected the feedback tab to have the reload label", actua lText, | |
|
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
| |
| 87 getActivity().getString(R.string.sad_tab_reload_label)); | |
| 88 | |
| 89 reloadSadTab(tab); | |
| 90 assertTrue(tab.isShowingSadTab()); | |
| 91 actualText = getSadTabButton(tab).getText().toString(); | |
| 92 assertEquals(getActivity().getString(R.string.sad_tab_send_feedback_labe l), actualText); | |
| 93 } | |
| 94 | |
| 95 /** | |
| 96 * Confirm after two failures, if we refresh a third time and it's | |
| 97 * successful, and then we crash again, we do not show the "Send Feedback" | |
| 98 * button and instead show the "Reload" tab | |
| 99 */ | |
| 100 @SmallTest | |
| 101 @Feature({"SadTab"}) | |
| 102 public void testSadButtonRevertsBackToReloadAfterSuccessfulLoad() { | |
| 103 final Tab tab = getActivity().getActivityTab(); | |
| 104 | |
| 105 simulateRendererKilled(tab, true); | |
| 106 reloadSadTab(tab); | |
| 107 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
| 108 | |
|
Theresa
2016/11/30 19:42:38
nit: remove extra blank line
JJ
2016/11/30 23:55:54
Done.
| |
| 109 @Override | |
| 110 public void run() { | |
| 111 tab.reload(); // Erases the sad tab page | |
| 112 tab.didFinishPageLoad(); // Resets the tab counter to 0 | |
| 113 } | |
| 114 }); | |
| 115 // Putting it in the same UI thread causes it to fail. Likely due to | |
| 116 // race conditions. | |
| 117 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
| |
| 118 String actualText = getSadTabButton(tab).getText().toString(); | |
| 119 assertEquals(getActivity().getString(R.string.sad_tab_reload_label), act ualText); | |
| 120 } | |
| 121 | |
| 122 /** | |
| 123 * Shortcut method that kills the renderer on a UI thread. | |
| 124 */ | |
| 125 private void simulateRendererKilled(final Tab tab, final boolean wasOomProte cted) { | |
| 126 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
| 127 | |
| 128 @Override | |
| 129 public void run() { | |
| 130 tab.simulateRendererKilledForTesting(wasOomProtected); | |
| 131 } | |
| 132 }); | |
| 133 } | |
| 134 | |
| 135 /** | |
| 136 * 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.
| |
| 137 */ | |
| 138 private void reloadSadTab(final Tab tab) { | |
| 139 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
| 140 | |
|
Theresa
2016/11/30 19:42:38
nit: remove blank line (here and in simulateRender
JJ
2016/11/30 23:55:54
Done.
| |
| 141 @Override | |
| 142 public void run() { | |
| 143 tab.reloadSadTabForTesting(); | |
| 144 } | |
| 145 }); | |
| 146 } | |
| 147 | |
| 148 /** | |
| 149 * If there is a SadTabView, this method will get the button for the sad tab | |
| 150 * @param tab The tab that needs to contain a SadTabView | |
| 151 * @return Returns the button that is on the SadTabView, null if SadTabView | |
| 152 * doesn't exist. | |
| 153 */ | |
| 154 private Button getSadTabButton(Tab tab) { | |
| 155 return (Button) tab.getContentViewCore().getContainerView() | |
| 156 .findViewById(R.id.sad_tab_reload_button); | |
| 157 } | |
| 158 | |
| 70 } | 159 } |
| OLD | NEW |