Commit 4062808b authored by ckitagawa's avatar ckitagawa Committed by Commit Bot

[Start Surface] Add missing test for testing no tabs view

This CL adds a variant of StartSurfaceTest where no tabs are present.
In this situation the UI for tabs shouldn't be shown, but the remainder
of the UI should remain unchanged.

This automates a P1 manual testcase.

Bug: 1091317
Change-Id: Ibbd08b668228c347e6d4c2e129ab2284fefe8a83
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2391614Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Commit-Queue: Calder Kitagawa <ckitagawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807546}
parent fad891d5
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.features.start_surface;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.Visibility.GONE;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.chromium.chrome.browser.tasks.ReturnToChromeExperimentsUtil.TAB_SWITCHER_ON_RETURN_MS;
import android.content.Intent;
import androidx.test.filters.MediumTest;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.params.ParameterAnnotations;
import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate;
import org.chromium.base.test.params.ParameterSet;
import org.chromium.base.test.params.ParameterizedRunner;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.flags.CachedFeatureFlags;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.tasks.ReturnToChromeExperimentsUtil;
import org.chromium.chrome.start_surface.R;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.ui.test.util.UiRestriction;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
/**
* Integration tests of the {@link StartSurface} for cases where there are no tabs. See {@link
* StartSurfaceTest} for test that have tabs.
*/
@RunWith(ParameterizedRunner.class)
@UseRunnerDelegate(ChromeJUnit4RunnerDelegate.class)
@Restriction(
{UiRestriction.RESTRICTION_TYPE_PHONE, Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE})
@EnableFeatures({ChromeFeatureList.START_SURFACE_ANDROID + "<Study"})
@CommandLineFlags.
Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, "force-fieldtrials=Study/Group"})
public class StartSurfaceNoTabsTest {
@ParameterAnnotations.ClassParameter
private static List<ParameterSet> sClassParams =
Arrays.asList(new ParameterSet().value(false, false).name("NoInstant_NoReturn"),
new ParameterSet().value(true, false).name("Instant_NoReturn"),
new ParameterSet().value(false, true).name("NoInstant_Return"),
new ParameterSet().value(true, true).name("Instant_Return"));
private static final String BASE_PARAMS =
"force-fieldtrial-params=Study.Group:start_surface_variation";
@Rule
public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
private final boolean mImmediateReturn;
public StartSurfaceNoTabsTest(boolean useInstantStart, boolean immediateReturn) {
CachedFeatureFlags.setForTesting(ChromeFeatureList.INSTANT_START, useInstantStart);
mImmediateReturn = immediateReturn;
}
/**
* Only launch Chrome without waiting for a current tab.
* This test could not use {@link ChromeActivityTestRule#startMainActivityFromLauncher()}
* because of its {@link org.chromium.chrome.browser.tab.Tab} dependency.
*/
private void startMainActivityFromLauncher() {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
mActivityTestRule.prepareUrlIntent(intent, null);
mActivityTestRule.startActivityCompletely(intent);
}
@Before
public void setUp() throws IOException {
if (mImmediateReturn) {
TAB_SWITCHER_ON_RETURN_MS.setForTesting(0);
assertEquals(0, ReturnToChromeExperimentsUtil.TAB_SWITCHER_ON_RETURN_MS.getValue());
assertTrue(ReturnToChromeExperimentsUtil.shouldShowTabSwitcher(-1));
} else {
assertFalse(ReturnToChromeExperimentsUtil.shouldShowTabSwitcher(-1));
}
startMainActivityFromLauncher();
}
@Test
@MediumTest
@Feature({"StartSurface"})
// clang-format off
@CommandLineFlags.Add({BASE_PARAMS + "/single"})
public void testShow_SingleAsHomepage_NoTabs() {
// clang-format on
CriteriaHelper.pollUiThread(
()
-> mActivityTestRule.getActivity().getLayoutManager() != null
&& mActivityTestRule.getActivity().getLayoutManager().overviewVisible());
onView(withId(R.id.primary_tasks_surface_view)).check(matches(isDisplayed()));
onView(withId(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(withEffectiveVisibility(GONE)));
onView(withId(org.chromium.chrome.tab_ui.R.id.carousel_tab_switcher_container))
.check(matches(withEffectiveVisibility(GONE)));
onView(withId(org.chromium.chrome.tab_ui.R.id.more_tabs))
.check(matches(withEffectiveVisibility(GONE)));
onView(withId(org.chromium.chrome.tab_ui.R.id.tasks_surface_body))
.check(matches(isDisplayed()));
onView(withId(org.chromium.chrome.tab_ui.R.id.trendy_terms_recycler_view))
.check(matches(withEffectiveVisibility(GONE)));
}
@Test
@MediumTest
@Feature({"StartSurface"})
// clang-format off
@CommandLineFlags.Add({BASE_PARAMS + "/single/exclude_mv_tiles/true" +
"/show_last_active_tab_only/true/show_stack_tab_switcher/true" +
"/open_ntp_instead_of_start/true"})
public void testShow_SingleAsHomepage_V2_NoTabs() {
// clang-format on
CriteriaHelper.pollUiThread(
()
-> mActivityTestRule.getActivity().getLayoutManager() != null
&& mActivityTestRule.getActivity().getLayoutManager().overviewVisible());
onView(withId(R.id.primary_tasks_surface_view)).check(matches(isDisplayed()));
onView(withId(R.id.search_box_text)).check(matches(isDisplayed()));
onView(withId(org.chromium.chrome.tab_ui.R.id.mv_tiles_container))
.check(matches(withEffectiveVisibility(GONE)));
onView(withId(org.chromium.chrome.tab_ui.R.id.tab_switcher_title))
.check(matches(withEffectiveVisibility(GONE)));
onView(withId(org.chromium.chrome.tab_ui.R.id.carousel_tab_switcher_container))
.check(matches(withEffectiveVisibility(GONE)));
onView(withId(org.chromium.chrome.tab_ui.R.id.single_tab_view))
.check(matches(withEffectiveVisibility(GONE)));
onView(withId(org.chromium.chrome.tab_ui.R.id.tasks_surface_body))
.check(matches(isDisplayed()));
onView(withId(org.chromium.chrome.tab_ui.R.id.trendy_terms_recycler_view))
.check(matches(withEffectiveVisibility(GONE)));
onView(withId(org.chromium.chrome.tab_ui.R.id.incognito_switch))
.check(matches(withEffectiveVisibility(GONE)));
onView(withId(org.chromium.chrome.tab_ui.R.id.more_tabs))
.check(matches(withEffectiveVisibility(GONE)));
}
@Test
@MediumTest
@Feature({"StartSurface"})
// clang-format off
@CommandLineFlags.Add({BASE_PARAMS + "/single/exclude_mv_tiles/true" +
"/show_last_active_tab_only/true/open_ntp_instead_of_start/true"})
public void testShow_SingleAsHomepage_SingleTabSwitcher_NoTabs() {
// clang-format on
CriteriaHelper.pollUiThread(
()
-> mActivityTestRule.getActivity().getLayoutManager() != null
&& mActivityTestRule.getActivity().getLayoutManager().overviewVisible());
onView(withId(R.id.primary_tasks_surface_view)).check(matches(isDisplayed()));
onView(withId(R.id.search_box_text)).check(matches(isDisplayed()));
onView(withId(org.chromium.chrome.tab_ui.R.id.mv_tiles_container))
.check(matches(withEffectiveVisibility(GONE)));
onView(withId(org.chromium.chrome.tab_ui.R.id.tab_switcher_title))
.check(matches(withEffectiveVisibility(GONE)));
onView(withId(org.chromium.chrome.tab_ui.R.id.carousel_tab_switcher_container))
.check(matches(withEffectiveVisibility(GONE)));
onView(withId(org.chromium.chrome.tab_ui.R.id.single_tab_view))
.check(matches(withEffectiveVisibility(GONE)));
onView(withId(org.chromium.chrome.tab_ui.R.id.more_tabs))
.check(matches(withEffectiveVisibility(GONE)));
onView(withId(org.chromium.chrome.tab_ui.R.id.tasks_surface_body))
.check(matches(isDisplayed()));
onView(withId(org.chromium.chrome.tab_ui.R.id.trendy_terms_recycler_view))
.check(matches(withEffectiveVisibility(GONE)));
}
}
......@@ -103,7 +103,10 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
/** Integration tests of the {@link StartSurface}. */
/**
* Integration tests of the {@link StartSurface} for cases with tabs. See {@link
* StartSurfaceNoTabsTest} for test that have no tabs.
*/
@RunWith(ParameterizedRunner.class)
@UseRunnerDelegate(ChromeJUnit4RunnerDelegate.class)
@Restriction(
......
......@@ -9,6 +9,7 @@ start_surface_test_java_sources = [
"//chrome/android/features/start_surface/internal/javatests/src/org/chromium/chrome/features/start_surface/SecondaryTasksSurfaceViewBinderTest.java",
"//chrome/android/features/start_surface/internal/javatests/src/org/chromium/chrome/features/start_surface/StartSurfaceLayoutPerfTest.java",
"//chrome/android/features/start_surface/internal/javatests/src/org/chromium/chrome/features/start_surface/StartSurfaceLayoutTest.java",
"//chrome/android/features/start_surface/internal/javatests/src/org/chromium/chrome/features/start_surface/StartSurfaceNoTabsTest.java",
"//chrome/android/features/start_surface/internal/javatests/src/org/chromium/chrome/features/start_surface/StartSurfaceTest.java",
"//chrome/android/features/start_surface/internal/javatests/src/org/chromium/chrome/features/start_surface/TasksSurfaceViewBinderTest.java",
]
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