1 /* 2 * Copyright 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 androidx.core.view.accessibility; 18 19 import static org.hamcrest.CoreMatchers.is; 20 import static org.hamcrest.core.IsEqual.equalTo; 21 import static org.junit.Assert.assertThat; 22 23 import android.os.Build; 24 import android.support.test.filters.SdkSuppress; 25 import android.support.test.filters.SmallTest; 26 import android.support.test.runner.AndroidJUnit4; 27 import android.view.accessibility.AccessibilityNodeInfo; 28 29 import org.junit.Test; 30 import org.junit.runner.RunWith; 31 32 @SmallTest 33 @RunWith(AndroidJUnit4.class) 34 public class AccessibilityNodeInfoCompatTest { 35 @Test 36 public void testSetCollectionInfoIsNullable() throws Exception { 37 AccessibilityNodeInfoCompat accessibilityNodeInfoCompat = obtainedWrappedNodeCompat(); 38 accessibilityNodeInfoCompat.setCollectionInfo(null); 39 } 40 41 @Test 42 public void testSetCollectionItemInfoIsNullable() throws Exception { 43 AccessibilityNodeInfoCompat accessibilityNodeInfoCompat = obtainedWrappedNodeCompat(); 44 accessibilityNodeInfoCompat.setCollectionItemInfo(null); 45 } 46 47 @Test 48 public void testGetSetHintText() { 49 final CharSequence hintText = (Build.VERSION.SDK_INT >= 19) ? "hint text" : null; 50 AccessibilityNodeInfoCompat nodeCompat = obtainedWrappedNodeCompat(); 51 nodeCompat.setHintText(hintText); 52 assertThat(nodeCompat.getHintText(), equalTo(hintText)); 53 } 54 55 @Test 56 public void testGetSetPaneTitle() { 57 final CharSequence paneTitle = (Build.VERSION.SDK_INT >= 19) ? "pane title" : null; 58 AccessibilityNodeInfoCompat nodeCompat = obtainedWrappedNodeCompat(); 59 nodeCompat.setPaneTitle(paneTitle); 60 assertThat(nodeCompat.getPaneTitle(), equalTo(paneTitle)); 61 } 62 63 @Test 64 public void testGetSetTooltipText() { 65 final CharSequence tooltipText = (Build.VERSION.SDK_INT >= 19) ? "tooltip" : null; 66 AccessibilityNodeInfoCompat nodeCompat = obtainedWrappedNodeCompat(); 67 nodeCompat.setTooltipText(tooltipText); 68 assertThat(nodeCompat.getTooltipText(), equalTo(tooltipText)); 69 } 70 71 @SdkSuppress(minSdkVersion = 19) 72 @Test 73 public void testGetSetShowingHintText() { 74 AccessibilityNodeInfoCompat nodeCompat = obtainedWrappedNodeCompat(); 75 nodeCompat.setShowingHintText(true); 76 assertThat(nodeCompat.isShowingHintText(), is(true)); 77 nodeCompat.setShowingHintText(false); 78 assertThat(nodeCompat.isShowingHintText(), is(false)); 79 } 80 81 @SdkSuppress(minSdkVersion = 19) 82 @Test 83 public void testGetSetScreenReaderFocusable() { 84 AccessibilityNodeInfoCompat nodeCompat = obtainedWrappedNodeCompat(); 85 nodeCompat.setScreenReaderFocusable(true); 86 assertThat(nodeCompat.isScreenReaderFocusable(), is(true)); 87 nodeCompat.setScreenReaderFocusable(false); 88 assertThat(nodeCompat.isScreenReaderFocusable(), is(false)); 89 } 90 91 @SdkSuppress(minSdkVersion = 19) 92 @Test 93 public void testGetSetHeading() { 94 AccessibilityNodeInfoCompat nodeCompat = obtainedWrappedNodeCompat(); 95 nodeCompat.setHeading(true); 96 assertThat(nodeCompat.isHeading(), is(true)); 97 nodeCompat.setHeading(false); 98 assertThat(nodeCompat.isHeading(), is(false)); 99 AccessibilityNodeInfoCompat.CollectionItemInfoCompat collectionItemInfo = 100 AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(0, 1, 0, 1, true); 101 nodeCompat.setCollectionItemInfo(collectionItemInfo); 102 assertThat(nodeCompat.isHeading(), is(true)); 103 } 104 105 private AccessibilityNodeInfoCompat obtainedWrappedNodeCompat() { 106 AccessibilityNodeInfo accessibilityNodeInfo = AccessibilityNodeInfo.obtain(); 107 return AccessibilityNodeInfoCompat.wrap(accessibilityNodeInfo); 108 } 109 } 110