/AccessCheck/src/com/android/accessibility/AccessibilityValidationContentHandlerTest.java

http://eyes-free.googlecode.com/ · 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. package com.android.accessibility;
  17. import junit.framework.TestCase;
  18. import org.xml.sax.Locator;
  19. import org.xml.sax.SAXException;
  20. import org.xml.sax.helpers.AttributesImpl;
  21. import org.xml.sax.helpers.LocatorImpl;
  22. import java.io.File;
  23. /**
  24. * Unit tests for an AccessibilityValidationContentHandler object
  25. *
  26. * @author dtseng@google.com (David Tseng)
  27. */
  28. public class AccessibilityValidationContentHandlerTest extends TestCase {
  29. private AccessibilityValidationContentHandler mObjectUnderTest;
  30. private Locator mLocator = new LocatorImpl();
  31. private static final String FILE_PATH_PROPERTY = "filePath";
  32. private static final String ANDROID_PATH_PROPERTY = "androidSdkPath";
  33. @Override
  34. protected void setUp() throws Exception {
  35. super.setUp();
  36. mObjectUnderTest = new AccessibilityValidationContentHandler(
  37. System.getProperty(FILE_PATH_PROPERTY), new File(
  38. System.getProperty(ANDROID_PATH_PROPERTY)));
  39. mObjectUnderTest.setDocumentLocator(mLocator);
  40. }
  41. public void testStartElement_withNoContentDescriptionAttributeHasOneValidationError()
  42. throws SAXException {
  43. AttributesImpl atts = new AttributesImpl();
  44. atts.addAttribute("", "testing", "", "", "");
  45. mObjectUnderTest.startElement("", "ImageView", "", atts);
  46. assertTrue(mObjectUnderTest.getValidationErrors() == 1);
  47. }
  48. public void testStartElement_withContentDescriptionAttributeHasNoValidationErrors()
  49. throws SAXException {
  50. AttributesImpl atts = new AttributesImpl();
  51. atts.addAttribute("", "contentDescription", "", "", "");
  52. mObjectUnderTest.startElement("", "ImageView", "", atts);
  53. assertTrue(mObjectUnderTest.getValidationErrors() == 0);
  54. }
  55. public void testStartElement_withMultipleAttributesIncludingContentDescriptionAttributeHasNoValidationErrors()
  56. throws SAXException {
  57. AttributesImpl atts = new AttributesImpl();
  58. atts.addAttribute("", "contentDescription", "", "", "");
  59. atts.addAttribute("", "testing", "", "", "");
  60. atts.addAttribute("", "testing2", "", "", "");
  61. atts.addAttribute("", "contentDescription", "", "", "");
  62. mObjectUnderTest.startElement("", "ImageView", "", atts);
  63. assertTrue(mObjectUnderTest.getValidationErrors() == 0);
  64. }
  65. public void testStartElement_caseInsensitivityForContentDescriptionAttribute()
  66. throws SAXException {
  67. AttributesImpl atts = new AttributesImpl();
  68. atts.addAttribute("", "ContentDescription", "", "", "");
  69. mObjectUnderTest.startElement("", "ImageView", "", atts);
  70. assertTrue(mObjectUnderTest.getValidationErrors() == 0);
  71. }
  72. public void testStartElement_withNoAttributesResultsInNoExceptions()
  73. throws SAXException {
  74. AttributesImpl atts = new AttributesImpl();
  75. mObjectUnderTest.startElement("", "ImageView", "", atts);
  76. // passes if there's no exception thrown
  77. }
  78. }