1 /* 2 * Copyright (C) 2022 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.launcher3.util 18 19 import android.view.InputDevice 20 import android.view.MotionEvent 21 import androidx.test.ext.junit.runners.AndroidJUnit4 22 import androidx.test.filters.SmallTest 23 import com.google.common.truth.Truth.assertThat 24 import org.junit.Test 25 import org.junit.runner.RunWith 26 27 /** Unit tests for [TouchUtil] */ 28 @SmallTest 29 @RunWith(AndroidJUnit4::class) 30 class TouchUtilTest { 31 32 @Test isMouseRightClickDownOrMove_onMouseRightButton_returnsTruenull33 fun isMouseRightClickDownOrMove_onMouseRightButton_returnsTrue() { 34 val ev = MotionEvent.obtain(200, 300, MotionEvent.ACTION_MOVE, 1.0f, 0.0f, 0) 35 ev.source = InputDevice.SOURCE_MOUSE 36 ev.buttonState = MotionEvent.BUTTON_SECONDARY 37 38 assertThat(TouchUtil.isMouseRightClickDownOrMove(ev)).isTrue() 39 } 40 41 @Test isMouseRightClickDownOrMove_onMouseLeftButton_returnsFalsenull42 fun isMouseRightClickDownOrMove_onMouseLeftButton_returnsFalse() { 43 val ev = MotionEvent.obtain(200, 300, MotionEvent.ACTION_MOVE, 1.0f, 0.0f, 0) 44 ev.source = InputDevice.SOURCE_MOUSE 45 ev.buttonState = MotionEvent.BUTTON_PRIMARY 46 47 assertThat(TouchUtil.isMouseRightClickDownOrMove(ev)).isFalse() 48 } 49 50 @Test isMouseRightClickDownOrMove_onMouseTertiaryButton_returnsFalsenull51 fun isMouseRightClickDownOrMove_onMouseTertiaryButton_returnsFalse() { 52 val ev = MotionEvent.obtain(200, 300, MotionEvent.ACTION_MOVE, 1.0f, 0.0f, 0) 53 ev.source = InputDevice.SOURCE_MOUSE 54 ev.buttonState = MotionEvent.BUTTON_TERTIARY 55 56 assertThat(TouchUtil.isMouseRightClickDownOrMove(ev)).isFalse() 57 } 58 59 @Test isMouseRightClickDownOrMove_onDpadRightButton_returnsFalsenull60 fun isMouseRightClickDownOrMove_onDpadRightButton_returnsFalse() { 61 val ev = MotionEvent.obtain(200, 300, MotionEvent.ACTION_MOVE, 1.0f, 0.0f, 0) 62 ev.source = InputDevice.SOURCE_DPAD 63 ev.buttonState = MotionEvent.BUTTON_SECONDARY 64 65 assertThat(TouchUtil.isMouseRightClickDownOrMove(ev)).isFalse() 66 } 67 } 68