blob: d6b38ff4936fa730cc41bd5856983d47a1075cf8 [file] [log] [blame]
Matthew Ng761562d2018-09-17 11:13:21 -07001/*
2 * Copyright (C) 2018 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.statusbar.phone;
18
19import static org.mockito.Mockito.doReturn;
20import static org.mockito.Mockito.mock;
21import static org.mockito.Mockito.spy;
22import static org.mockito.Mockito.times;
23import static org.mockito.Mockito.verify;
24
Matthew Ng761562d2018-09-17 11:13:21 -070025import android.view.View;
26
Brett Chabot84151d92019-02-27 15:37:59 -080027import androidx.test.InstrumentationRegistry;
28import androidx.test.filters.SmallTest;
29import androidx.test.runner.AndroidJUnit4;
30
Matthew Ng761562d2018-09-17 11:13:21 -070031import com.android.systemui.SysuiTestCase;
Brett Chabot84151d92019-02-27 15:37:59 -080032import com.android.systemui.SysuiTestableContext;
Matthew Ng761562d2018-09-17 11:13:21 -070033import com.android.systemui.statusbar.policy.KeyButtonDrawable;
34import com.android.systemui.statusbar.policy.RotationLockController;
35
36import org.junit.Before;
37import org.junit.Rule;
38import org.junit.Test;
39import org.junit.runner.RunWith;
40import org.mockito.MockitoAnnotations;
41
42/** atest NavigationBarRotationContextTest */
43@SmallTest
44@RunWith(AndroidJUnit4.class)
45public class NavigationBarRotationContextTest extends SysuiTestCase {
46 static final int RES_UNDEF = 0;
47 static final int DEFAULT_ROTATE = 0;
48
49 @Rule
50 public final SysuiTestableContext mContext = new SysuiTestableContext(
51 InstrumentationRegistry.getContext(), getLeakCheck());
Tracy Zhou24fd0282019-05-20 14:40:38 -070052 private RotationButtonController mRotationButtonController;
53 private RotationButton mRotationButton;
Matthew Ng761562d2018-09-17 11:13:21 -070054
55 @Before
56 public void setup() {
57 MockitoAnnotations.initMocks(this);
58 mDependency.injectMockDependency(RotationLockController.class);
59
60 final View view = new View(mContext);
Tracy Zhou24fd0282019-05-20 14:40:38 -070061 mRotationButton = mock(RotationButton.class);
62 mRotationButtonController = spy(
63 new RotationButtonController(mContext, RES_UNDEF, mRotationButton));
Matthew Ng761562d2018-09-17 11:13:21 -070064 final KeyButtonDrawable kbd = mock(KeyButtonDrawable.class);
Tracy Zhou24fd0282019-05-20 14:40:38 -070065 doReturn(view).when(mRotationButton).getCurrentView();
66 doReturn(true).when(mRotationButton).acceptRotationProposal();
Matthew Ng761562d2018-09-17 11:13:21 -070067 }
68
69 @Test
70 public void testOnInvalidRotationProposal() {
Tracy Zhou24fd0282019-05-20 14:40:38 -070071 mRotationButtonController.onRotationProposal(DEFAULT_ROTATE, DEFAULT_ROTATE + 1,
72 false /* isValid */);
73 verify(mRotationButtonController, times(1)).setRotateSuggestionButtonState(
74 false /* visible */);
Matthew Ng761562d2018-09-17 11:13:21 -070075 }
76
77 @Test
78 public void testOnSameRotationProposal() {
Tracy Zhou24fd0282019-05-20 14:40:38 -070079 mRotationButtonController.onRotationProposal(DEFAULT_ROTATE, DEFAULT_ROTATE,
80 true /* isValid */);
81 verify(mRotationButtonController, times(1)).setRotateSuggestionButtonState(
82 false /* visible */);
Matthew Ng761562d2018-09-17 11:13:21 -070083 }
84
85 @Test
86 public void testOnRotationProposalShowButtonShowNav() {
87 // No navigation bar should not call to set visibility state
Tracy Zhou24fd0282019-05-20 14:40:38 -070088 mRotationButtonController.onNavigationBarWindowVisibilityChange(false /* showing */);
89 verify(mRotationButtonController, times(0)).setRotateSuggestionButtonState(
90 false /* visible */);
91 verify(mRotationButtonController, times(0)).setRotateSuggestionButtonState(
92 true /* visible */);
Matthew Ng761562d2018-09-17 11:13:21 -070093
94 // No navigation bar with rotation change should not call to set visibility state
Tracy Zhou24fd0282019-05-20 14:40:38 -070095 mRotationButtonController.onRotationProposal(DEFAULT_ROTATE, DEFAULT_ROTATE + 1,
96 true /* isValid */);
97 verify(mRotationButtonController, times(0)).setRotateSuggestionButtonState(
98 false /* visible */);
99 verify(mRotationButtonController, times(0)).setRotateSuggestionButtonState(
100 true /* visible */);
Matthew Ng761562d2018-09-17 11:13:21 -0700101
102 // Since rotation has changed rotation should be pending, show mButton when showing nav bar
Tracy Zhou24fd0282019-05-20 14:40:38 -0700103 mRotationButtonController.onNavigationBarWindowVisibilityChange(true /* showing */);
104 verify(mRotationButtonController, times(1)).setRotateSuggestionButtonState(
105 true /* visible */);
Matthew Ng761562d2018-09-17 11:13:21 -0700106 }
107
108 @Test
109 public void testOnRotationProposalShowButton() {
110 // Navigation bar being visible should not call to set visibility state
Tracy Zhou24fd0282019-05-20 14:40:38 -0700111 mRotationButtonController.onNavigationBarWindowVisibilityChange(true /* showing */);
112 verify(mRotationButtonController, times(0)).setRotateSuggestionButtonState(
113 false /* visible */);
114 verify(mRotationButtonController, times(0)).setRotateSuggestionButtonState(
115 true /* visible */);
Matthew Ng761562d2018-09-17 11:13:21 -0700116
117 // Navigation bar is visible and rotation requested
Tracy Zhou24fd0282019-05-20 14:40:38 -0700118 mRotationButtonController.onRotationProposal(DEFAULT_ROTATE, DEFAULT_ROTATE + 1,
119 true /* isValid */);
120 verify(mRotationButtonController, times(1)).setRotateSuggestionButtonState(
121 true /* visible */);
Matthew Ng761562d2018-09-17 11:13:21 -0700122 }
123}