Commit 52e2324c authored by Yue Zhang's avatar Yue Zhang Committed by Commit Bot

Remove unused TabGridIphItemTest

After http://crrev.com/c/2026380, TabGridIphItemTest is no longer in
use. This CL removes this test class.

Bug: 1002678
Change-Id: I00e7cfaca83ec42d45143ef70eef31bc837ba670
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2076079
Commit-Queue: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Auto-Submit: Yue Zhang <yuezhanggg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744878}
parent 28b513d0
// Copyright 2019 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.browser.tasks.tab_management;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.RootMatchers.withDecorView;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.hamcrest.Matchers.not;
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.tab_management.TabUiTestHelper.enterTabSwitcher;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.rotateDeviceToOrientation;
import android.content.res.Configuration;
import android.support.test.espresso.NoMatchingRootException;
import android.support.test.filters.MediumTest;
import android.view.ViewGroup;
import android.widget.TextView;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisableIf;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.compositor.layouts.Layout;
import org.chromium.chrome.browser.flags.CachedFeatureFlags;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.features.start_surface.StartSurfaceLayout;
import org.chromium.chrome.tab_ui.R;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.ui.display.DisplayAndroid;
import org.chromium.ui.test.util.UiRestriction;
/** End-to-end tests for TabGridIphItem component. */
@RunWith(ChromeJUnit4ClassRunner.class)
// clang-format off
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
@Features.EnableFeatures({ChromeFeatureList.TAB_GROUPS_UI_IMPROVEMENTS_ANDROID})
public class TabGridIphItemTest {
// clang-format on
@Rule
public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
@Rule
public TestRule mProcessor = new Features.InstrumentationProcessor();
@Before
public void setUp() {
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, true);
mActivityTestRule.startMainActivityFromLauncher();
Layout layout = mActivityTestRule.getActivity().getLayoutManager().getOverviewLayout();
assertTrue(layout instanceof StartSurfaceLayout);
CriteriaHelper.pollUiThread(mActivityTestRule.getActivity()
.getTabModelSelector()
.getTabModelFilterProvider()
.getCurrentTabModelFilter()::isTabModelRestored);
}
@After
public void tearDown() {
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, null);
}
@Test
@MediumTest
public void testShowAndHideIphItem() throws InterruptedException {
final ChromeTabbedActivity cta = mActivityTestRule.getActivity();
enterTabSwitcher(cta);
verifyIphEntranceShowing(cta);
// Enter the IPH dialog and exit by clicking "OK" button.
enterIphDialog(cta);
verifyIphDialogShowing(cta);
exitIphDialogByClickingButton(cta);
verifyIphDialogHiding(cta);
// Exiting IPH dialog should not dismiss the IPH.
verifyIphEntranceShowing(cta);
// Enter the IPH dialog and exit by clicking ScrimView.
enterIphDialog(cta);
verifyIphDialogShowing(cta);
TabUiTestHelper.clickScrimToExitDialog(cta);
verifyIphDialogHiding(cta);
// Exiting IPH dialog should not dismiss the IPH.
verifyIphEntranceShowing(cta);
// Explicitly close IPH entrance should dismiss the IPH.
closeIphEntrance(cta);
verifyIphEntranceHiding(cta);
}
@Test
@MediumTest
@DisableIf.Build(message = "https://crbug.com/1023430, https://crbug.com/1045417")
public void testIphItemScreenRotation() throws InterruptedException {
final ChromeTabbedActivity cta = mActivityTestRule.getActivity();
enterTabSwitcher(cta);
verifyIphEntranceShowing(cta);
enterIphDialog(cta);
// Check the margins for default orientation which is portrait.
assertEquals(Configuration.ORIENTATION_PORTRAIT,
cta.getResources().getConfiguration().orientation);
verifyDialogMargins(cta, Configuration.ORIENTATION_PORTRAIT);
// Rotate the device to landscape mode.
rotateDeviceToOrientation(cta, Configuration.ORIENTATION_LANDSCAPE);
verifyDialogMargins(cta, Configuration.ORIENTATION_LANDSCAPE);
// Reset the orientation to portrait.
rotateDeviceToOrientation(cta, Configuration.ORIENTATION_PORTRAIT);
}
private void verifyIphEntranceShowing(ChromeTabbedActivity cta) {
onView(withId(R.id.tab_grid_iph_item)).check((v, noMatchException) -> {
if (noMatchException != null) throw noMatchException;
Assert.assertTrue(v.findViewById(R.id.iph_description) instanceof TextView);
Assert.assertTrue(v.findViewById(R.id.show_me_button) instanceof TextView);
TextView descriptionText = v.findViewById(R.id.iph_description);
String description = cta.getString(R.string.iph_drag_and_drop_introduction);
assertEquals(description, descriptionText.getText());
TextView showMeTextButton = v.findViewById(R.id.show_me_button);
String buttonText = cta.getString(R.string.iph_drag_and_drop_show_me);
assertEquals(buttonText, showMeTextButton.getText());
});
}
private void verifyIphEntranceHiding(ChromeTabbedActivity cta) {
onView(withId(R.id.tab_grid_iph_item)).check(doesNotExist());
}
private void verifyIphDialogShowing(ChromeTabbedActivity cta) {
onView(withId(R.id.iph_dialog))
.inRoot(withDecorView(not(cta.getWindow().getDecorView())))
.check((v, noMatchException) -> {
if (noMatchException != null) throw noMatchException;
String title = cta.getString(R.string.iph_drag_and_drop_title);
assertEquals(title, ((TextView) v.findViewById(R.id.title)).getText());
String description = cta.getString(R.string.iph_drag_and_drop_content);
assertEquals(
description, ((TextView) v.findViewById(R.id.description)).getText());
String closeButtonText = cta.getString(R.string.ok);
assertEquals(closeButtonText,
((TextView) v.findViewById(R.id.close_button)).getText());
});
}
private void verifyIphDialogHiding(ChromeTabbedActivity cta) {
boolean isShowing = true;
try {
onView(withId(R.id.iph_dialog))
.inRoot(withDecorView(not(cta.getWindow().getDecorView())))
.check(matches(isDisplayed()));
} catch (NoMatchingRootException e) {
isShowing = false;
} catch (Exception e) {
assert false : "error when inspecting iph dialog.";
}
assertFalse(isShowing);
}
private void exitIphDialogByClickingButton(ChromeTabbedActivity cta) {
onView(withId(R.id.close_button))
.inRoot(withDecorView(not(cta.getWindow().getDecorView())))
.perform(click());
}
private void enterIphDialog(ChromeTabbedActivity cta) {
assertTrue(cta.getLayoutManager().overviewVisible());
onView(withId(R.id.show_me_button)).perform(click());
}
private void closeIphEntrance(ChromeTabbedActivity cta) {
assertTrue(cta.getLayoutManager().overviewVisible());
onView(withId(R.id.close_iph_button)).perform(click());
}
private void verifyDialogMargins(ChromeTabbedActivity cta, int orientation) {
verifyIphDialogShowing(cta);
int screenHeight = TestThreadUtils.runOnUiThreadBlockingNoException(
() -> DisplayAndroid.getNonMultiDisplay(cta).getDisplayHeight());
int dialogHeight =
(int) cta.getResources().getDimension(R.dimen.tab_grid_iph_dialog_height);
int updatedDialogTopMargin = Math.max((screenHeight - dialogHeight) / 2,
(int) cta.getResources().getDimension(R.dimen.tab_grid_iph_dialog_top_margin));
int sideMargin =
(int) cta.getResources().getDimension(R.dimen.tab_grid_iph_dialog_side_margin);
int textTopMarginPortrait = (int) cta.getResources().getDimension(
R.dimen.tab_grid_iph_dialog_text_top_margin_portrait);
int textTopMarginLandscape = (int) cta.getResources().getDimension(
R.dimen.tab_grid_iph_dialog_text_top_margin_landscape);
int textSideMargin =
(int) cta.getResources().getDimension(R.dimen.tab_grid_iph_dialog_text_side_margin);
int dialogTopMargin;
int dialogSideMargin;
int textTopMargin;
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
dialogTopMargin = updatedDialogTopMargin;
dialogSideMargin = sideMargin;
textTopMargin = textTopMarginPortrait;
} else {
dialogTopMargin = sideMargin;
dialogSideMargin = updatedDialogTopMargin;
textTopMargin = textTopMarginLandscape;
}
onView(withId(R.id.iph_dialog))
.inRoot(withDecorView(not(cta.getWindow().getDecorView())))
.check((v, noMatchException) -> {
if (noMatchException != null) throw noMatchException;
ViewGroup.MarginLayoutParams realMargins =
(ViewGroup.MarginLayoutParams) v.getLayoutParams();
assertEquals(dialogTopMargin, realMargins.topMargin);
assertEquals(dialogSideMargin, realMargins.leftMargin);
});
onView(withId(R.id.title))
.inRoot(withDecorView(not(cta.getWindow().getDecorView())))
.check((v, noMatchException) -> {
if (noMatchException != null) throw noMatchException;
ViewGroup.MarginLayoutParams realMargins =
(ViewGroup.MarginLayoutParams) v.getLayoutParams();
assertEquals(textTopMargin, realMargins.topMargin);
assertEquals(textSideMargin, realMargins.leftMargin);
});
onView(withId(R.id.description))
.inRoot(withDecorView(not(cta.getWindow().getDecorView())))
.check((v, noMatchException) -> {
if (noMatchException != null) throw noMatchException;
ViewGroup.MarginLayoutParams realMargins =
(ViewGroup.MarginLayoutParams) v.getLayoutParams();
assertEquals(0, realMargins.topMargin);
assertEquals(textTopMargin, realMargins.bottomMargin);
assertEquals(textSideMargin, realMargins.leftMargin);
});
onView(withId(R.id.close_button))
.inRoot(withDecorView(not(cta.getWindow().getDecorView())))
.check((v, noMatchException) -> {
if (noMatchException != null) throw noMatchException;
ViewGroup.MarginLayoutParams realMargins =
(ViewGroup.MarginLayoutParams) v.getLayoutParams();
assertEquals(textTopMargin, realMargins.topMargin);
assertEquals(textSideMargin, realMargins.leftMargin);
});
}
}
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