blob: cec7feb237528993d1b527171cd2d240422f6a6e [file] [log] [blame]
Charles Chenaa94d95b2019-02-19 14:18:19 +08001/*
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
17package com.android.systemui.statusbar.phone;
18
19import static org.junit.Assert.assertEquals;
20import static org.mockito.Mockito.doNothing;
21import static org.mockito.Mockito.doReturn;
22import static org.mockito.Mockito.mock;
23import static org.mockito.Mockito.spy;
24
Charles Chenaa94d95b2019-02-19 14:18:19 +080025import android.testing.AndroidTestingRunner;
26import android.testing.TestableLooper.RunWithLooper;
27import android.util.SparseArray;
28import android.view.View;
29import android.widget.FrameLayout;
30
Brett Chabot84151d92019-02-27 15:37:59 -080031import androidx.test.filters.SmallTest;
32
Charles Chenaa94d95b2019-02-19 14:18:19 +080033import com.android.systemui.SysuiTestCase;
34import com.android.systemui.statusbar.CommandQueue;
35
36import org.junit.After;
37import org.junit.Before;
38import org.junit.Test;
39import org.junit.runner.RunWith;
40
41/** atest NavigationBarInflaterViewTest */
42@RunWith(AndroidTestingRunner.class)
43@RunWithLooper
44@SmallTest
45public 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}