summaryrefslogtreecommitdiff
path: root/media/tests
diff options
context:
space:
mode:
author Vadim Caen <caen@google.com> 2025-03-21 12:15:43 -0700
committer Android (Google) Code Review <android-gerrit@google.com> 2025-03-21 12:15:43 -0700
commit7543cedb9f9abd61475e055b2db21615005c9c26 (patch)
tree72360e47c67c09519694f8ebd28c1eadf060039d /media/tests
parenta1a7381a9c4d65c18fd29f44bda9f05a7d6eaefb (diff)
parenta97ff8e4a2102603d8c41a5989e8eb91e69a4fc1 (diff)
Merge changes from topic "media-proj-builder" into main
* changes: Introduce MediaProjectionAppContent Builder pattern for MediaProjectionConfig
Diffstat (limited to 'media/tests')
-rw-r--r--media/tests/projection/Android.bp1
-rw-r--r--media/tests/projection/src/android/media/projection/MediaProjectionAppContentTest.java86
-rw-r--r--media/tests/projection/src/android/media/projection/MediaProjectionConfigTest.java32
3 files changed, 118 insertions, 1 deletions
diff --git a/media/tests/projection/Android.bp b/media/tests/projection/Android.bp
index 0b02d3cb4250..0b4b7dbbca1f 100644
--- a/media/tests/projection/Android.bp
+++ b/media/tests/projection/Android.bp
@@ -26,6 +26,7 @@ android_test {
"androidx.test.runner",
"androidx.test.rules",
"androidx.test.ext.junit",
+ "flag-junit",
"frameworks-base-testutils",
"mockito-target-extended-minus-junit4",
"platform-test-annotations",
diff --git a/media/tests/projection/src/android/media/projection/MediaProjectionAppContentTest.java b/media/tests/projection/src/android/media/projection/MediaProjectionAppContentTest.java
new file mode 100644
index 000000000000..7e167c63a2a2
--- /dev/null
+++ b/media/tests/projection/src/android/media/projection/MediaProjectionAppContentTest.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.media.projection;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.graphics.Bitmap;
+import android.os.Parcel;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class MediaProjectionAppContentTest {
+
+ @Test
+ public void testConstructorAndGetters() {
+ // Create a mock Bitmap
+ Bitmap mockBitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
+
+ // Create a MediaProjectionAppContent object
+ MediaProjectionAppContent content = new MediaProjectionAppContent(mockBitmap, "Test Title",
+ 123);
+
+ // Verify the values using getters
+ assertThat(content.getTitle()).isEqualTo("Test Title");
+ assertThat(content.getId()).isEqualTo(123);
+ // Compare bitmap configurations and dimensions
+ assertThat(content.getThumbnail().getConfig()).isEqualTo(mockBitmap.getConfig());
+ assertThat(content.getThumbnail().getWidth()).isEqualTo(mockBitmap.getWidth());
+ assertThat(content.getThumbnail().getHeight()).isEqualTo(mockBitmap.getHeight());
+ }
+
+ @Test
+ public void testParcelable() {
+ // Create a mock Bitmap
+ Bitmap mockBitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
+
+ // Create a MediaProjectionAppContent object
+ MediaProjectionAppContent content = new MediaProjectionAppContent(mockBitmap, "Test Title",
+ 123);
+
+ // Parcel and unparcel the object
+ Parcel parcel = Parcel.obtain();
+ content.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ MediaProjectionAppContent unparceledContent =
+ MediaProjectionAppContent.CREATOR.createFromParcel(parcel);
+
+ // Verify the values of the unparceled object
+ assertThat(unparceledContent.getTitle()).isEqualTo("Test Title");
+ assertThat(unparceledContent.getId()).isEqualTo(123);
+ // Compare bitmap configurations and dimensions
+ assertThat(unparceledContent.getThumbnail().getConfig()).isEqualTo(mockBitmap.getConfig());
+ assertThat(unparceledContent.getThumbnail().getWidth()).isEqualTo(mockBitmap.getWidth());
+ assertThat(unparceledContent.getThumbnail().getHeight()).isEqualTo(mockBitmap.getHeight());
+
+ parcel.recycle();
+ }
+
+ @Test
+ public void testCreatorNewArray() {
+ // Create a new array using the CREATOR
+ MediaProjectionAppContent[] contentArray = MediaProjectionAppContent.CREATOR.newArray(5);
+
+ // Verify that the array is not null and has the correct size
+ assertThat(contentArray).isNotNull();
+ assertThat(contentArray).hasLength(5);
+ }
+}
diff --git a/media/tests/projection/src/android/media/projection/MediaProjectionConfigTest.java b/media/tests/projection/src/android/media/projection/MediaProjectionConfigTest.java
index 2820606958b7..bc0eae1a3ec7 100644
--- a/media/tests/projection/src/android/media/projection/MediaProjectionConfigTest.java
+++ b/media/tests/projection/src/android/media/projection/MediaProjectionConfigTest.java
@@ -18,22 +18,31 @@ package android.media.projection;
import static android.media.projection.MediaProjectionConfig.CAPTURE_REGION_FIXED_DISPLAY;
import static android.media.projection.MediaProjectionConfig.CAPTURE_REGION_USER_CHOICE;
+import static android.media.projection.MediaProjectionConfig.PROJECTION_SOURCE_DISPLAY;
+import static android.media.projection.MediaProjectionConfig.DEFAULT_PROJECTION_SOURCES;
import static android.view.Display.DEFAULT_DISPLAY;
import static com.google.common.truth.Truth.assertThat;
import android.os.Parcel;
import android.platform.test.annotations.Presubmit;
+import android.platform.test.annotations.RequiresFlagsDisabled;
+import android.platform.test.annotations.RequiresFlagsEnabled;
+import android.platform.test.flag.junit.CheckFlagsRule;
+import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
+import com.android.media.projection.flags.Flags;
+
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests for the {@link MediaProjectionConfig} class.
- *
+ * <p>
* Build/Install/Run:
* atest MediaProjectionTests:MediaProjectionConfigTest
*/
@@ -41,6 +50,11 @@ import org.junit.runner.RunWith;
@Presubmit
@RunWith(AndroidJUnit4.class)
public class MediaProjectionConfigTest {
+
+ @Rule
+ public final CheckFlagsRule mCheckFlagsRule =
+ DeviceFlagsValueProvider.createCheckFlagsRule();
+
private static final MediaProjectionConfig DISPLAY_CONFIG =
MediaProjectionConfig.createConfigForDefaultDisplay();
private static final MediaProjectionConfig USERS_CHOICE_CONFIG =
@@ -57,17 +71,33 @@ public class MediaProjectionConfigTest {
}
@Test
+ @RequiresFlagsDisabled(Flags.FLAG_APP_CONTENT_SHARING)
public void testCreateDisplayConfig() {
assertThat(DISPLAY_CONFIG.getRegionToCapture()).isEqualTo(CAPTURE_REGION_FIXED_DISPLAY);
assertThat(DISPLAY_CONFIG.getDisplayToCapture()).isEqualTo(DEFAULT_DISPLAY);
}
@Test
+ @RequiresFlagsDisabled(Flags.FLAG_APP_CONTENT_SHARING)
public void testCreateUsersChoiceConfig() {
assertThat(USERS_CHOICE_CONFIG.getRegionToCapture()).isEqualTo(CAPTURE_REGION_USER_CHOICE);
}
@Test
+ @RequiresFlagsEnabled(Flags.FLAG_APP_CONTENT_SHARING)
+ public void testDefaultProjectionSources() {
+ assertThat(USERS_CHOICE_CONFIG.getProjectionSources())
+ .isEqualTo(DEFAULT_PROJECTION_SOURCES);
+ }
+
+ @Test
+ @RequiresFlagsEnabled(Flags.FLAG_APP_CONTENT_SHARING)
+ public void testCreateDisplayConfigProjectionSource() {
+ assertThat(DISPLAY_CONFIG.getProjectionSources()).isEqualTo(PROJECTION_SOURCE_DISPLAY);
+ assertThat(DISPLAY_CONFIG.getDisplayToCapture()).isEqualTo(DEFAULT_DISPLAY);
+ }
+
+ @Test
public void testEquals() {
assertThat(MediaProjectionConfig.createConfigForUserChoice()).isEqualTo(
USERS_CHOICE_CONFIG);