blob: 28e91eaadd491eb9fe273546b1daf396abfc1869 [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.TestableDependency;
34import com.android.systemui.statusbar.policy.KeyButtonDrawable;
35import com.android.systemui.statusbar.policy.RotationLockController;
36
37import org.junit.Before;
38import org.junit.Rule;
39import org.junit.Test;
40import org.junit.runner.RunWith;
41import org.mockito.MockitoAnnotations;
42
43/** atest NavigationBarRotationContextTest */
44@SmallTest
45@RunWith(AndroidJUnit4.class)
46public class NavigationBarRotationContextTest extends SysuiTestCase {
47 static final int RES_UNDEF = 0;
48 static final int DEFAULT_ROTATE = 0;
49
50 @Rule
51 public final SysuiTestableContext mContext = new SysuiTestableContext(
52 InstrumentationRegistry.getContext(), getLeakCheck());
53 private final TestableDependency mDependency = new TestableDependency(mContext);
54 private RotationContextButton mButton;
55
56 @Before
57 public void setup() {
58 MockitoAnnotations.initMocks(this);
59 mDependency.injectMockDependency(RotationLockController.class);
60
61 final View view = new View(mContext);
62 mButton = spy(new RotationContextButton(RES_UNDEF, RES_UNDEF, mContext, RES_UNDEF));
63 final KeyButtonDrawable kbd = mock(KeyButtonDrawable.class);
64 doReturn(view).when(mButton).getCurrentView();
65 doReturn(kbd).when(mButton).getNewDrawable();
66 }
67
68 @Test
69 public void testOnInvalidRotationProposal() {
70 mButton.onRotationProposal(DEFAULT_ROTATE, DEFAULT_ROTATE + 1, false /* isValid */);
71 verify(mButton, times(1)).setRotateSuggestionButtonState(false /* visible */);
72 }
73
74 @Test
75 public void testOnSameRotationProposal() {
76 mButton.onRotationProposal(DEFAULT_ROTATE, DEFAULT_ROTATE, true /* isValid */);
77 verify(mButton, times(1)).setRotateSuggestionButtonState(false /* visible */);
78 }
79
80 @Test
81 public void testOnRotationProposalShowButtonShowNav() {
82 // No navigation bar should not call to set visibility state
83 mButton.onNavigationBarWindowVisibilityChange(false /* showing */);
84 verify(mButton, times(0)).setRotateSuggestionButtonState(false /* visible */);
85 verify(mButton, times(0)).setRotateSuggestionButtonState(true /* visible */);
86
87 // No navigation bar with rotation change should not call to set visibility state
88 mButton.onRotationProposal(DEFAULT_ROTATE, DEFAULT_ROTATE + 1, true /* isValid */);
89 verify(mButton, times(0)).setRotateSuggestionButtonState(false /* visible */);
90 verify(mButton, times(0)).setRotateSuggestionButtonState(true /* visible */);
91
92 // Since rotation has changed rotation should be pending, show mButton when showing nav bar
93 mButton.onNavigationBarWindowVisibilityChange(true /* showing */);
94 verify(mButton, times(1)).setRotateSuggestionButtonState(true /* visible */);
95 }
96
97 @Test
98 public void testOnRotationProposalShowButton() {
99 // Navigation bar being visible should not call to set visibility state
100 mButton.onNavigationBarWindowVisibilityChange(true /* showing */);
101 verify(mButton, times(0)).setRotateSuggestionButtonState(false /* visible */);
102 verify(mButton, times(0)).setRotateSuggestionButtonState(true /* visible */);
103
104 // Navigation bar is visible and rotation requested
105 mButton.onRotationProposal(DEFAULT_ROTATE, DEFAULT_ROTATE + 1, true /* isValid */);
106 verify(mButton, times(1)).setRotateSuggestionButtonState(true /* visible */);
107 }
108}