/AccessCheck/src/com/android/accessibility/AccessibilityValidationContentHandlerTest.java
Java | 91 lines | 57 code | 13 blank | 21 comment | 4 complexity | 87b7d1b6b8ee180158375f4fe098e106 MD5 | raw file
1/* 2 * Copyright 2010 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * 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, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17package com.android.accessibility; 18 19import junit.framework.TestCase; 20 21import org.xml.sax.Locator; 22import org.xml.sax.SAXException; 23import org.xml.sax.helpers.AttributesImpl; 24import org.xml.sax.helpers.LocatorImpl; 25 26import java.io.File; 27 28/** 29 * Unit tests for an AccessibilityValidationContentHandler object 30 * 31 * @author dtseng@google.com (David Tseng) 32 */ 33public class AccessibilityValidationContentHandlerTest extends TestCase { 34 private AccessibilityValidationContentHandler mObjectUnderTest; 35 private Locator mLocator = new LocatorImpl(); 36 37 private static final String FILE_PATH_PROPERTY = "filePath"; 38 private static final String ANDROID_PATH_PROPERTY = "androidSdkPath"; 39 40 @Override 41 protected void setUp() throws Exception { 42 super.setUp(); 43 44 mObjectUnderTest = new AccessibilityValidationContentHandler( 45 System.getProperty(FILE_PATH_PROPERTY), new File( 46 System.getProperty(ANDROID_PATH_PROPERTY))); 47 mObjectUnderTest.setDocumentLocator(mLocator); 48 } 49 50 public void testStartElement_withNoContentDescriptionAttributeHasOneValidationError() 51 throws SAXException { 52 AttributesImpl atts = new AttributesImpl(); 53 atts.addAttribute("", "testing", "", "", ""); 54 mObjectUnderTest.startElement("", "ImageView", "", atts); 55 assertTrue(mObjectUnderTest.getValidationErrors() == 1); 56 } 57 58 public void testStartElement_withContentDescriptionAttributeHasNoValidationErrors() 59 throws SAXException { 60 AttributesImpl atts = new AttributesImpl(); 61 atts.addAttribute("", "contentDescription", "", "", ""); 62 mObjectUnderTest.startElement("", "ImageView", "", atts); 63 assertTrue(mObjectUnderTest.getValidationErrors() == 0); 64 } 65 66 public void testStartElement_withMultipleAttributesIncludingContentDescriptionAttributeHasNoValidationErrors() 67 throws SAXException { 68 AttributesImpl atts = new AttributesImpl(); 69 atts.addAttribute("", "contentDescription", "", "", ""); 70 atts.addAttribute("", "testing", "", "", ""); 71 atts.addAttribute("", "testing2", "", "", ""); 72 atts.addAttribute("", "contentDescription", "", "", ""); 73 mObjectUnderTest.startElement("", "ImageView", "", atts); 74 assertTrue(mObjectUnderTest.getValidationErrors() == 0); 75 } 76 77 public void testStartElement_caseInsensitivityForContentDescriptionAttribute() 78 throws SAXException { 79 AttributesImpl atts = new AttributesImpl(); 80 atts.addAttribute("", "ContentDescription", "", "", ""); 81 mObjectUnderTest.startElement("", "ImageView", "", atts); 82 assertTrue(mObjectUnderTest.getValidationErrors() == 0); 83 } 84 85 public void testStartElement_withNoAttributesResultsInNoExceptions() 86 throws SAXException { 87 AttributesImpl atts = new AttributesImpl(); 88 mObjectUnderTest.startElement("", "ImageView", "", atts); 89 // passes if there's no exception thrown 90 } 91}