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; ...@@ -30,9 +30,9 @@ import org.junit.runner.RunWith;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.SuppressFBWarnings; import org.chromium.base.annotations.SuppressFBWarnings;
import org.chromium.base.test.util.CommandLineFlags; 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.Feature;
import org.chromium.base.test.util.Restriction; import org.chromium.base.test.util.Restriction;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
...@@ -44,6 +44,7 @@ import org.chromium.chrome.browser.ntp.cards.TreeNode; ...@@ -44,6 +44,7 @@ import org.chromium.chrome.browser.ntp.cards.TreeNode;
import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; import org.chromium.chrome.browser.offlinepages.OfflinePageBridge;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.Tab; 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.browser.widget.displaystyle.UiConfig;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
...@@ -187,9 +188,9 @@ public class TileGridLayoutTest { ...@@ -187,9 +188,9 @@ public class TileGridLayoutTest {
} }
@Test @Test
// @MediumTest @MediumTest
// @Feature({"NewTabPage", "RenderTest"}) @RetryOnFailure
@DisabledTest @Feature({"NewTabPage", "RenderTest"})
@ChromeHome @ChromeHome
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE) @Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
public void testModernTileGridAppearance_Two() throws IOException, InterruptedException { public void testModernTileGridAppearance_Two() throws IOException, InterruptedException {
...@@ -204,6 +205,7 @@ public class TileGridLayoutTest { ...@@ -204,6 +205,7 @@ public class TileGridLayoutTest {
@Test @Test
@MediumTest @MediumTest
@RetryOnFailure
@Feature({"NewTabPage", "RenderTest"}) @Feature({"NewTabPage", "RenderTest"})
@ChromeHome(false) @ChromeHome(false)
public void testTileGridAppearance_Two() throws IOException, InterruptedException { public void testTileGridAppearance_Two() throws IOException, InterruptedException {
...@@ -272,27 +274,24 @@ public class TileGridLayoutTest { ...@@ -272,27 +274,24 @@ public class TileGridLayoutTest {
/** /**
* Checks whether the requested orientation matches the current one. * 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 * @param requestedOrientation The requested orientation, as used in
* {@link ActivityInfo#screenOrientation}. Note: This value is different from the one we * {@link ActivityInfo#screenOrientation}.
* check against from {@link Configuration#orientation}. The constants used to represent
* the values are not the same.
*/ */
public boolean orientationMatchesRequest(Activity activity, int requestedOrientation) { private boolean orientationMatchesRequest(Activity activity, int requestedOrientation) {
int currentOrientation = activity.getResources().getConfiguration().orientation; // Note: Requests use a constant from ActivityInfo, not Configuration.ORIENTATION_*!
boolean expectLandscape = requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
// 1 => 1
if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { // We check the orientation by looking at the dimensions of the content view. Looking at
return currentOrientation == Configuration.ORIENTATION_PORTRAIT; // 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();
// 0 => 2 View contentView = activity.findViewById(android.R.id.content);
if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { int smallestWidthPx = ViewUtils.dpToPx(activity, configuration.smallestScreenWidthDp);
return currentOrientation == Configuration.ORIENTATION_LANDSCAPE; boolean viewIsLandscape = contentView.getMeasuredWidth() > smallestWidthPx;
}
return expectLandscape == viewIsLandscape;
throw new IllegalArgumentException(
"unexpected orientation requested: " + requestedOrientation);
} }
private TileGridLayout getTileGridLayout(NewTabPage ntp) { 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