1 /** 2 * Copyright (C) 2009 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.view.accessibility; 16 17 import android.test.suitebuilder.annotation.SmallTest; 18 19 import junit.framework.TestCase; 20 21 /** 22 * This class exercises the caching and recycling of {@link AccessibilityEvent}s. 23 */ 24 public class RecycleAccessibilityEventTest extends TestCase { 25 26 private static final String CLASS_NAME = "foo.bar.baz.Test"; 27 private static final String PACKAGE_NAME = "foo.bar.baz"; 28 private static final String TEXT = "Some stuff"; 29 30 private static final String CONTENT_DESCRIPTION = "Content description"; 31 private static final int ITEM_COUNT = 10; 32 private static final int CURRENT_ITEM_INDEX = 1; 33 34 private static final int FROM_INDEX = 1; 35 private static final int ADDED_COUNT = 2; 36 private static final int REMOVED_COUNT = 1; 37 38 /** 39 * If an {@link AccessibilityEvent} is marshaled/unmarshaled correctly 40 */ 41 @SmallTest testAccessibilityEventViewTextChangedType()42 public void testAccessibilityEventViewTextChangedType() { 43 AccessibilityEvent first = 44 AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED); 45 assertNotNull(first); 46 47 first.setClassName(CLASS_NAME); 48 first.setPackageName(PACKAGE_NAME); 49 first.getText().add(TEXT); 50 first.setFromIndex(FROM_INDEX); 51 first.setAddedCount(ADDED_COUNT); 52 first.setRemovedCount(REMOVED_COUNT); 53 first.setChecked(true); 54 first.setContentDescription(CONTENT_DESCRIPTION); 55 first.setItemCount(ITEM_COUNT); 56 first.setCurrentItemIndex(CURRENT_ITEM_INDEX); 57 first.setEnabled(true); 58 first.setPassword(true); 59 60 first.recycle(); 61 62 assertNotNull(first); 63 assertNull(first.getClassName()); 64 assertNull(first.getPackageName()); 65 assertEquals(0, first.getText().size()); 66 assertFalse(first.isChecked()); 67 assertNull(first.getContentDescription()); 68 assertEquals(-1, first.getItemCount()); 69 assertEquals(AccessibilityEvent.INVALID_POSITION, first.getCurrentItemIndex()); 70 assertFalse(first.isEnabled()); 71 assertFalse(first.isPassword()); 72 assertEquals(-1, first.getFromIndex()); 73 assertEquals(-1, first.getAddedCount()); 74 assertEquals(-1, first.getRemovedCount()); 75 76 // get another event from the pool (this must be the recycled first) 77 AccessibilityEvent second = AccessibilityEvent.obtain(); 78 assertEquals(first, second); 79 } 80 } 81