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