blob: 2d28c9f214fb8f39dad03bdf07843a282e4c3253 [file] [log] [blame]
Julia Reynolds561d3f42018-01-26 11:31:02 -05001/*
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.volume;
18
19import static com.android.systemui.volume.Events.DISMISS_REASON_UNKNOWN;
20import static com.android.systemui.volume.Events.SHOW_REASON_UNKNOWN;
21import static com.android.systemui.volume.VolumeDialogControllerImpl.STREAMS;
22
23import static junit.framework.Assert.assertTrue;
24
25import android.app.KeyguardManager;
26import android.media.AudioManager;
27import android.support.test.filters.SmallTest;
28import android.testing.AndroidTestingRunner;
29import android.testing.TestableLooper;
30import android.text.TextUtils;
31import android.view.View;
32import android.view.ViewGroup;
33import android.widget.ImageView;
34
35import com.android.systemui.SysuiTestCase;
36import com.android.systemui.plugins.VolumeDialogController;
37import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper;
38
39import org.junit.Before;
40import org.junit.Test;
41import org.junit.runner.RunWith;
42import org.mockito.Mock;
43import org.mockito.MockitoAnnotations;
44
45import java.util.function.Predicate;
46
47@SmallTest
48@RunWith(AndroidTestingRunner.class)
49@TestableLooper.RunWithLooper
50public class VolumeDialogImplTest extends SysuiTestCase {
51
52 VolumeDialogImpl mDialog;
53
54 @Mock
55 VolumeDialogController mController;
56
57 @Mock
58 KeyguardManager mKeyguard;
59
60 @Mock
61 AccessibilityManagerWrapper mAccessibilityMgr;
62
63 @Before
64 public void setup() throws Exception {
65 MockitoAnnotations.initMocks(this);
66
67 mController = mDependency.injectMockDependency(VolumeDialogController.class);
68 mAccessibilityMgr = mDependency.injectMockDependency(AccessibilityManagerWrapper.class);
69 getContext().addMockSystemService(KeyguardManager.class, mKeyguard);
70
71 mDialog = new VolumeDialogImpl(getContext());
72 mDialog.init(0, null);
73 VolumeDialogController.State state = new VolumeDialogController.State();
74 for (int i = AudioManager.STREAM_VOICE_CALL; i <= AudioManager.STREAM_ACCESSIBILITY; i++) {
75 VolumeDialogController.StreamState ss = new VolumeDialogController.StreamState();
76 ss.name = STREAMS.get(i);
77 state.states.append(i, ss);
78 }
79 mDialog.onStateChangedH(state);
80 }
81
82 private void navigateViews(View view, Predicate<View> condition) {
83 if (view instanceof ViewGroup) {
84 ViewGroup viewGroup = (ViewGroup) view;
85 for (int i = 0; i < viewGroup.getChildCount(); i++) {
86 navigateViews(viewGroup.getChildAt(i), condition);
87 }
88 } else {
89 String resourceName = null;
90 try {
91 resourceName = getContext().getResources().getResourceName(view.getId());
92 } catch (Exception e) {}
93 assertTrue("View " + resourceName != null ? resourceName : view.getId()
94 + " failed test", condition.test(view));
95 }
96 }
97
98 @Test
99 public void testContentDescriptions() {
100 mDialog.show(SHOW_REASON_UNKNOWN);
101 ViewGroup dialog = mDialog.getDialogView();
102
103 navigateViews(dialog, view -> {
104 if (view instanceof ImageView) {
105 return !TextUtils.isEmpty(view.getContentDescription());
106 } else {
107 return true;
108 }
109 });
110
111 mDialog.dismiss(DISMISS_REASON_UNKNOWN);
112 }
113
114}