Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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.junit.Assert.assertEquals; |
| 20 | import static org.mockito.Mockito.doNothing; |
| 21 | import static org.mockito.Mockito.doReturn; |
| 22 | import static org.mockito.Mockito.mock; |
| 23 | import static org.mockito.Mockito.spy; |
| 24 | |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 25 | import android.testing.AndroidTestingRunner; |
| 26 | import android.testing.TestableLooper.RunWithLooper; |
| 27 | import android.util.SparseArray; |
| 28 | import android.view.View; |
| 29 | import android.widget.FrameLayout; |
| 30 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 31 | import androidx.test.filters.SmallTest; |
| 32 | |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 33 | import com.android.systemui.SysuiTestCase; |
| 34 | import com.android.systemui.statusbar.CommandQueue; |
| 35 | |
| 36 | import org.junit.After; |
| 37 | import org.junit.Before; |
| 38 | import org.junit.Test; |
| 39 | import org.junit.runner.RunWith; |
| 40 | |
| 41 | /** atest NavigationBarInflaterViewTest */ |
| 42 | @RunWith(AndroidTestingRunner.class) |
| 43 | @RunWithLooper |
| 44 | @SmallTest |
| 45 | public class NavigationBarInflaterViewTest extends SysuiTestCase { |
| 46 | |
| 47 | private NavigationBarInflaterView mNavBarInflaterView; |
| 48 | |
| 49 | private static final int BUTTON_ID = 0; |
| 50 | |
| 51 | @Before |
| 52 | public void setUp() { |
| 53 | mContext.putComponent(CommandQueue.class, mock(CommandQueue.class)); |
| 54 | |
| 55 | mNavBarInflaterView = spy(new NavigationBarInflaterView(mContext, null)); |
| 56 | doNothing().when(mNavBarInflaterView).createInflaters(); |
| 57 | |
| 58 | mNavBarInflaterView.mButtonDispatchers = new SparseArray<>(1); |
| 59 | mNavBarInflaterView.mButtonDispatchers.put(BUTTON_ID, new ButtonDispatcher(BUTTON_ID)); |
| 60 | |
| 61 | initializeViews(); |
| 62 | } |
| 63 | |
| 64 | private void initializeViews() { |
| 65 | mNavBarInflaterView.mVertical = mock(FrameLayout.class); |
| 66 | mNavBarInflaterView.mHorizontal = mock(FrameLayout.class); |
| 67 | initializeLayout(mNavBarInflaterView.mVertical); |
| 68 | initializeLayout(mNavBarInflaterView.mHorizontal); |
| 69 | } |
| 70 | |
| 71 | private void initializeLayout(FrameLayout layout) { |
| 72 | View verticalChildView = mock(View.class); |
| 73 | verticalChildView.setId(BUTTON_ID); |
| 74 | doReturn(layout).when(verticalChildView).getParent(); |
| 75 | doReturn(verticalChildView).when(layout).findViewById(BUTTON_ID); |
| 76 | } |
| 77 | |
| 78 | @After |
| 79 | public void tearDown() { |
| 80 | mNavBarInflaterView = null; |
| 81 | } |
| 82 | |
| 83 | @Test |
| 84 | public void testUpdateButtonDispatchersCurrentView_isVerticalTrue() { |
| 85 | mNavBarInflaterView.setVertical(true); |
| 86 | |
| 87 | mNavBarInflaterView.updateButtonDispatchersCurrentView(); |
| 88 | |
| 89 | ButtonDispatcher button = mNavBarInflaterView.mButtonDispatchers.get(BUTTON_ID); |
| 90 | assertEquals("Buttons need to be set to vertical layout", |
| 91 | mNavBarInflaterView.mVertical.getId(), |
| 92 | ((View) button.getCurrentView().getParent()).getId()); |
| 93 | } |
| 94 | |
| 95 | @Test |
| 96 | public void testUpdateButtonDispatchersCurrentView_isVerticalFalse() { |
| 97 | mNavBarInflaterView.setVertical(false); |
| 98 | |
| 99 | mNavBarInflaterView.updateButtonDispatchersCurrentView(); |
| 100 | |
| 101 | ButtonDispatcher button = mNavBarInflaterView.mButtonDispatchers.get(BUTTON_ID); |
| 102 | assertEquals("Buttons need to be set to horizon layout", |
| 103 | mNavBarInflaterView.mHorizontal.getId(), |
| 104 | ((View) button.getCurrentView().getParent()).getId()); |
| 105 | } |
| 106 | } |