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 com.android.systemui.reardisplay; 18 19 import static junit.framework.Assert.assertEquals; 20 import static junit.framework.Assert.assertNotSame; 21 import static junit.framework.Assert.assertTrue; 22 23 import android.content.res.Configuration; 24 import android.hardware.devicestate.DeviceStateManager; 25 import android.testing.AndroidTestingRunner; 26 import android.testing.TestableLooper; 27 import android.widget.TextView; 28 29 import androidx.test.filters.SmallTest; 30 31 import com.android.systemui.R; 32 import com.android.systemui.SysuiTestCase; 33 import com.android.systemui.statusbar.CommandQueue; 34 import com.android.systemui.util.concurrency.FakeExecutor; 35 import com.android.systemui.util.time.FakeSystemClock; 36 37 import org.junit.Test; 38 import org.junit.runner.RunWith; 39 import org.mockito.Mock; 40 41 @SmallTest 42 @RunWith(AndroidTestingRunner.class) 43 @TestableLooper.RunWithLooper(setAsMainLooper = true) 44 public class RearDisplayDialogControllerTest extends SysuiTestCase { 45 46 @Mock 47 private CommandQueue mCommandQueue; 48 49 private FakeExecutor mFakeExecutor = new FakeExecutor(new FakeSystemClock()); 50 51 52 private static final int CLOSED_BASE_STATE = 0; 53 private static final int OPEN_BASE_STATE = 1; 54 55 @Test testClosedDialogIsShown()56 public void testClosedDialogIsShown() { 57 RearDisplayDialogController controller = new RearDisplayDialogController(mContext, 58 mCommandQueue, mFakeExecutor); 59 controller.setDeviceStateManagerCallback(new TestDeviceStateManagerCallback()); 60 controller.setFoldedStates(new int[]{0}); 61 controller.setAnimationRepeatCount(0); 62 63 controller.showRearDisplayDialog(CLOSED_BASE_STATE); 64 assertTrue(controller.mRearDisplayEducationDialog.isShowing()); 65 TextView deviceClosedTitleTextView = controller.mRearDisplayEducationDialog.findViewById( 66 R.id.rear_display_title_text_view); 67 assertEquals(deviceClosedTitleTextView.getText().toString(), 68 getContext().getResources().getString( 69 R.string.rear_display_folded_bottom_sheet_title)); 70 } 71 72 @Test testClosedDialogIsRefreshedOnConfigurationChange()73 public void testClosedDialogIsRefreshedOnConfigurationChange() { 74 RearDisplayDialogController controller = new RearDisplayDialogController(mContext, 75 mCommandQueue, mFakeExecutor); 76 controller.setDeviceStateManagerCallback(new TestDeviceStateManagerCallback()); 77 controller.setFoldedStates(new int[]{0}); 78 controller.setAnimationRepeatCount(0); 79 80 controller.showRearDisplayDialog(CLOSED_BASE_STATE); 81 assertTrue(controller.mRearDisplayEducationDialog.isShowing()); 82 TextView deviceClosedTitleTextView = controller.mRearDisplayEducationDialog.findViewById( 83 R.id.rear_display_title_text_view); 84 85 controller.onConfigurationChanged(new Configuration()); 86 assertTrue(controller.mRearDisplayEducationDialog.isShowing()); 87 TextView deviceClosedTitleTextView2 = controller.mRearDisplayEducationDialog.findViewById( 88 R.id.rear_display_title_text_view); 89 90 assertNotSame(deviceClosedTitleTextView, deviceClosedTitleTextView2); 91 } 92 93 @Test testOpenDialogIsShown()94 public void testOpenDialogIsShown() { 95 RearDisplayDialogController controller = new RearDisplayDialogController(mContext, 96 mCommandQueue, mFakeExecutor); 97 controller.setDeviceStateManagerCallback(new TestDeviceStateManagerCallback()); 98 controller.setFoldedStates(new int[]{0}); 99 controller.setAnimationRepeatCount(0); 100 101 controller.showRearDisplayDialog(OPEN_BASE_STATE); 102 103 assertTrue(controller.mRearDisplayEducationDialog.isShowing()); 104 TextView deviceClosedTitleTextView = controller.mRearDisplayEducationDialog.findViewById( 105 R.id.rear_display_title_text_view); 106 assertEquals(deviceClosedTitleTextView.getText().toString(), 107 getContext().getResources().getString( 108 R.string.rear_display_unfolded_bottom_sheet_title)); 109 } 110 111 /** 112 * Empty device state manager callbacks, so we can verify that the correct 113 * dialogs are being created regardless of device state of the test device. 114 */ 115 private static class TestDeviceStateManagerCallback implements 116 DeviceStateManager.DeviceStateCallback { 117 118 @Override onStateChanged(int state)119 public void onStateChanged(int state) { } 120 } 121 } 122