Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DeviceConfig set MaxBounds on Android S+. #9031

Open
wants to merge 1 commit into
base: google
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,11 +1,15 @@
package org.robolectric.android;

import static android.os.Build.VERSION_CODES.O;
import static android.os.Build.VERSION_CODES.S;
import static com.google.common.truth.Truth.assertThat;

import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Rect;
import android.os.Build.VERSION_CODES;
import android.util.DisplayMetrics;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import java.util.Locale;
import org.junit.Before;
Expand Down Expand Up @@ -83,6 +87,20 @@ public void applyToConfiguration_isCumulative() {
+ "land-television-night-xxhdpi-notouch-keyshidden-nokeys-navhidden-nonav");
}

@Config(minSdk = S)
@Test
public void windowResources_maxBounds() throws Exception {
Resources systemResources = Resources.getSystem();
Resources appResources = ApplicationProvider.getApplicationContext().getResources();

Rect maxBounds = systemResources.getConfiguration().windowConfiguration.getMaxBounds();
Rect appMaxBounds = appResources.getConfiguration().windowConfiguration.getMaxBounds();

assertThat(maxBounds).isEqualTo(appMaxBounds);
assertThat(maxBounds.width()).isGreaterThan(0);
assertThat(maxBounds.height()).isGreaterThan(0);
}

@Test
public void applyRules_defaults() {
DeviceConfig.applyRules(configuration, displayMetrics, apiLevel);
Expand Down
Expand Up @@ -255,6 +255,9 @@ private static void setDimensions(
ReflectionHelpers.getField(configuration, "windowConfiguration");
windowConfiguration.setBounds(bounds);
windowConfiguration.setAppBounds(bounds);
if (apiLevel >= VERSION_CODES.S) {
windowConfiguration.setMaxBounds(bounds);
}
}
}

Expand Down