blob: e5024595d97e2490235e84a207a87cc52f0008d1 [file] [log] [blame]
Beth Thibodeau58772782020-02-18 20:55:38 -05001/*
2 * Copyright (C) 2020 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
17package com.android.systemui.qs.tiles;
18
19import static junit.framework.Assert.assertEquals;
20import static junit.framework.Assert.assertTrue;
21
22import static org.mockito.Mockito.times;
23import static org.mockito.Mockito.verify;
24import static org.mockito.Mockito.when;
25
26import android.service.quicksettings.Tile;
27import android.testing.AndroidTestingRunner;
28import android.testing.TestableLooper;
29
30import androidx.test.filters.SmallTest;
31
Beth Thibodeauabb338f2020-03-03 16:17:24 -050032import com.android.internal.logging.UiEventLogger;
Beth Thibodeau58772782020-02-18 20:55:38 -050033import com.android.systemui.Dependency;
34import com.android.systemui.R;
35import com.android.systemui.SysuiTestCase;
Beth Thibodeauf54cace2020-04-23 12:46:55 -040036import com.android.systemui.plugins.ActivityStarter;
Beth Thibodeau58772782020-02-18 20:55:38 -050037import com.android.systemui.qs.QSTileHost;
38import com.android.systemui.screenrecord.RecordingController;
39
40import org.junit.Before;
41import org.junit.Test;
42import org.junit.runner.RunWith;
43import org.mockito.Mock;
44import org.mockito.MockitoAnnotations;
45
46@RunWith(AndroidTestingRunner.class)
47@TestableLooper.RunWithLooper
48@SmallTest
49public class ScreenRecordTileTest extends SysuiTestCase {
50
51 @Mock
52 private RecordingController mController;
53 @Mock
Beth Thibodeauf54cace2020-04-23 12:46:55 -040054 private ActivityStarter mActivityStarter;
55 @Mock
Beth Thibodeau58772782020-02-18 20:55:38 -050056 private QSTileHost mHost;
Beth Thibodeauabb338f2020-03-03 16:17:24 -050057 @Mock
58 private UiEventLogger mUiEventLogger;
Beth Thibodeau58772782020-02-18 20:55:38 -050059
60 private TestableLooper mTestableLooper;
61 private ScreenRecordTile mTile;
62
63 @Before
64 public void setUp() throws Exception {
65 MockitoAnnotations.initMocks(this);
66
67 mTestableLooper = TestableLooper.get(this);
68 mDependency.injectTestDependency(Dependency.BG_LOOPER, mTestableLooper.getLooper());
69 mController = mDependency.injectMockDependency(RecordingController.class);
Beth Thibodeauf54cace2020-04-23 12:46:55 -040070 mActivityStarter = mDependency.injectMockDependency(ActivityStarter.class);
Beth Thibodeau58772782020-02-18 20:55:38 -050071
72 when(mHost.getContext()).thenReturn(mContext);
73
Beth Thibodeauabb338f2020-03-03 16:17:24 -050074 mTile = new ScreenRecordTile(mHost, mController, mActivityStarter, mUiEventLogger);
Beth Thibodeau58772782020-02-18 20:55:38 -050075 }
76
77 // Test that the tile is inactive and labeled correctly when the controller is neither starting
78 // or recording, and that clicking on the tile in this state brings up the record prompt
79 @Test
80 public void testNotActive() {
81 when(mController.isStarting()).thenReturn(false);
82 when(mController.isRecording()).thenReturn(false);
83
84 mTile.refreshState();
85 mTestableLooper.processAllMessages();
86
87 assertEquals(Tile.STATE_INACTIVE, mTile.getState().state);
88 assertTrue(mTile.getState().secondaryLabel.toString().equals(
89 mContext.getString(R.string.quick_settings_screen_record_start)));
90
91 mTile.handleClick();
Beth Thibodeauf54cace2020-04-23 12:46:55 -040092 verify(mController, times(1)).getPromptIntent();
Beth Thibodeau58772782020-02-18 20:55:38 -050093 }
94
95 // Test that the tile is active and labeled correctly when the controller is starting
96 @Test
97 public void testIsStarting() {
98 when(mController.isStarting()).thenReturn(true);
99 when(mController.isRecording()).thenReturn(false);
100
101 mTile.refreshState();
102 mTestableLooper.processAllMessages();
103
104 assertEquals(Tile.STATE_ACTIVE, mTile.getState().state);
105 assertTrue(mTile.getState().secondaryLabel.toString().endsWith("..."));
106 }
107
108 // Test that the tile cancels countdown if it is clicked when the controller is starting
109 @Test
110 public void testCancelRecording() {
111 when(mController.isStarting()).thenReturn(true);
112 when(mController.isRecording()).thenReturn(false);
113
114 mTile.handleClick();
115
116 verify(mController, times(1)).cancelCountdown();
117 }
118
119 // Test that the tile is active and labeled correctly when the controller is recording
120 @Test
121 public void testIsRecording() {
122 when(mController.isStarting()).thenReturn(false);
123 when(mController.isRecording()).thenReturn(true);
124
125 mTile.refreshState();
126 mTestableLooper.processAllMessages();
127
128 assertEquals(Tile.STATE_ACTIVE, mTile.getState().state);
129 assertTrue(mTile.getState().secondaryLabel.toString().equals(
130 mContext.getString(R.string.quick_settings_screen_record_stop)));
131 }
132
133 // Test that the tile stops the recording if it is clicked when the controller is recording
134 @Test
135 public void testStopRecording() {
136 when(mController.isStarting()).thenReturn(false);
137 when(mController.isRecording()).thenReturn(true);
138
139 mTile.handleClick();
140
141 verify(mController, times(1)).stopRecording();
142 }
Fabian Kozynski0daa9702020-04-20 15:03:50 -0400143
144 @Test
145 public void testContentDescriptionHasTileName() {
146 mTile.refreshState();
147 mTestableLooper.processAllMessages();
148
149 assertTrue(mTile.getState().contentDescription.toString().contains(mTile.getState().label));
150 }
Beth Thibodeau58772782020-02-18 20:55:38 -0500151}