Commit 8d23be52 authored by gogerald's avatar gogerald Committed by Commit Bot

[StartSurface] Add integration tests for more single start surface paths

Bug: 1051226
Change-Id: Idd065587ccd944ae8dfbc890887d939fea685c84
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2050579
Commit-Queue: Ganggui Tang <gogerald@chromium.org>
Commit-Queue: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
Auto-Submit: Ganggui Tang <gogerald@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740485}
parent 5ba1995f
......@@ -7,19 +7,28 @@ package org.chromium.chrome.features.start_surface;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.Espresso.pressBack;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.pressKey;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.Visibility.GONE;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isRoot;
import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withParent;
import static org.hamcrest.CoreMatchers.allOf;
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.chromium.chrome.test.util.ViewUtils.waitForView;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.filters.MediumTest;
import android.view.KeyEvent;
import android.view.ViewGroup;
import org.junit.Before;
......@@ -39,8 +48,10 @@ import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.OverviewModeBehaviorWatcher;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.ui.test.util.UiRestriction;
import java.util.concurrent.ExecutionException;
......@@ -61,10 +72,17 @@ public class StartSurfaceTest {
@Rule
public TestRule mProcessor = new Features.InstrumentationProcessor();
private String mUrl;
@Before
public void setUp() {
CachedFeatureFlags.setStartSurfaceEnabledForTesting(true);
EmbeddedTestServer testServer =
EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext());
mActivityTestRule.startMainActivityFromLauncher();
mUrl = testServer.getURL("/chrome/test/data/android/navigate/simple.html");
}
@Test
......@@ -126,7 +144,9 @@ public class StartSurfaceTest {
@MediumTest
@Feature({"StartSurface"})
@CommandLineFlags.Add({BASE_PARAMS + "/single"})
public void testShowAndHideSingleSurface() {
public void testShowAndHideHomePageInSingleSurface() {
// TODO(crbug.com/1025296): Set cached flag before starting the activity and mimic clicking
// the 'home' button to show the single start surface home page.
TestThreadUtils.runOnUiThreadBlocking(
()
-> mActivityTestRule.getActivity()
......@@ -139,12 +159,16 @@ public class StartSurfaceTest {
onView(withId(org.chromium.chrome.start_surface.R.id.primary_tasks_surface_view))
.check(matches(isDisplayed()));
onView(withId(org.chromium.chrome.start_surface.R.id.search_box_text))
.check(matches(isDisplayed()));
onView(withId(org.chromium.chrome.tab_ui.R.id.mv_tiles_container))
.check(matches(isDisplayed()));
onView(withId(org.chromium.chrome.tab_ui.R.id.tab_switcher_title))
.check(matches(isDisplayed()));
onView(withId(org.chromium.chrome.tab_ui.R.id.carousel_tab_switcher_container))
.check(matches(isDisplayed()));
onView(withId(org.chromium.chrome.tab_ui.R.id.tasks_surface_body))
.check(matches(isDisplayed()));
// Note that onView(R.id.more_tabs).perform(click()) can not be used since it requires 90
// percent of the view's area is displayed to the users. However, this view has negative
......@@ -170,9 +194,85 @@ public class StartSurfaceTest {
withId(org.chromium.chrome.start_surface.R.id.primary_tasks_surface_view));
});
OverviewModeBehaviorWatcher hideWatcher =
TabUiTestHelper.createOverviewHideWatcher(mActivityTestRule.getActivity());
onView(allOf(withParent(withId(
org.chromium.chrome.tab_ui.R.id.carousel_tab_switcher_container)),
withId(org.chromium.chrome.tab_ui.R.id.tab_list_view)))
.perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
hideWatcher.waitForBehavior();
}
@Test
@MediumTest
@Feature({"StartSurface"})
@CommandLineFlags.Add({BASE_PARAMS + "/single"})
public void testShowAndHideTabSwitcherInSingleSurface() {
TabUiTestHelper.enterTabSwitcher(mActivityTestRule.getActivity());
onView(withId(org.chromium.chrome.start_surface.R.id.secondary_tasks_surface_view))
.check(matches(isDisplayed()));
OverviewModeBehaviorWatcher hideWatcher =
TabUiTestHelper.createOverviewHideWatcher(mActivityTestRule.getActivity());
onView(allOf(withParent(withId(org.chromium.chrome.tab_ui.R.id.tasks_surface_body)),
withId(org.chromium.chrome.tab_ui.R.id.tab_list_view)))
.perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
hideWatcher.waitForBehavior();
}
@Test
@MediumTest
@Feature({"StartSurface"})
@CommandLineFlags.Add({BASE_PARAMS + "/single"})
public void testSearchInSingleSurface() {
// TODO(crbug.com/1025296): Set cached flag before starting the activity and mimic clicking
// the 'home' button to show the single start surface home page.
TestThreadUtils.runOnUiThreadBlocking(
() -> mActivityTestRule.getActivity().getLayoutManager().hideOverview(false));
assertFalse(mActivityTestRule.getActivity().getLayoutManager().overviewVisible());
()
-> mActivityTestRule.getActivity()
.getStartSurface()
.getController()
.setOverviewState(OverviewModeState.SHOWING_HOMEPAGE));
TestThreadUtils.runOnUiThreadBlocking(
() -> mActivityTestRule.getActivity().getLayoutManager().showOverview(false));
assertTrue(mActivityTestRule.getActivity().getLayoutManager().overviewVisible());
assertThat(
mActivityTestRule.getActivity().getTabModelSelector().getCurrentModel().getCount(),
equalTo(1));
OverviewModeBehaviorWatcher hideWatcher =
TabUiTestHelper.createOverviewHideWatcher(mActivityTestRule.getActivity());
onView(withId(org.chromium.chrome.start_surface.R.id.search_box_text))
.perform(typeText(mUrl));
onView(withId(org.chromium.chrome.start_surface.R.id.url_bar))
.perform(pressKey(KeyEvent.KEYCODE_ENTER));
hideWatcher.waitForBehavior();
assertThat(
mActivityTestRule.getActivity().getTabModelSelector().getCurrentModel().getCount(),
equalTo(2));
// Search in incognito mode.
TestThreadUtils.runOnUiThreadBlocking(
()
-> mActivityTestRule.getActivity()
.getStartSurface()
.getController()
.setOverviewState(OverviewModeState.SHOWING_HOMEPAGE));
TestThreadUtils.runOnUiThreadBlocking(
() -> mActivityTestRule.getActivity().getLayoutManager().showOverview(false));
onView(withId(org.chromium.chrome.start_surface.R.id.incognito_switch)).perform(click());
assertTrue(mActivityTestRule.getActivity().getTabModelSelector().isIncognitoSelected());
hideWatcher = TabUiTestHelper.createOverviewHideWatcher(mActivityTestRule.getActivity());
onView(allOf(withId(org.chromium.chrome.start_surface.R.id.search_box_text), isDisplayed()))
.perform(typeText(mUrl));
onView(withId(org.chromium.chrome.start_surface.R.id.url_bar))
.perform(pressKey(KeyEvent.KEYCODE_ENTER));
hideWatcher.waitForBehavior();
assertThat(
mActivityTestRule.getActivity().getTabModelSelector().getCurrentModel().getCount(),
equalTo(1));
}
@Test
......
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