Commit 2b6c4fef authored by Troy Hildebrandt's avatar Troy Hildebrandt Committed by Commit Bot

Fix NewApi Lint errors for Android chrome/browser tests.

NewApi warnings were suppressed accidentally and an AssertionError
constructor that requires API 19 was used. The NewApi warnings are back,
so this fix avoids using the AssertionError and throws the exceptions
as they are.

Bug: 805509,803484
Change-Id: I1f342d06cb7e4e24ea816803d0e97dbeab6f59d9
Reviewed-on: https://chromium-review.googlesource.com/884385
Commit-Queue: Troy Hildebrandt <thildebr@chromium.org>
Reviewed-by: default avatarMaria Khomenko <mariakhomenko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#531705}
parent fbb0cc0f
...@@ -29,7 +29,7 @@ public class BackgroundSyncLauncherTest { ...@@ -29,7 +29,7 @@ public class BackgroundSyncLauncherTest {
private Boolean mShouldLaunchResult; private Boolean mShouldLaunchResult;
@Before @Before
public void setUp() throws Exception { public void setUp() throws ExecutionException, InterruptedException {
BackgroundSyncLauncher.setGCMEnabled(false); BackgroundSyncLauncher.setGCMEnabled(false);
RecordHistogram.setDisabledForTests(true); RecordHistogram.setDisabledForTests(true);
mLauncher = BackgroundSyncLauncher.create(); mLauncher = BackgroundSyncLauncher.create();
...@@ -47,7 +47,7 @@ public class BackgroundSyncLauncherTest { ...@@ -47,7 +47,7 @@ public class BackgroundSyncLauncherTest {
mLauncher = null; mLauncher = null;
} }
private Boolean shouldLaunchBrowserIfStoppedSync() { private Boolean shouldLaunchBrowserIfStoppedSync() throws InterruptedException {
mShouldLaunchResult = false; mShouldLaunchResult = false;
// Use a semaphore to wait for the callback to be called. // Use a semaphore to wait for the callback to be called.
...@@ -60,23 +60,13 @@ public class BackgroundSyncLauncherTest { ...@@ -60,23 +60,13 @@ public class BackgroundSyncLauncherTest {
}; };
BackgroundSyncLauncher.shouldLaunchBrowserIfStopped(callback); BackgroundSyncLauncher.shouldLaunchBrowserIfStopped(callback);
try {
// Wait on the callback to be called. // Wait on the callback to be called.
semaphore.acquire(); semaphore.acquire();
} catch (InterruptedException e) {
throw new AssertionError("Failed to acquire semaphore", e);
}
return mShouldLaunchResult; return mShouldLaunchResult;
} }
private void waitForLaunchBrowserTask() { private void waitForLaunchBrowserTask() throws ExecutionException, InterruptedException {
try {
mLauncher.mLaunchBrowserIfStoppedTask.get(); mLauncher.mLaunchBrowserIfStoppedTask.get();
} catch (InterruptedException e) {
throw new AssertionError("Launch task was interrupted", e);
} catch (ExecutionException e) {
throw new AssertionError("Launch task had execution exception", e);
}
} }
@Test @Test
...@@ -92,7 +82,7 @@ public class BackgroundSyncLauncherTest { ...@@ -92,7 +82,7 @@ public class BackgroundSyncLauncherTest {
@Test @Test
@SmallTest @SmallTest
@Feature({"BackgroundSync"}) @Feature({"BackgroundSync"})
public void testDefaultNoLaunch() { public void testDefaultNoLaunch() throws InterruptedException {
Assert.assertFalse(shouldLaunchBrowserIfStoppedSync()); Assert.assertFalse(shouldLaunchBrowserIfStoppedSync());
} }
...@@ -100,7 +90,7 @@ public class BackgroundSyncLauncherTest { ...@@ -100,7 +90,7 @@ public class BackgroundSyncLauncherTest {
@SmallTest @SmallTest
@Feature({"BackgroundSync"}) @Feature({"BackgroundSync"})
@RetryOnFailure @RetryOnFailure
public void testSetLaunchWhenNextOnline() { public void testSetLaunchWhenNextOnline() throws ExecutionException, InterruptedException {
Assert.assertFalse(shouldLaunchBrowserIfStoppedSync()); Assert.assertFalse(shouldLaunchBrowserIfStoppedSync());
mLauncher.launchBrowserIfStopped(true, 0); mLauncher.launchBrowserIfStopped(true, 0);
waitForLaunchBrowserTask(); waitForLaunchBrowserTask();
...@@ -114,7 +104,8 @@ public class BackgroundSyncLauncherTest { ...@@ -114,7 +104,8 @@ public class BackgroundSyncLauncherTest {
@SmallTest @SmallTest
@Feature({"BackgroundSync"}) @Feature({"BackgroundSync"})
@RetryOnFailure @RetryOnFailure
public void testNewLauncherDisablesNextOnline() { public void testNewLauncherDisablesNextOnline()
throws ExecutionException, InterruptedException {
mLauncher.launchBrowserIfStopped(true, 0); mLauncher.launchBrowserIfStopped(true, 0);
waitForLaunchBrowserTask(); waitForLaunchBrowserTask();
Assert.assertTrue(shouldLaunchBrowserIfStoppedSync()); Assert.assertTrue(shouldLaunchBrowserIfStoppedSync());
......
...@@ -47,7 +47,7 @@ public class ProcessIsolationTest { ...@@ -47,7 +47,7 @@ public class ProcessIsolationTest {
@DisableIf.Build(sdk_is_greater_than = 22, message = "crbug.com/517611") @DisableIf.Build(sdk_is_greater_than = 22, message = "crbug.com/517611")
@Feature({"Browser", "Security"}) @Feature({"Browser", "Security"})
@RetryOnFailure @RetryOnFailure
public void testProcessIsolationForRenderers() throws InterruptedException { public void testProcessIsolationForRenderers() throws InterruptedException, IOException {
int tabsCount = mActivityTestRule.getActivity().getCurrentTabModel().getCount(); int tabsCount = mActivityTestRule.getActivity().getCurrentTabModel().getCount();
// The ActivityManager can be used to retrieve the current processes, but the reported UID // The ActivityManager can be used to retrieve the current processes, but the reported UID
// in the RunningAppProcessInfo for isolated processes is the same as the parent process // in the RunningAppProcessInfo for isolated processes is the same as the parent process
...@@ -101,8 +101,6 @@ public class ProcessIsolationTest { ...@@ -101,8 +101,6 @@ public class ProcessIsolationTest {
} }
} }
} }
} catch (IOException ioe) {
throw new AssertionError("Failed to read ps output.", ioe);
} finally { } finally {
if (reader != null) { if (reader != null) {
try { try {
......
...@@ -121,7 +121,7 @@ public class ShareIntentTest { ...@@ -121,7 +121,7 @@ public class ShareIntentTest {
@Test @Test
@LargeTest @LargeTest
@RetryOnFailure @RetryOnFailure
public void testShareIntent() throws ExecutionException { public void testShareIntent() throws ExecutionException, InterruptedException {
MockChromeActivity mockActivity = ThreadUtils.runOnUiThreadBlocking(() -> { MockChromeActivity mockActivity = ThreadUtils.runOnUiThreadBlocking(() -> {
// Sets a test component as last shared and "shareDirectly" option is set so that // Sets a test component as last shared and "shareDirectly" option is set so that
// the share selector menu is not opened. The start activity is overriden, so the // the share selector menu is not opened. The start activity is overriden, so the
...@@ -136,11 +136,7 @@ public class ShareIntentTest { ...@@ -136,11 +136,7 @@ public class ShareIntentTest {
ThreadUtils.runOnUiThreadBlocking(() -> mockActivity.onShareMenuItemSelected( ThreadUtils.runOnUiThreadBlocking(() -> mockActivity.onShareMenuItemSelected(
true /* shareDirectly */, false /* isIncognito */)); true /* shareDirectly */, false /* isIncognito */));
try {
mockActivity.waitForFileCheck(); mockActivity.waitForFileCheck();
} catch (InterruptedException e) {
throw new AssertionError("Test thread was interrupted while trying to wait.", e);
}
ShareHelper.setLastShareComponentName(new ComponentName("", ""), null); ShareHelper.setLastShareComponentName(new ComponentName("", ""), null);
} }
......
...@@ -1482,7 +1482,7 @@ public class TabsTest { ...@@ -1482,7 +1482,7 @@ public class TabsTest {
@Feature({"Android-TabSwitcher"}) @Feature({"Android-TabSwitcher"})
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@RetryOnFailure @RetryOnFailure
public void testToolbarSwipeOnlyTab() throws InterruptedException { public void testToolbarSwipeOnlyTab() throws InterruptedException, TimeoutException {
final TabModel tabModel = final TabModel tabModel =
mActivityTestRule.getActivity().getTabModelSelector().getModel(false); mActivityTestRule.getActivity().getTabModelSelector().getModel(false);
...@@ -1496,7 +1496,7 @@ public class TabsTest { ...@@ -1496,7 +1496,7 @@ public class TabsTest {
@Feature({"Android-TabSwitcher"}) @Feature({"Android-TabSwitcher"})
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@RetryOnFailure @RetryOnFailure
public void testToolbarSwipePrevTab() throws InterruptedException { public void testToolbarSwipePrevTab() throws InterruptedException, TimeoutException {
ChromeTabUtils.newTabFromMenu( ChromeTabUtils.newTabFromMenu(
InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity()); InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity());
UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation()); UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation());
...@@ -1514,7 +1514,7 @@ public class TabsTest { ...@@ -1514,7 +1514,7 @@ public class TabsTest {
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@RetryOnFailure @RetryOnFailure
@DisabledTest(message = "crbug.com/802183") @DisabledTest(message = "crbug.com/802183")
public void testToolbarSwipeNextTab() throws InterruptedException { public void testToolbarSwipeNextTab() throws InterruptedException, TimeoutException {
ChromeTabUtils.newTabFromMenu( ChromeTabUtils.newTabFromMenu(
InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity()); InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity());
ChromeTabUtils.switchTabInCurrentTabModel(mActivityTestRule.getActivity(), 0); ChromeTabUtils.switchTabInCurrentTabModel(mActivityTestRule.getActivity(), 0);
...@@ -1532,7 +1532,7 @@ public class TabsTest { ...@@ -1532,7 +1532,7 @@ public class TabsTest {
@Feature({"Android-TabSwitcher"}) @Feature({"Android-TabSwitcher"})
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@RetryOnFailure @RetryOnFailure
public void testToolbarSwipePrevTabNone() throws InterruptedException { public void testToolbarSwipePrevTabNone() throws InterruptedException, TimeoutException {
ChromeTabUtils.newTabFromMenu( ChromeTabUtils.newTabFromMenu(
InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity()); InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity());
ChromeTabUtils.switchTabInCurrentTabModel(mActivityTestRule.getActivity(), 0); ChromeTabUtils.switchTabInCurrentTabModel(mActivityTestRule.getActivity(), 0);
...@@ -1550,7 +1550,7 @@ public class TabsTest { ...@@ -1550,7 +1550,7 @@ public class TabsTest {
@Feature({"Android-TabSwitcher"}) @Feature({"Android-TabSwitcher"})
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@RetryOnFailure @RetryOnFailure
public void testToolbarSwipeNextTabNone() throws InterruptedException { public void testToolbarSwipeNextTabNone() throws InterruptedException, TimeoutException {
ChromeTabUtils.newTabFromMenu( ChromeTabUtils.newTabFromMenu(
InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity()); InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity());
UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation()); UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation());
...@@ -1567,7 +1567,7 @@ public class TabsTest { ...@@ -1567,7 +1567,7 @@ public class TabsTest {
@Feature({"Android-TabSwitcher"}) @Feature({"Android-TabSwitcher"})
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@RetryOnFailure @RetryOnFailure
public void testToolbarSwipeNextThenPrevTab() throws InterruptedException { public void testToolbarSwipeNextThenPrevTab() throws InterruptedException, TimeoutException {
ChromeTabUtils.newTabFromMenu( ChromeTabUtils.newTabFromMenu(
InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity()); InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity());
ChromeTabUtils.switchTabInCurrentTabModel(mActivityTestRule.getActivity(), 0); ChromeTabUtils.switchTabInCurrentTabModel(mActivityTestRule.getActivity(), 0);
...@@ -1588,7 +1588,8 @@ public class TabsTest { ...@@ -1588,7 +1588,8 @@ public class TabsTest {
@Feature({"Android-TabSwitcher"}) @Feature({"Android-TabSwitcher"})
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@RetryOnFailure @RetryOnFailure
public void testToolbarSwipeNextThenPrevTabIncognito() throws InterruptedException { public void testToolbarSwipeNextThenPrevTabIncognito()
throws InterruptedException, TimeoutException {
mActivityTestRule.newIncognitoTabFromMenu(); mActivityTestRule.newIncognitoTabFromMenu();
mActivityTestRule.newIncognitoTabFromMenu(); mActivityTestRule.newIncognitoTabFromMenu();
ChromeTabUtils.switchTabInCurrentTabModel(mActivityTestRule.getActivity(), 0); ChromeTabUtils.switchTabInCurrentTabModel(mActivityTestRule.getActivity(), 0);
...@@ -1605,7 +1606,7 @@ public class TabsTest { ...@@ -1605,7 +1606,7 @@ public class TabsTest {
} }
private void runToolbarSideSwipeTestOnCurrentModel(ScrollDirection direction, int finalIndex, private void runToolbarSideSwipeTestOnCurrentModel(ScrollDirection direction, int finalIndex,
boolean expectsSelection) throws InterruptedException { boolean expectsSelection) throws InterruptedException, TimeoutException {
final CallbackHelper selectCallback = new CallbackHelper(); final CallbackHelper selectCallback = new CallbackHelper();
final int id = final int id =
mActivityTestRule.getActivity().getCurrentTabModel().getTabAt(finalIndex).getId(); mActivityTestRule.getActivity().getCurrentTabModel().getTabAt(finalIndex).getId();
...@@ -1631,11 +1632,7 @@ public class TabsTest { ...@@ -1631,11 +1632,7 @@ public class TabsTest {
mActivityTestRule.getActivity().getCurrentTabModel().index()); mActivityTestRule.getActivity().getCurrentTabModel().index());
if (expectsSelection) { if (expectsSelection) {
try {
selectCallback.waitForCallback(0); selectCallback.waitForCallback(0);
} catch (TimeoutException e) {
throw new AssertionError("Tab selected event was never received", e);
}
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(() -> {
TabModelSelector selector = mActivityTestRule.getActivity().getTabModelSelector(); TabModelSelector selector = mActivityTestRule.getActivity().getTabModelSelector();
for (TabModel tabModel : selector.getModels()) { for (TabModel tabModel : selector.getModels()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment