Commit 9c2c141e authored by Nicolas Dossou-gbete's avatar Nicolas Dossou-gbete Committed by Commit Bot

📰 Attempt to unflake TileGridLayout #2

Look at the content view dimensions to see if the orientation
change happened as expected.

Bug: 768779
Change-Id: I364f1fb13e1b88bb69542f584204dc295be32677
Reviewed-on: https://chromium-review.googlesource.com/689995
Commit-Queue: Nicolas Dossou-Gbété <dgn@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505342}
parent 0756470f
......@@ -30,9 +30,9 @@ import org.junit.runner.RunWith;
import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.SuppressFBWarnings;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.Restriction;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeSwitches;
......@@ -44,6 +44,7 @@ import org.chromium.chrome.browser.ntp.cards.TreeNode;
import org.chromium.chrome.browser.offlinepages.OfflinePageBridge;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.util.ViewUtils;
import org.chromium.chrome.browser.widget.displaystyle.UiConfig;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
......@@ -187,9 +188,9 @@ public class TileGridLayoutTest {
}
@Test
// @MediumTest
// @Feature({"NewTabPage", "RenderTest"})
@DisabledTest
@MediumTest
@RetryOnFailure
@Feature({"NewTabPage", "RenderTest"})
@ChromeHome
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
public void testModernTileGridAppearance_Two() throws IOException, InterruptedException {
......@@ -204,6 +205,7 @@ public class TileGridLayoutTest {
@Test
@MediumTest
@RetryOnFailure
@Feature({"NewTabPage", "RenderTest"})
@ChromeHome(false)
public void testTileGridAppearance_Two() throws IOException, InterruptedException {
......@@ -272,27 +274,24 @@ public class TileGridLayoutTest {
/**
* Checks whether the requested orientation matches the current one.
* @param activity Activity to check the orientation from. We pull its {@link Configuration}.
* @param activity Activity to check the orientation from. We pull its {@link Configuration} and
* content {@link View}.
* @param requestedOrientation The requested orientation, as used in
* {@link ActivityInfo#screenOrientation}. Note: This value is different from the one we
* check against from {@link Configuration#orientation}. The constants used to represent
* the values are not the same.
* {@link ActivityInfo#screenOrientation}.
*/
public boolean orientationMatchesRequest(Activity activity, int requestedOrientation) {
int currentOrientation = activity.getResources().getConfiguration().orientation;
// 1 => 1
if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
return currentOrientation == Configuration.ORIENTATION_PORTRAIT;
}
// 0 => 2
if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
return currentOrientation == Configuration.ORIENTATION_LANDSCAPE;
}
throw new IllegalArgumentException(
"unexpected orientation requested: " + requestedOrientation);
private boolean orientationMatchesRequest(Activity activity, int requestedOrientation) {
// Note: Requests use a constant from ActivityInfo, not Configuration.ORIENTATION_*!
boolean expectLandscape = requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
// We check the orientation by looking at the dimensions of the content view. Looking at
// orientation from the configuration is not reliable as sometimes the activity gets the
// event that its configuration changed, but has not updated its layout yet.
Configuration configuration = activity.getResources().getConfiguration();
View contentView = activity.findViewById(android.R.id.content);
int smallestWidthPx = ViewUtils.dpToPx(activity, configuration.smallestScreenWidthDp);
boolean viewIsLandscape = contentView.getMeasuredWidth() > smallestWidthPx;
return expectLandscape == viewIsLandscape;
}
private TileGridLayout getTileGridLayout(NewTabPage ntp) {
......
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