Commit e6c42375 authored by Wei-Yin Chen (陳威尹)'s avatar Wei-Yin Chen (陳威尹) Committed by Commit Bot

Clean up instrumented tests in features/start_surface

This CL is a mechanical cleanup for instrumented tests under
org/chromium/chrome/features/start_surface, suggested by
Android Studio.

Bug: None
Change-Id: I3b6f24e4e2b510d3e6d7ba8d6e648c9480cfc418
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2123643
Commit-Queue: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754824}
parent dba0f746
......@@ -34,8 +34,10 @@ import org.chromium.ui.test.util.DummyUiActivityTestCase;
import java.util.concurrent.atomic.AtomicBoolean;
/** Tests for {@link BottomBarViewBinder}. */
@SuppressWarnings("ConstantConditions")
@RunWith(ChromeJUnit4ClassRunner.class)
public class BottomBarViewBinderTest extends DummyUiActivityTestCase {
@SuppressWarnings("unused")
private BottomBarCoordinator mBottomBarCoordinator;
private TabLayout mTabLayout;
private ViewGroup mParentView;
......@@ -54,8 +56,8 @@ public class BottomBarViewBinderTest extends DummyUiActivityTestCase {
new BottomBarCoordinator(getActivity(), mParentView, mPropertyModel);
});
mBottomBarView = (BottomBarView) mParentView.findViewById(R.id.ss_bottom_bar);
mTabLayout = (TabLayout) mBottomBarView.findViewById(R.id.bottom_tab_layout);
mBottomBarView = mParentView.findViewById(R.id.ss_bottom_bar);
mTabLayout = mBottomBarView.findViewById(R.id.bottom_tab_layout);
}
@Test
......
......@@ -7,6 +7,7 @@ package org.chromium.chrome.features.start_surface;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.BOTTOM_BAR_HEIGHT;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.FEED_SURFACE_COORDINATOR;
......@@ -72,13 +73,13 @@ public class ExploreSurfaceViewBinderTest {
public void testSetVisibilityWithoutFeedSurfaceCoordinator() {
assertFalse(mPropertyModel.get(IS_SHOWING_OVERVIEW));
assertFalse(mPropertyModel.get(IS_EXPLORE_SURFACE_VISIBLE));
assertEquals(mFeedSurfaceView.getParent(), null);
assertNull(mFeedSurfaceView.getParent());
TestThreadUtils.runOnUiThreadBlocking(() -> {
mPropertyModel.set(IS_SHOWING_OVERVIEW, true);
mPropertyModel.set(IS_EXPLORE_SURFACE_VISIBLE, true);
});
assertEquals(mFeedSurfaceView.getParent(), null);
assertNull(mFeedSurfaceView.getParent());
}
@Test
......@@ -86,7 +87,7 @@ public class ExploreSurfaceViewBinderTest {
public void testSetVisibilityWithFeedSurfaceCoordinator() {
assertFalse(mPropertyModel.get(IS_SHOWING_OVERVIEW));
assertFalse(mPropertyModel.get(IS_EXPLORE_SURFACE_VISIBLE));
assertEquals(mFeedSurfaceView.getParent(), null);
assertNull(mFeedSurfaceView.getParent());
TestThreadUtils.runOnUiThreadBlocking(() -> {
mPropertyModel.set(FEED_SURFACE_COORDINATOR, mFeedSurfaceCoordinator);
......@@ -97,12 +98,11 @@ public class ExploreSurfaceViewBinderTest {
assertEquals(mFeedSurfaceView.getVisibility(), View.VISIBLE);
TestThreadUtils.runOnUiThreadBlocking(
() -> { mPropertyModel.set(IS_EXPLORE_SURFACE_VISIBLE, false); });
assertEquals(mFeedSurfaceView.getParent(), null);
() -> mPropertyModel.set(IS_EXPLORE_SURFACE_VISIBLE, false));
assertNull(mFeedSurfaceView.getParent());
TestThreadUtils.runOnUiThreadBlocking(
() -> { mPropertyModel.set(IS_SHOWING_OVERVIEW, false); });
assertEquals(mFeedSurfaceView.getParent(), null);
TestThreadUtils.runOnUiThreadBlocking(() -> mPropertyModel.set(IS_SHOWING_OVERVIEW, false));
assertNull(mFeedSurfaceView.getParent());
}
@Test
......@@ -110,7 +110,7 @@ public class ExploreSurfaceViewBinderTest {
public void testSetVisibilityWithBottomBarVisible() {
assertFalse(mPropertyModel.get(IS_SHOWING_OVERVIEW));
assertFalse(mPropertyModel.get(IS_EXPLORE_SURFACE_VISIBLE));
assertEquals(mFeedSurfaceView.getParent(), null);
assertNull(mFeedSurfaceView.getParent());
TestThreadUtils.runOnUiThreadBlocking(() -> {
mPropertyModel.set(FEED_SURFACE_COORDINATOR, mFeedSurfaceCoordinator);
......@@ -129,12 +129,11 @@ public class ExploreSurfaceViewBinderTest {
assertEquals(layoutParams.topMargin, 20);
TestThreadUtils.runOnUiThreadBlocking(
() -> { mPropertyModel.set(IS_EXPLORE_SURFACE_VISIBLE, false); });
assertEquals(mFeedSurfaceView.getParent(), null);
() -> mPropertyModel.set(IS_EXPLORE_SURFACE_VISIBLE, false));
assertNull(mFeedSurfaceView.getParent());
TestThreadUtils.runOnUiThreadBlocking(
() -> { mPropertyModel.set(IS_SHOWING_OVERVIEW, false); });
assertEquals(mFeedSurfaceView.getParent(), null);
TestThreadUtils.runOnUiThreadBlocking(() -> mPropertyModel.set(IS_SHOWING_OVERVIEW, false));
assertNull(mFeedSurfaceView.getParent());
}
@Test
......@@ -142,26 +141,25 @@ public class ExploreSurfaceViewBinderTest {
public void testSetVisibilityAfterShowingOverview() {
assertFalse(mPropertyModel.get(IS_SHOWING_OVERVIEW));
assertFalse(mPropertyModel.get(IS_EXPLORE_SURFACE_VISIBLE));
assertEquals(mFeedSurfaceView.getParent(), null);
assertNull(mFeedSurfaceView.getParent());
TestThreadUtils.runOnUiThreadBlocking(() -> {
mPropertyModel.set(FEED_SURFACE_COORDINATOR, mFeedSurfaceCoordinator);
mPropertyModel.set(IS_SHOWING_OVERVIEW, true);
});
assertEquals(mFeedSurfaceView.getParent(), null);
assertNull(mFeedSurfaceView.getParent());
TestThreadUtils.runOnUiThreadBlocking(
() -> { mPropertyModel.set(IS_EXPLORE_SURFACE_VISIBLE, true); });
() -> mPropertyModel.set(IS_EXPLORE_SURFACE_VISIBLE, true));
assertNotEquals(mFeedSurfaceView.getParent(), null);
assertEquals(mFeedSurfaceView.getVisibility(), View.VISIBLE);
TestThreadUtils.runOnUiThreadBlocking(
() -> { mPropertyModel.set(IS_EXPLORE_SURFACE_VISIBLE, false); });
assertEquals(mFeedSurfaceView.getParent(), null);
() -> mPropertyModel.set(IS_EXPLORE_SURFACE_VISIBLE, false));
assertNull(mFeedSurfaceView.getParent());
TestThreadUtils.runOnUiThreadBlocking(
() -> { mPropertyModel.set(IS_SHOWING_OVERVIEW, false); });
assertEquals(mFeedSurfaceView.getParent(), null);
TestThreadUtils.runOnUiThreadBlocking(() -> mPropertyModel.set(IS_SHOWING_OVERVIEW, false));
assertNull(mFeedSurfaceView.getParent());
}
@Test
......@@ -169,25 +167,23 @@ public class ExploreSurfaceViewBinderTest {
public void testSetVisibilityBeforeShowingOverview() {
assertFalse(mPropertyModel.get(IS_SHOWING_OVERVIEW));
assertFalse(mPropertyModel.get(IS_EXPLORE_SURFACE_VISIBLE));
assertEquals(mFeedSurfaceView.getParent(), null);
assertNull(mFeedSurfaceView.getParent());
TestThreadUtils.runOnUiThreadBlocking(() -> {
mPropertyModel.set(FEED_SURFACE_COORDINATOR, mFeedSurfaceCoordinator);
mPropertyModel.set(IS_EXPLORE_SURFACE_VISIBLE, true);
});
assertEquals(mFeedSurfaceView.getParent(), null);
assertNull(mFeedSurfaceView.getParent());
TestThreadUtils.runOnUiThreadBlocking(
() -> { mPropertyModel.set(IS_SHOWING_OVERVIEW, true); });
TestThreadUtils.runOnUiThreadBlocking(() -> mPropertyModel.set(IS_SHOWING_OVERVIEW, true));
assertNotEquals(mFeedSurfaceView.getParent(), null);
assertEquals(mFeedSurfaceView.getVisibility(), View.VISIBLE);
TestThreadUtils.runOnUiThreadBlocking(
() -> { mPropertyModel.set(IS_SHOWING_OVERVIEW, false); });
assertEquals(mFeedSurfaceView.getParent(), null);
TestThreadUtils.runOnUiThreadBlocking(() -> mPropertyModel.set(IS_SHOWING_OVERVIEW, false));
assertNull(mFeedSurfaceView.getParent());
TestThreadUtils.runOnUiThreadBlocking(
() -> { mPropertyModel.set(IS_EXPLORE_SURFACE_VISIBLE, false); });
assertEquals(mFeedSurfaceView.getParent(), null);
() -> mPropertyModel.set(IS_EXPLORE_SURFACE_VISIBLE, false));
assertNull(mFeedSurfaceView.getParent());
}
}
......@@ -7,6 +7,7 @@ package org.chromium.chrome.features.start_surface;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.IS_SECONDARY_SURFACE_VISIBLE;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.IS_SHOWING_OVERVIEW;
......@@ -34,6 +35,7 @@ public class SecondaryTasksSurfaceViewBinderTest extends DummyUiActivityTestCase
private ViewGroup mParentView;
private View mTasksSurfaceView;
private PropertyModel mPropertyModel;
@SuppressWarnings({"FieldCanBeLocal", "unused"})
private PropertyModelChangeProcessor mPropertyModelChangeProcessor;
@Override
......@@ -60,10 +62,10 @@ public class SecondaryTasksSurfaceViewBinderTest extends DummyUiActivityTestCase
public void testSetVisibilityAfterShowingOverview() {
assertFalse(mPropertyModel.get(IS_SHOWING_OVERVIEW));
assertFalse(mPropertyModel.get(IS_SECONDARY_SURFACE_VISIBLE));
assertEquals(mTasksSurfaceView.getParent(), null);
assertNull(mTasksSurfaceView.getParent());
mPropertyModel.set(IS_SHOWING_OVERVIEW, true);
assertEquals(mTasksSurfaceView.getParent(), null);
assertNull(mTasksSurfaceView.getParent());
assertEquals(mTasksSurfaceView.getVisibility(), View.GONE);
mPropertyModel.set(IS_SECONDARY_SURFACE_VISIBLE, true);
......@@ -85,10 +87,10 @@ public class SecondaryTasksSurfaceViewBinderTest extends DummyUiActivityTestCase
public void testSetVisibilityBeforeShowingOverview() {
assertFalse(mPropertyModel.get(IS_SHOWING_OVERVIEW));
assertFalse(mPropertyModel.get(IS_SECONDARY_SURFACE_VISIBLE));
assertEquals(mTasksSurfaceView.getParent(), null);
assertNull(mTasksSurfaceView.getParent());
mPropertyModel.set(IS_SECONDARY_SURFACE_VISIBLE, true);
assertEquals(mTasksSurfaceView.getParent(), null);
assertNull(mTasksSurfaceView.getParent());
assertEquals(mTasksSurfaceView.getVisibility(), View.GONE);
mPropertyModel.set(IS_SHOWING_OVERVIEW, true);
......@@ -110,11 +112,11 @@ public class SecondaryTasksSurfaceViewBinderTest extends DummyUiActivityTestCase
public void testSetVisibilityWithTopBar() {
assertFalse(mPropertyModel.get(IS_SHOWING_OVERVIEW));
assertFalse(mPropertyModel.get(IS_SECONDARY_SURFACE_VISIBLE));
assertEquals(mTasksSurfaceView.getParent(), null);
assertNull(mTasksSurfaceView.getParent());
mPropertyModel.set(TOP_BAR_HEIGHT, 20);
mPropertyModel.set(IS_SHOWING_OVERVIEW, true);
assertEquals(mTasksSurfaceView.getParent(), null);
assertNull(mTasksSurfaceView.getParent());
assertEquals(mTasksSurfaceView.getVisibility(), View.GONE);
mPropertyModel.set(IS_SECONDARY_SURFACE_VISIBLE, true);
......
......@@ -85,6 +85,7 @@ public class StartSurfaceLayoutPerfTest {
@Rule
public TestRule mProcessor = new Features.InstrumentationProcessor();
@SuppressWarnings("FieldCanBeLocal")
private EmbeddedTestServer mTestServer;
private StartSurfaceLayout mStartSurfaceLayout;
private String mUrl;
......
......@@ -128,6 +128,7 @@ import java.util.concurrent.atomic.AtomicReference;
// clang-format off
/** Tests for the {@link StartSurfaceLayout} */
@SuppressWarnings("ConstantConditions")
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
"force-fieldtrials=Study/Group"})
......@@ -155,6 +156,8 @@ public class StartSurfaceLayoutTest {
@Rule
public ChromeRenderTestRule mRenderTestRule = new ChromeRenderTestRule();
@SuppressWarnings("FieldCanBeLocal")
private EmbeddedTestServer mTestServer;
private StartSurfaceLayout mStartSurfaceLayout;
private String mUrl;
private int mRepeat;
......@@ -166,15 +169,14 @@ public class StartSurfaceLayoutTest {
@Before
public void setUp() {
AccessibilityChecks.enable();
EmbeddedTestServer testServer =
EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext());
mTestServer = EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext());
// After setUp, Chrome is launched and has one NTP.
mActivityTestRule.startMainActivityFromLauncher();
Layout layout = mActivityTestRule.getActivity().getLayoutManager().getOverviewLayout();
assertTrue(layout instanceof StartSurfaceLayout);
mStartSurfaceLayout = (StartSurfaceLayout) layout;
mUrl = testServer.getURL("/chrome/test/data/android/navigate/simple.html");
mUrl = mTestServer.getURL("/chrome/test/data/android/navigate/simple.html");
mRepeat = 1;
mTabListDelegate = mStartSurfaceLayout.getStartSurfaceForTesting().getTabListDelegate();
......@@ -1016,7 +1018,7 @@ public class StartSurfaceLayoutTest {
@Test
@MediumTest
@CommandLineFlags.Add({BASE_PARAMS})
public void testThumbnailAspectRatio_default() throws Exception {
public void testThumbnailAspectRatio_default() {
prepareTabs(2, 0, mUrl);
enterTabSwitcher(mActivityTestRule.getActivity());
onView(withId(R.id.tab_list_view))
......@@ -1026,7 +1028,7 @@ public class StartSurfaceLayoutTest {
@Test
@MediumTest
@CommandLineFlags.Add({BASE_PARAMS + "/thumbnail_aspect_ratio/0.75"})
public void testThumbnailAspectRatio_point75() throws Exception {
public void testThumbnailAspectRatio_point75() {
prepareTabs(2, 0, mUrl);
enterTabSwitcher(mActivityTestRule.getActivity());
onView(withId(R.id.tab_list_view))
......@@ -1269,7 +1271,7 @@ public class StartSurfaceLayoutTest {
@Features.DisableFeatures({ChromeFeatureList.TAB_TO_GTS_ANIMATION + "<Study",
ChromeFeatureList.CLOSE_TAB_SUGGESTIONS})
@CommandLineFlags.Add({BASE_PARAMS + "/tab_grid_layout_android_new_tab/NewTabVariation"})
public void testNewTabVariation() throws InterruptedException {
public void testNewTabVariation() {
// clang-format on
ChromeTabbedActivity cta = mActivityTestRule.getActivity();
prepareTabs(2, 0, null);
......@@ -1345,7 +1347,7 @@ public class StartSurfaceLayoutTest {
@MediumTest
@CommandLineFlags.Add({BASE_PARAMS})
@EnableFeatures({ChromeFeatureList.TAB_GROUPS_ANDROID})
public void testSwipeToDismiss_GTS() throws Exception {
public void testSwipeToDismiss_GTS() {
ChromeTabbedActivity cta = mActivityTestRule.getActivity();
// Create 3 tabs and merge the first two tabs into one group.
createTabs(cta, false, 3);
......@@ -1564,7 +1566,7 @@ public class StartSurfaceLayoutTest {
Drawable googleDrawable = iconImageView.getDrawable();
TestThreadUtils.runOnUiThreadBlocking(
() -> { TemplateUrlServiceFactory.get().setSearchEngine("yahoo.com"); });
() -> TemplateUrlServiceFactory.get().setSearchEngine("yahoo.com"));
assertNotEquals(googleDrawable, iconImageView.getDrawable());
}
......@@ -1710,7 +1712,6 @@ public class StartSurfaceLayoutTest {
new FileOutputStream(TabContentManager.getTabThumbnailFileJpeg(tab.getId()));
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, outputStream);
outputStream.close();
Bitmap decodedBitmap = TabContentManager.getJpegForTab(tab.getId());
}
private void verifyAllThumbnailHasAspectRatio(double ratio) {
......
......@@ -22,6 +22,7 @@ import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.chromium.chrome.test.util.ViewUtils.waitForView;
......@@ -209,7 +210,7 @@ public class StartSurfaceTest {
.findViewById(org.chromium.chrome.tab_ui.R.id.more_tabs)
.performClick());
} catch (ExecutionException e) {
assertTrue(false);
fail();
}
onView(isRoot()).check((r, e) -> {
waitForView((ViewGroup) r,
......@@ -269,7 +270,7 @@ public class StartSurfaceTest {
.findViewById(org.chromium.chrome.tab_ui.R.id.more_tabs)
.performClick());
} catch (ExecutionException e) {
assertTrue(false);
fail();
}
onView(isRoot()).check((r, e) -> {
waitForView((ViewGroup) r,
......@@ -374,7 +375,7 @@ public class StartSurfaceTest {
mActivityTestRule.getActivity().getTabModelSelector().getCurrentModel().getCount(),
equalTo(1));
ViewGroup mvTilesContainer = (ViewGroup) mActivityTestRule.getActivity().findViewById(
ViewGroup mvTilesContainer = mActivityTestRule.getActivity().findViewById(
org.chromium.chrome.tab_ui.R.id.mv_tiles_layout);
assertTrue(mvTilesContainer.getChildCount() > 0);
......@@ -386,7 +387,7 @@ public class StartSurfaceTest {
TestThreadUtils.runOnUiThreadBlocking(
() -> mvTilesContainer.getChildAt(0).performClick());
} catch (ExecutionException e) {
assertTrue(false);
fail();
}
hideWatcher.waitForBehavior();
assertThat(
......
......@@ -7,6 +7,7 @@ package org.chromium.chrome.features.start_surface;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.BOTTOM_BAR_HEIGHT;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.IS_SHOWING_OVERVIEW;
......@@ -34,6 +35,7 @@ public class TasksSurfaceViewBinderTest extends DummyUiActivityTestCase {
private ViewGroup mParentView;
private View mTasksSurfaceView;
private PropertyModel mPropertyModel;
@SuppressWarnings({"FieldCanBeLocal", "unused"})
private PropertyModelChangeProcessor mPropertyModelChangeProcessor;
@Override
......@@ -59,7 +61,7 @@ public class TasksSurfaceViewBinderTest extends DummyUiActivityTestCase {
@SmallTest
public void testSetShowAndHideOverview() {
assertFalse(mPropertyModel.get(IS_SHOWING_OVERVIEW));
assertEquals(mTasksSurfaceView.getParent(), null);
assertNull(mTasksSurfaceView.getParent());
mPropertyModel.set(BOTTOM_BAR_HEIGHT, 10);
mPropertyModel.set(TOP_BAR_HEIGHT, 20);
......
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