Eugene Susla | 554edd3 | 2017-05-24 16:49:59 -0700 | [diff] [blame^] | 1 | package com.android.server.accessibility; |
| 2 | |
| 3 | import static org.junit.Assert.fail; |
| 4 | |
| 5 | import android.support.test.runner.AndroidJUnit4; |
| 6 | import android.util.ArraySet; |
| 7 | import android.view.accessibility.AccessibilityNodeInfo; |
| 8 | import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; |
| 9 | |
| 10 | import com.android.internal.util.CollectionUtils; |
| 11 | |
| 12 | import org.junit.Test; |
| 13 | import org.junit.runner.RunWith; |
| 14 | |
| 15 | import java.util.ArrayList; |
| 16 | |
| 17 | @RunWith(AndroidJUnit4.class) |
| 18 | public class AccessibilityNodeInfoTest { |
| 19 | |
| 20 | @Test |
| 21 | public void testStandardActions_serializationFlagIsValid() { |
| 22 | AccessibilityAction brokenStandardAction = CollectionUtils.find( |
| 23 | new ArrayList<>(AccessibilityAction.sStandardActions), |
| 24 | action -> Integer.bitCount(action.mSerializationFlag) != 1); |
| 25 | if (brokenStandardAction != null) { |
| 26 | String message = "Invalid serialization flag(0x" |
| 27 | + Integer.toHexString(brokenStandardAction.mSerializationFlag) |
| 28 | + ") in " + brokenStandardAction; |
| 29 | if (brokenStandardAction.mSerializationFlag == 0L) { |
| 30 | message += "\nThis is likely due to an overflow"; |
| 31 | } |
| 32 | fail(message); |
| 33 | } |
| 34 | |
| 35 | brokenStandardAction = CollectionUtils.find( |
| 36 | new ArrayList<>(AccessibilityAction.sStandardActions), |
| 37 | action -> Integer.bitCount(action.getId()) == 1 |
| 38 | && action.getId() <= AccessibilityNodeInfo.LAST_LEGACY_STANDARD_ACTION |
| 39 | && action.getId() != action.mSerializationFlag); |
| 40 | if (brokenStandardAction != null) { |
| 41 | fail("Serialization flag(0x" |
| 42 | + Integer.toHexString(brokenStandardAction.mSerializationFlag) |
| 43 | + ") is different from legacy action id(0x" |
| 44 | + Integer.toHexString(brokenStandardAction.getId()) |
| 45 | + ") in " + brokenStandardAction); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | @Test |
| 50 | public void testStandardActions_idsAreUnique() { |
| 51 | ArraySet<AccessibilityAction> actions = AccessibilityAction.sStandardActions; |
| 52 | for (int i = 0; i < actions.size(); i++) { |
| 53 | for (int j = 0; j < i; j++) { |
| 54 | int id = actions.valueAt(i).getId(); |
| 55 | if (id == actions.valueAt(j).getId()) { |
| 56 | fail("Id 0x" + Integer.toHexString(id) |
| 57 | + " is duplicated for standard actions #" + i + " and #" + j); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | } |