-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
1,562 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...hics/src/test/java/org/robolectric/integrationtests/nativegraphics/BitmapLoadingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.robolectric.integrationtests.nativegraphics; | ||
|
||
import static android.os.Build.VERSION_CODES.O; | ||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
|
||
import android.graphics.Bitmap; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.Config; | ||
|
||
@Config(minSdk = O) | ||
@RunWith(RobolectricTestRunner.class) | ||
public class BitmapLoadingTest { | ||
|
||
/** | ||
* There is a potential race that happens if Bitmap classes are loaded by multiple threads. The | ||
* race is due to the lazy initialization of ColorSpace class members in hwui's jni/Graphics.cpp. | ||
*/ | ||
@Test | ||
public void bitmapLoading_backgroundThreads_doesNotRace() throws Exception { | ||
ExecutorService executorService = Executors.newFixedThreadPool(4); | ||
for (int i = 0; i < 10; i++) { | ||
executorService.execute( | ||
() -> { | ||
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); | ||
// createScaledBitmap triggers lazy ColorSpace member initialization in hwui | ||
// Graphics.cpp. | ||
Bitmap.createScaledBitmap(bitmap, 200, 200, false); | ||
}); | ||
} | ||
executorService.shutdown(); | ||
executorService.awaitTermination(10, SECONDS); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...aphics/src/test/java/org/robolectric/integrationtests/nativegraphics/FontLoadingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.robolectric.integrationtests.nativegraphics; | ||
|
||
import static android.os.Build.VERSION_CODES.O; | ||
|
||
import androidx.core.content.res.ResourcesCompat; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.RuntimeEnvironment; | ||
import org.robolectric.annotation.Config; | ||
|
||
@Config(minSdk = O) | ||
@RunWith(RobolectricTestRunner.class) | ||
public class FontLoadingTest { | ||
|
||
/** | ||
* There is a potential static initializer cycle that can happen when creating fonts triggers | ||
* loading RNR. Because statically initializing Typeface is the last step of loading RNR, and the | ||
* static initializer of Typeface causes a lot of Font objects to be created, there has to be | ||
* special logic when fonts are loaded to avoid statically initializing Typeface. This is captured | ||
* in a test here. | ||
*/ | ||
@Test | ||
public void loadFont_doesNotCauseStaticInitializerCycle() { | ||
ResourcesCompat.getFont(RuntimeEnvironment.getApplication(), R.font.multiweight_family); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...rg/robolectric/integrationtests/nativegraphics/HardwareAcceleratedActivityRenderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.robolectric.integrationtests.nativegraphics; | ||
|
||
import static android.os.Build.VERSION_CODES.S; | ||
|
||
import android.app.Activity; | ||
import android.view.WindowManager; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.Robolectric; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.android.controller.ActivityController; | ||
import org.robolectric.annotation.Config; | ||
|
||
@RunWith(RobolectricTestRunner.class) | ||
@Config(minSdk = S) | ||
public class HardwareAcceleratedActivityRenderTest { | ||
@Test | ||
public void setupHardwareAcceleratedActivity() { | ||
// This will exercise much of the HardwareRenderer / RenderNode / RecordingCanvas native code. | ||
ActivityController<Activity> controller = Robolectric.buildActivity(Activity.class); | ||
controller | ||
.get() | ||
.getWindow() | ||
.setFlags( | ||
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, | ||
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); | ||
controller.setup(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...raphics/src/test/java/org/robolectric/integrationtests/nativegraphics/MediaStoreTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.robolectric.integrationtests.nativegraphics; | ||
|
||
import static android.os.Build.VERSION_CODES.O; | ||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import android.graphics.Bitmap; | ||
import android.net.Uri; | ||
import android.provider.MediaStore; | ||
import java.io.IOException; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.RuntimeEnvironment; | ||
import org.robolectric.annotation.Config; | ||
|
||
@RunWith(RobolectricTestRunner.class) | ||
@Config(minSdk = O) | ||
public class MediaStoreTest { | ||
|
||
@Test | ||
public void getBitmap_legacyAPI_alwaysReturnsABitmap() throws IOException { | ||
Uri screenshotUri = new Uri.Builder().scheme("content").appendPath("invalid_file").build(); | ||
Bitmap bitmap = | ||
MediaStore.Images.Media.getBitmap( | ||
RuntimeEnvironment.getApplication().getContentResolver(), screenshotUri); | ||
assertThat(bitmap).isNotNull(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...raphics/src/test/java/org/robolectric/integrationtests/nativegraphics/ScrollViewTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.robolectric.integrationtests.nativegraphics; | ||
|
||
import static android.os.Build.VERSION_CODES.O; | ||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import android.app.Activity; | ||
import android.widget.ScrollView; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.Robolectric; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.Config; | ||
|
||
@RunWith(RobolectricTestRunner.class) | ||
@Config(minSdk = O) | ||
public final class ScrollViewTest { | ||
|
||
/** | ||
* Checks that even if {@code robolectric.useRealScrolling} is set to false, real scrolling code | ||
* is used when RNG is enabled. | ||
*/ | ||
@Test | ||
public void smoothScrollTo_usesRealCode_whenRNGEnabled() { | ||
try { | ||
System.setProperty("robolectric.useRealScrolling", "false"); | ||
Activity activity = Robolectric.setupActivity(Activity.class); | ||
ScrollView scrollView = new ScrollView(activity); | ||
scrollView.smoothScrollTo(100, 100); | ||
// Because the scroll view has no children, it should not get scrolled. | ||
assertThat(scrollView.getScrollX()).isEqualTo(0); | ||
assertThat(scrollView.getScrollY()).isEqualTo(0); | ||
} finally { | ||
System.clearProperty("robolectric.useRealScrolling"); | ||
} | ||
} | ||
} |
Oops, something went wrong.