blob: fd403db70a61f0668a53bdd48e696c538e02cf15 [file] [log] [blame]
Bill Lin32ed3d62018-10-02 18:10:09 +08001/*
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.power;
18
19import static com.google.common.truth.Truth.assertThat;
20
21import static org.mockito.Mockito.atLeastOnce;
22import static org.mockito.Mockito.spy;
23import static org.mockito.Mockito.verify;
24
25import android.os.SystemClock;
Bill Lin32ed3d62018-10-02 18:10:09 +080026import android.testing.AndroidTestingRunner;
27import android.testing.TestableLooper.RunWithLooper;
28import android.view.KeyEvent;
29import android.view.MotionEvent;
30import android.view.WindowManager;
31
Brett Chabot0a4ceee2019-03-01 10:55:38 -080032import androidx.test.filters.SmallTest;
33
Bill Lin32ed3d62018-10-02 18:10:09 +080034import com.android.systemui.SysuiTestCase;
35
36import org.junit.After;
37import org.junit.Before;
38import org.junit.Test;
39import org.junit.runner.RunWith;
40
41
42@RunWith(AndroidTestingRunner.class)
43@RunWithLooper(setAsMainLooper = true)
44@SmallTest
45public class OverheatAlarmDialogTest extends SysuiTestCase {
46
47 private OverheatAlarmDialog mDialog, mSpyDialog;
48
49 @Before
50 public void setup() {
51 mDialog = new OverheatAlarmDialog(mContext);
52 mSpyDialog = spy(mDialog);
53 }
54
55 @After
56 public void tearDown() {
57 mSpyDialog = mDialog = null;
58 }
59
60 @Test
61 public void testFlagShowForAllUsers() {
62 assertThat((mDialog.getWindow().getAttributes().privateFlags
63 & WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS) != 0).isTrue();
64 }
65
66 @Test
67 public void testFlagShowWhenLocked() {
68 assertThat((mDialog.getWindow().getAttributes().flags
69 & WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED) != 0).isTrue();
70 }
71
72 @Test
73 public void testFlagTurnScreenOn() {
74 assertThat((mDialog.getWindow().getAttributes().flags
75 & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0).isTrue();
76 }
77
78 @Test
79 public void testFlagKeepScreenOn() {
80 assertThat((mDialog.getWindow().getAttributes().flags
81 & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) != 0).isTrue();
82 }
83
84 @Test
85 public void testTouchOutsideDialog_NotifyAlarmBeepSoundIntent_ShouldStopBeepSound() {
86 final long currentTime = SystemClock.uptimeMillis();
87 mSpyDialog.show();
88 MotionEvent ev = createMotionEvent(MotionEvent.ACTION_DOWN, currentTime, 0, 0);
89 mSpyDialog.dispatchTouchEvent(ev);
90
91 verify(mSpyDialog, atLeastOnce()).notifyAlarmBeepSoundChange();
92 mSpyDialog.dismiss();
93 }
94
95 @Test
96 public void testPressBackKey_NotifyAlarmBeepSoundIntent_ShouldStopBeepSound() {
97 mSpyDialog.show();
98 KeyEvent ev = new KeyEvent(0, 0, MotionEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK, 0,
99 0);
100 mSpyDialog.dispatchKeyEvent(ev);
101
102 verify(mSpyDialog, atLeastOnce()).notifyAlarmBeepSoundChange();
103 mSpyDialog.dismiss();
104 }
105
106 @Test
107 public void testPressVolumeUp_NotifyAlarmBeepSoundIntent_ShouldStopBeepSound() {
108 mSpyDialog.show();
109 KeyEvent ev = new KeyEvent(0, 0, MotionEvent.ACTION_DOWN,
110 KeyEvent.KEYCODE_VOLUME_UP, 0, 0);
111 mSpyDialog.dispatchKeyEvent(ev);
112
113 verify(mSpyDialog, atLeastOnce()).notifyAlarmBeepSoundChange();
114 mSpyDialog.dismiss();
115 }
116
117 @Test
118 public void testPressVolumeDown_NotifyAlarmBeepSoundIntent_ShouldStopBeepSound() {
119 mSpyDialog.show();
120 KeyEvent ev = new KeyEvent(0, 0, MotionEvent.ACTION_DOWN,
121 KeyEvent.KEYCODE_VOLUME_DOWN, 0, 0);
122 mSpyDialog.dispatchKeyEvent(ev);
123
124 verify(mSpyDialog, atLeastOnce()).notifyAlarmBeepSoundChange();
125 mSpyDialog.dismiss();
126 }
127
128 private MotionEvent createMotionEvent(int action, long eventTime, float x, float y) {
129 return MotionEvent.obtain(0, eventTime, action, x, y, 0);
130 }
131}