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 /* 18 * Copyright (C) 2022 The Android Open Source Project 19 * 20 * Licensed under the Apache License, Version 2.0 (the "License"); 21 * you may not use this file except in compliance with the License. 22 * You may obtain a copy of the License at 23 * 24 * http://www.apache.org/licenses/LICENSE-2.0 25 * 26 * Unless required by applicable law or agreed to in writing, software 27 * distributed under the License is distributed on an "AS IS" BASIS, 28 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 29 * See the License for the specific language governing permissions and 30 * limitations under the License. 31 */ 32 33 package com.android.systemui.screenrecord 34 35 import android.testing.AndroidTestingRunner 36 import android.testing.TestableLooper 37 import android.view.View 38 import androidx.test.filters.SmallTest 39 import com.android.systemui.R 40 import com.android.systemui.SysuiTestCase 41 import com.android.systemui.animation.DialogLaunchAnimator 42 import com.android.systemui.flags.FeatureFlags 43 import com.android.systemui.flags.Flags 44 import com.android.systemui.plugins.ActivityStarter 45 import com.android.systemui.settings.UserContextProvider 46 import com.google.common.truth.Truth.assertThat 47 import org.junit.After 48 import org.junit.Before 49 import org.junit.Test 50 import org.junit.runner.RunWith 51 import org.mockito.Mock 52 import org.mockito.MockitoAnnotations 53 import org.mockito.Mockito.`when` as whenever 54 55 @SmallTest 56 @RunWith(AndroidTestingRunner::class) 57 @TestableLooper.RunWithLooper(setAsMainLooper = true) 58 class ScreenRecordDialogTest : SysuiTestCase() { 59 60 @Mock 61 private lateinit var starter: ActivityStarter 62 @Mock 63 private lateinit var controller: RecordingController 64 @Mock 65 private lateinit var userContextProvider: UserContextProvider 66 @Mock 67 private lateinit var flags: FeatureFlags 68 @Mock 69 private lateinit var dialogLaunchAnimator: DialogLaunchAnimator 70 @Mock 71 private lateinit var onStartRecordingClicked: Runnable 72 73 private lateinit var dialog: ScreenRecordDialog 74 75 @Before 76 fun setUp() { 77 MockitoAnnotations.initMocks(this) 78 79 dialog = ScreenRecordDialog( 80 context, controller, starter, userContextProvider, flags, dialogLaunchAnimator, 81 onStartRecordingClicked 82 ) 83 } 84 85 @After 86 fun teardown() { 87 if (::dialog.isInitialized) { 88 dialog.dismiss() 89 } 90 } 91 92 @Test 93 fun testShowDialog_partialScreenSharingDisabled_appButtonIsNotVisible() { 94 whenever(flags.isEnabled(Flags.WM_ENABLE_PARTIAL_SCREEN_SHARING)).thenReturn(false) 95 96 dialog.show() 97 98 val visibility = dialog.requireViewById<View>(R.id.button_app).visibility 99 assertThat(visibility).isEqualTo(View.GONE) 100 } 101 102 @Test 103 fun testShowDialog_partialScreenSharingEnabled_appButtonIsVisible() { 104 whenever(flags.isEnabled(Flags.WM_ENABLE_PARTIAL_SCREEN_SHARING)).thenReturn(true) 105 106 dialog.show() 107 108 val visibility = dialog.requireViewById<View>(R.id.button_app).visibility 109 assertThat(visibility).isEqualTo(View.VISIBLE) 110 } 111 } 112