Bill Lin | 32ed3d6 | 2018-10-02 18:10:09 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.power; |
| 18 | |
| 19 | import static com.google.common.truth.Truth.assertThat; |
| 20 | |
| 21 | import static org.mockito.Mockito.atLeastOnce; |
| 22 | import static org.mockito.Mockito.spy; |
| 23 | import static org.mockito.Mockito.verify; |
| 24 | |
| 25 | import android.os.SystemClock; |
| 26 | import android.support.test.filters.SmallTest; |
| 27 | import android.testing.AndroidTestingRunner; |
| 28 | import android.testing.TestableLooper.RunWithLooper; |
| 29 | import android.view.KeyEvent; |
| 30 | import android.view.MotionEvent; |
| 31 | import android.view.WindowManager; |
| 32 | |
| 33 | import com.android.systemui.SysuiTestCase; |
| 34 | |
| 35 | import org.junit.After; |
| 36 | import org.junit.Before; |
| 37 | import org.junit.Test; |
| 38 | import org.junit.runner.RunWith; |
| 39 | |
| 40 | |
| 41 | @RunWith(AndroidTestingRunner.class) |
| 42 | @RunWithLooper(setAsMainLooper = true) |
| 43 | @SmallTest |
| 44 | public 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 | } |