Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
| 19 | import static org.mockito.Mockito.doReturn; |
| 20 | import static org.mockito.Mockito.mock; |
| 21 | import static org.mockito.Mockito.spy; |
| 22 | import static org.mockito.Mockito.times; |
| 23 | import static org.mockito.Mockito.verify; |
| 24 | |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 25 | import android.view.View; |
| 26 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 27 | import androidx.test.InstrumentationRegistry; |
| 28 | import androidx.test.filters.SmallTest; |
| 29 | import androidx.test.runner.AndroidJUnit4; |
| 30 | |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 31 | import com.android.systemui.SysuiTestCase; |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 32 | import com.android.systemui.SysuiTestableContext; |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 33 | import com.android.systemui.statusbar.policy.KeyButtonDrawable; |
| 34 | import com.android.systemui.statusbar.policy.RotationLockController; |
| 35 | |
| 36 | import org.junit.Before; |
| 37 | import org.junit.Rule; |
| 38 | import org.junit.Test; |
| 39 | import org.junit.runner.RunWith; |
| 40 | import org.mockito.MockitoAnnotations; |
| 41 | |
| 42 | /** atest NavigationBarRotationContextTest */ |
| 43 | @SmallTest |
| 44 | @RunWith(AndroidJUnit4.class) |
| 45 | public 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 Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 52 | private RotationButtonController mRotationButtonController; |
| 53 | private RotationButton mRotationButton; |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 54 | |
| 55 | @Before |
| 56 | public void setup() { |
| 57 | MockitoAnnotations.initMocks(this); |
| 58 | mDependency.injectMockDependency(RotationLockController.class); |
| 59 | |
| 60 | final View view = new View(mContext); |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 61 | mRotationButton = mock(RotationButton.class); |
| 62 | mRotationButtonController = spy( |
| 63 | new RotationButtonController(mContext, RES_UNDEF, mRotationButton)); |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 64 | final KeyButtonDrawable kbd = mock(KeyButtonDrawable.class); |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 65 | doReturn(view).when(mRotationButton).getCurrentView(); |
| 66 | doReturn(true).when(mRotationButton).acceptRotationProposal(); |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | @Test |
| 70 | public void testOnInvalidRotationProposal() { |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 71 | mRotationButtonController.onRotationProposal(DEFAULT_ROTATE, DEFAULT_ROTATE + 1, |
| 72 | false /* isValid */); |
| 73 | verify(mRotationButtonController, times(1)).setRotateSuggestionButtonState( |
| 74 | false /* visible */); |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Test |
| 78 | public void testOnSameRotationProposal() { |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 79 | mRotationButtonController.onRotationProposal(DEFAULT_ROTATE, DEFAULT_ROTATE, |
| 80 | true /* isValid */); |
| 81 | verify(mRotationButtonController, times(1)).setRotateSuggestionButtonState( |
| 82 | false /* visible */); |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | @Test |
| 86 | public void testOnRotationProposalShowButtonShowNav() { |
| 87 | // No navigation bar should not call to set visibility state |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 88 | mRotationButtonController.onNavigationBarWindowVisibilityChange(false /* showing */); |
| 89 | verify(mRotationButtonController, times(0)).setRotateSuggestionButtonState( |
| 90 | false /* visible */); |
| 91 | verify(mRotationButtonController, times(0)).setRotateSuggestionButtonState( |
| 92 | true /* visible */); |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 93 | |
| 94 | // No navigation bar with rotation change should not call to set visibility state |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 95 | 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 Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 101 | |
| 102 | // Since rotation has changed rotation should be pending, show mButton when showing nav bar |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 103 | mRotationButtonController.onNavigationBarWindowVisibilityChange(true /* showing */); |
| 104 | verify(mRotationButtonController, times(1)).setRotateSuggestionButtonState( |
| 105 | true /* visible */); |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @Test |
| 109 | public void testOnRotationProposalShowButton() { |
| 110 | // Navigation bar being visible should not call to set visibility state |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 111 | mRotationButtonController.onNavigationBarWindowVisibilityChange(true /* showing */); |
| 112 | verify(mRotationButtonController, times(0)).setRotateSuggestionButtonState( |
| 113 | false /* visible */); |
| 114 | verify(mRotationButtonController, times(0)).setRotateSuggestionButtonState( |
| 115 | true /* visible */); |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 116 | |
| 117 | // Navigation bar is visible and rotation requested |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 118 | mRotationButtonController.onRotationProposal(DEFAULT_ROTATE, DEFAULT_ROTATE + 1, |
| 119 | true /* isValid */); |
| 120 | verify(mRotationButtonController, times(1)).setRotateSuggestionButtonState( |
| 121 | true /* visible */); |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 122 | } |
| 123 | } |