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 android.accessibilityservice.AccessibilityButtonController; 18 import android.app.Instrumentation; 19 import android.platform.test.annotations.AppModeFull; 20 import android.support.test.InstrumentationRegistry; 21 import android.support.test.runner.AndroidJUnit4; 22 23 import org.junit.After; 24 import org.junit.Before; 25 import org.junit.Test; 26 import org.junit.runner.RunWith; 27 28 /** 29 * Test cases for accessibility service APIs related to the accessibility button within 30 * software-rendered navigation bars. 31 * 32 * TODO: Extend coverage with a more precise signal if a device is compatible with the button 33 */ 34 @RunWith(AndroidJUnit4.class) 35 public class AccessibilityButtonTest { 36 37 private StubAccessibilityButtonService mService; 38 private AccessibilityButtonController mButtonController; 39 private AccessibilityButtonController.AccessibilityButtonCallback mStubCallback = 40 new AccessibilityButtonController.AccessibilityButtonCallback() { 41 @Override 42 public void onClicked(AccessibilityButtonController controller) { 43 /* do nothing */ 44 } 45 46 @Override 47 public void onAvailabilityChanged(AccessibilityButtonController controller, 48 boolean available) { 49 /* do nothing */ 50 } 51 }; 52 53 @Before 54 public void setUp() { 55 Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); 56 mService = StubAccessibilityButtonService.enableSelf(instrumentation); 57 mButtonController = mService.getAccessibilityButtonController(); 58 } 59 60 @After 61 public void tearDown() { 62 mService.runOnServiceSync(() -> mService.disableSelf()); 63 } 64 65 @Test 66 @AppModeFull 67 public void testCallbackRegistrationUnregistration_serviceDoesNotCrash() { 68 mButtonController.registerAccessibilityButtonCallback(mStubCallback); 69 mButtonController.unregisterAccessibilityButtonCallback(mStubCallback); 70 } 71 } 72