• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.view;
18 
19 import static android.view.ContentRecordingSession.RECORD_CONTENT_DISPLAY;
20 import static android.view.ContentRecordingSession.RECORD_CONTENT_TASK;
21 import static android.view.Display.DEFAULT_DISPLAY;
22 import static android.view.Display.INVALID_DISPLAY;
23 
24 import static com.google.common.truth.Truth.assertThat;
25 
26 import android.os.Binder;
27 import android.os.IBinder;
28 import android.os.Parcel;
29 import android.platform.test.annotations.Presubmit;
30 
31 import androidx.test.ext.junit.runners.AndroidJUnit4;
32 import androidx.test.filters.SmallTest;
33 
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 
37 /**
38  * Tests for {@link ContentRecordingSession} class.
39  *
40  * Build/Install/Run:
41  * atest FrameworksCoreTests:ContentRecordingSessionTest
42  */
43 @RunWith(AndroidJUnit4.class)
44 @SmallTest
45 @Presubmit
46 public class ContentRecordingSessionTest {
47     private static final int DISPLAY_ID = 1;
48     private static final IBinder WINDOW_TOKEN = new Binder("DisplayContentWindowToken");
49 
50     @Test
testParcelable()51     public void testParcelable() {
52         ContentRecordingSession session = ContentRecordingSession.createTaskSession(WINDOW_TOKEN);
53         session.setDisplayId(DISPLAY_ID);
54 
55         Parcel parcel = Parcel.obtain();
56         session.writeToParcel(parcel, 0 /* flags */);
57         parcel.setDataPosition(0);
58         ContentRecordingSession session2 = ContentRecordingSession.CREATOR.createFromParcel(parcel);
59         assertThat(session).isEqualTo(session2);
60         parcel.recycle();
61     }
62 
63     @Test
testTaskConstructor()64     public void testTaskConstructor() {
65         ContentRecordingSession session = ContentRecordingSession.createTaskSession(WINDOW_TOKEN);
66         assertThat(session.getContentToRecord()).isEqualTo(RECORD_CONTENT_TASK);
67         assertThat(session.getTokenToRecord()).isEqualTo(WINDOW_TOKEN);
68     }
69 
70     @Test
testDisplayConstructor()71     public void testDisplayConstructor() {
72         ContentRecordingSession session = ContentRecordingSession.createDisplaySession(
73                 WINDOW_TOKEN);
74         assertThat(session.getContentToRecord()).isEqualTo(RECORD_CONTENT_DISPLAY);
75         assertThat(session.getTokenToRecord()).isEqualTo(WINDOW_TOKEN);
76     }
77 
78     @Test
testIsValid()79     public void testIsValid() {
80         ContentRecordingSession session = ContentRecordingSession.createDisplaySession(
81                 WINDOW_TOKEN);
82         assertThat(ContentRecordingSession.isValid(session)).isFalse();
83 
84         session.setDisplayId(DEFAULT_DISPLAY);
85         assertThat(ContentRecordingSession.isValid(session)).isTrue();
86 
87         session.setDisplayId(INVALID_DISPLAY);
88         assertThat(ContentRecordingSession.isValid(session)).isFalse();
89     }
90 
91     @Test
testIsSameDisplay()92     public void testIsSameDisplay() {
93         assertThat(ContentRecordingSession.isSameDisplay(null, null)).isFalse();
94         ContentRecordingSession session = ContentRecordingSession.createDisplaySession(
95                 WINDOW_TOKEN);
96         session.setDisplayId(DEFAULT_DISPLAY);
97         assertThat(ContentRecordingSession.isSameDisplay(session, null)).isFalse();
98 
99         ContentRecordingSession incomingSession = ContentRecordingSession.createDisplaySession(
100                 WINDOW_TOKEN);
101         incomingSession.setDisplayId(DEFAULT_DISPLAY);
102         assertThat(ContentRecordingSession.isSameDisplay(session, incomingSession)).isTrue();
103 
104         incomingSession.setDisplayId(DEFAULT_DISPLAY + 1);
105         assertThat(ContentRecordingSession.isSameDisplay(session, incomingSession)).isFalse();
106     }
107 
108     @Test
testEquals()109     public void testEquals() {
110         ContentRecordingSession session = ContentRecordingSession.createTaskSession(WINDOW_TOKEN);
111         session.setDisplayId(DISPLAY_ID);
112 
113         ContentRecordingSession session2 = ContentRecordingSession.createTaskSession(WINDOW_TOKEN);
114         session2.setDisplayId(DISPLAY_ID);
115         assertThat(session).isEqualTo(session2);
116     }
117 }
118