Commit d9122360 authored by Yue Zhang's avatar Yue Zhang Committed by Commit Bot

Dynamically get span count for message card in GTS

http://crrev.com/c/2023197 makes message card adapt to the span count
when it changes. This is achieved through updating the span size
based on spanCount that we calculate when orientation change is
detected. However, there is a corner case where the span size lookup
happens but the orientation change is not detected and therefore
the spanCount is not updated. This CL fixes this issue by letting
SpanSizeLookup() to dynamically get the current span count from
GridLayoutManager instead of replying on a calculation when
orientation change is detected.

Also, this CL adds some render tests for the IPH message card so that we
have some coverage on the orientation change related logic.

Bug: 1050494
Change-Id: Ie86a8583db926c41a46451a1c5eff3c6a4a5ec54
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2076550
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@{#745683}
parent 7aac305e
......@@ -1095,7 +1095,7 @@ class TabListMediator {
public int getSpanSize(int position) {
int itemType = mModel.get(position).type;
if (itemType == TabProperties.UiType.MESSAGE) return spanCount;
if (itemType == TabProperties.UiType.MESSAGE) return manager.getSpanCount();
return 1;
}
});
......
......@@ -21,7 +21,9 @@ import static org.junit.Assert.assertTrue;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.clickScrimToExitDialog;
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.widget.TextView;
......@@ -34,6 +36,7 @@ import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
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.ChromeSwitches;
import org.chromium.chrome.browser.ChromeTabbedActivity;
......@@ -45,10 +48,13 @@ 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.ApplicationTestUtils;
import org.chromium.chrome.test.util.ChromeRenderTestRule;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.ui.test.util.UiRestriction;
import java.io.IOException;
/** End-to-end tests for TabGridIph component. */
@RunWith(ChromeJUnit4ClassRunner.class)
// clang-format off
......@@ -64,6 +70,9 @@ public class TabGridIphTest {
@Rule
public TestRule mProcessor = new Features.InstrumentationProcessor();
@Rule
public ChromeRenderTestRule mRenderTestRule = new ChromeRenderTestRule();
@Before
public void setUp() {
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, true);
......@@ -143,6 +152,38 @@ public class TabGridIphTest {
onView(withId(R.id.tab_grid_message_item)).check(doesNotExist());
}
@Test
@MediumTest
@Feature({"RenderTest"})
public void testRenderIph_Portrait() throws IOException {
ChromeTabbedActivity cta = mActivityTestRule.getActivity();
enterTabSwitcher(cta);
CriteriaHelper.pollInstrumentationThread(
TabSwitcherCoordinator::hasAppendedMessagesForTesting);
onView(withId(R.id.tab_grid_message_item)).check(matches(isDisplayed()));
mRenderTestRule.render(cta.findViewById(R.id.tab_grid_message_item), "iph_portrait");
}
@Test
@MediumTest
@Feature({"RenderTest"})
public void testRenderIph_Landscape() throws IOException {
ChromeTabbedActivity cta = mActivityTestRule.getActivity();
enterTabSwitcher(cta);
rotateDeviceToOrientation(cta, Configuration.ORIENTATION_LANDSCAPE);
CriteriaHelper.pollInstrumentationThread(
TabSwitcherCoordinator::hasAppendedMessagesForTesting);
onView(withId(R.id.tab_grid_message_item)).check(matches(isDisplayed()));
mRenderTestRule.render(cta.findViewById(R.id.tab_grid_message_item), "iph_landscape");
// Reset orientation.
rotateDeviceToOrientation(cta, Configuration.ORIENTATION_PORTRAIT);
}
private void verifyIphDialogShowing(ChromeTabbedActivity cta) {
onView(withId(R.id.iph_dialog))
.inRoot(withDecorView(not(cta.getWindow().getDecorView())))
......
d042754b31261730a99f1ab48b8d2be8da49da3f
\ No newline at end of file
bb0917985d1b2966460727b5073794aef03a2785
\ No newline at end of file
9da492922e5f75bb701c41ea8541ff6635e94a70
\ No newline at end of file
a9ffabcd7e6f2a8c02bbc74d4f5e9819d9ce29e1
\ No newline at end of file
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