1 /** 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 * express or implied. See the License for the specific language governing permissions and 12 * limitations under the License. 13 */ 14 15 package android.accessibilityservice.cts; 16 17 import static android.accessibilityservice.cts.utils.CtsTestUtils.runIfNotNull; 18 19 import android.accessibilityservice.AccessibilityButtonController; 20 import android.app.Instrumentation; 21 import android.platform.test.annotations.AppModeFull; 22 23 import androidx.test.InstrumentationRegistry; 24 import androidx.test.runner.AndroidJUnit4; 25 26 import org.junit.After; 27 import org.junit.Before; 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 31 /** 32 * Test cases for accessibility service APIs related to the accessibility button within 33 * software-rendered navigation bars. 34 * 35 * TODO: Extend coverage with a more precise signal if a device is compatible with the button 36 */ 37 @RunWith(AndroidJUnit4.class) 38 public class AccessibilityButtonTest { 39 40 private StubAccessibilityButtonService mService; 41 private AccessibilityButtonController mButtonController; 42 private AccessibilityButtonController.AccessibilityButtonCallback mStubCallback = 43 new AccessibilityButtonController.AccessibilityButtonCallback() { 44 @Override 45 public void onClicked(AccessibilityButtonController controller) { 46 /* do nothing */ 47 } 48 49 @Override 50 public void onAvailabilityChanged(AccessibilityButtonController controller, 51 boolean available) { 52 /* do nothing */ 53 } 54 }; 55 56 @Before 57 public void setUp() { 58 Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); 59 mService = StubAccessibilityButtonService.enableSelf(instrumentation); 60 mButtonController = mService.getAccessibilityButtonController(); 61 } 62 63 @After 64 public void tearDown() { 65 runIfNotNull(mService, service -> service.runOnServiceSync(service::disableSelf)); 66 } 67 68 @Test 69 @AppModeFull 70 public void testCallbackRegistrationUnregistration_serviceDoesNotCrash() { 71 mButtonController.registerAccessibilityButtonCallback(mStubCallback); 72 mButtonController.unregisterAccessibilityButtonCallback(mStubCallback); 73 } 74 } 75