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 {
private Boolean mShouldLaunchResult;
@Before
public void setUp() throws Exception {
public void setUp() throws ExecutionException, InterruptedException {
BackgroundSyncLauncher.setGCMEnabled(false);
RecordHistogram.setDisabledForTests(true);
mLauncher = BackgroundSyncLauncher.create();
......@@ -47,7 +47,7 @@ public class BackgroundSyncLauncherTest {
mLauncher = null;
}
private Boolean shouldLaunchBrowserIfStoppedSync() {
private Boolean shouldLaunchBrowserIfStoppedSync() throws InterruptedException {
mShouldLaunchResult = false;
// Use a semaphore to wait for the callback to be called.
......@@ -60,23 +60,13 @@ public class BackgroundSyncLauncherTest {
};
BackgroundSyncLauncher.shouldLaunchBrowserIfStopped(callback);
try {
// Wait on the callback to be called.
semaphore.acquire();
} catch (InterruptedException e) {
throw new AssertionError("Failed to acquire semaphore", e);
}
// Wait on the callback to be called.
semaphore.acquire();
return mShouldLaunchResult;
}
private void waitForLaunchBrowserTask() {
try {
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);
}
private void waitForLaunchBrowserTask() throws ExecutionException, InterruptedException {
mLauncher.mLaunchBrowserIfStoppedTask.get();
}
@Test
......@@ -92,7 +82,7 @@ public class BackgroundSyncLauncherTest {
@Test
@SmallTest
@Feature({"BackgroundSync"})
public void testDefaultNoLaunch() {
public void testDefaultNoLaunch() throws InterruptedException {
Assert.assertFalse(shouldLaunchBrowserIfStoppedSync());
}
......@@ -100,7 +90,7 @@ public class BackgroundSyncLauncherTest {
@SmallTest
@Feature({"BackgroundSync"})
@RetryOnFailure
public void testSetLaunchWhenNextOnline() {
public void testSetLaunchWhenNextOnline() throws ExecutionException, InterruptedException {
Assert.assertFalse(shouldLaunchBrowserIfStoppedSync());
mLauncher.launchBrowserIfStopped(true, 0);
waitForLaunchBrowserTask();
......@@ -114,7 +104,8 @@ public class BackgroundSyncLauncherTest {
@SmallTest
@Feature({"BackgroundSync"})
@RetryOnFailure
public void testNewLauncherDisablesNextOnline() {
public void testNewLauncherDisablesNextOnline()
throws ExecutionException, InterruptedException {
mLauncher.launchBrowserIfStopped(true, 0);
waitForLaunchBrowserTask();
Assert.assertTrue(shouldLaunchBrowserIfStoppedSync());
......
......@@ -47,7 +47,7 @@ public class ProcessIsolationTest {
@DisableIf.Build(sdk_is_greater_than = 22, message = "crbug.com/517611")
@Feature({"Browser", "Security"})
@RetryOnFailure
public void testProcessIsolationForRenderers() throws InterruptedException {
public void testProcessIsolationForRenderers() throws InterruptedException, IOException {
int tabsCount = mActivityTestRule.getActivity().getCurrentTabModel().getCount();
// 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
......@@ -101,8 +101,6 @@ public class ProcessIsolationTest {
}
}
}
} catch (IOException ioe) {
throw new AssertionError("Failed to read ps output.", ioe);
} finally {
if (reader != null) {
try {
......
......@@ -121,7 +121,7 @@ public class ShareIntentTest {
@Test
@LargeTest
@RetryOnFailure
public void testShareIntent() throws ExecutionException {
public void testShareIntent() throws ExecutionException, InterruptedException {
MockChromeActivity mockActivity = ThreadUtils.runOnUiThreadBlocking(() -> {
// 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
......@@ -136,11 +136,7 @@ public class ShareIntentTest {
ThreadUtils.runOnUiThreadBlocking(() -> mockActivity.onShareMenuItemSelected(
true /* shareDirectly */, false /* isIncognito */));
try {
mockActivity.waitForFileCheck();
} catch (InterruptedException e) {
throw new AssertionError("Test thread was interrupted while trying to wait.", e);
}
mockActivity.waitForFileCheck();
ShareHelper.setLastShareComponentName(new ComponentName("", ""), null);
}
......
......@@ -1482,7 +1482,7 @@ public class TabsTest {
@Feature({"Android-TabSwitcher"})
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@RetryOnFailure
public void testToolbarSwipeOnlyTab() throws InterruptedException {
public void testToolbarSwipeOnlyTab() throws InterruptedException, TimeoutException {
final TabModel tabModel =
mActivityTestRule.getActivity().getTabModelSelector().getModel(false);
......@@ -1496,7 +1496,7 @@ public class TabsTest {
@Feature({"Android-TabSwitcher"})
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@RetryOnFailure
public void testToolbarSwipePrevTab() throws InterruptedException {
public void testToolbarSwipePrevTab() throws InterruptedException, TimeoutException {
ChromeTabUtils.newTabFromMenu(
InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity());
UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation());
......@@ -1514,7 +1514,7 @@ public class TabsTest {
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@RetryOnFailure
@DisabledTest(message = "crbug.com/802183")
public void testToolbarSwipeNextTab() throws InterruptedException {
public void testToolbarSwipeNextTab() throws InterruptedException, TimeoutException {
ChromeTabUtils.newTabFromMenu(
InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity());
ChromeTabUtils.switchTabInCurrentTabModel(mActivityTestRule.getActivity(), 0);
......@@ -1532,7 +1532,7 @@ public class TabsTest {
@Feature({"Android-TabSwitcher"})
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@RetryOnFailure
public void testToolbarSwipePrevTabNone() throws InterruptedException {
public void testToolbarSwipePrevTabNone() throws InterruptedException, TimeoutException {
ChromeTabUtils.newTabFromMenu(
InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity());
ChromeTabUtils.switchTabInCurrentTabModel(mActivityTestRule.getActivity(), 0);
......@@ -1550,7 +1550,7 @@ public class TabsTest {
@Feature({"Android-TabSwitcher"})
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@RetryOnFailure
public void testToolbarSwipeNextTabNone() throws InterruptedException {
public void testToolbarSwipeNextTabNone() throws InterruptedException, TimeoutException {
ChromeTabUtils.newTabFromMenu(
InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity());
UiUtils.settleDownUI(InstrumentationRegistry.getInstrumentation());
......@@ -1567,7 +1567,7 @@ public class TabsTest {
@Feature({"Android-TabSwitcher"})
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@RetryOnFailure
public void testToolbarSwipeNextThenPrevTab() throws InterruptedException {
public void testToolbarSwipeNextThenPrevTab() throws InterruptedException, TimeoutException {
ChromeTabUtils.newTabFromMenu(
InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity());
ChromeTabUtils.switchTabInCurrentTabModel(mActivityTestRule.getActivity(), 0);
......@@ -1588,7 +1588,8 @@ public class TabsTest {
@Feature({"Android-TabSwitcher"})
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@RetryOnFailure
public void testToolbarSwipeNextThenPrevTabIncognito() throws InterruptedException {
public void testToolbarSwipeNextThenPrevTabIncognito()
throws InterruptedException, TimeoutException {
mActivityTestRule.newIncognitoTabFromMenu();
mActivityTestRule.newIncognitoTabFromMenu();
ChromeTabUtils.switchTabInCurrentTabModel(mActivityTestRule.getActivity(), 0);
......@@ -1605,7 +1606,7 @@ public class TabsTest {
}
private void runToolbarSideSwipeTestOnCurrentModel(ScrollDirection direction, int finalIndex,
boolean expectsSelection) throws InterruptedException {
boolean expectsSelection) throws InterruptedException, TimeoutException {
final CallbackHelper selectCallback = new CallbackHelper();
final int id =
mActivityTestRule.getActivity().getCurrentTabModel().getTabAt(finalIndex).getId();
......@@ -1631,11 +1632,7 @@ public class TabsTest {
mActivityTestRule.getActivity().getCurrentTabModel().index());
if (expectsSelection) {
try {
selectCallback.waitForCallback(0);
} catch (TimeoutException e) {
throw new AssertionError("Tab selected event was never received", e);
}
selectCallback.waitForCallback(0);
ThreadUtils.runOnUiThreadBlocking(() -> {
TabModelSelector selector = mActivityTestRule.getActivity().getTabModelSelector();
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