Home | History | Annotate | Download | only in uiautomation
      1 /*
      2  * Copyright (C) 2013 DroidDriver committers
      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 com.google.android.droiddriver.uiautomation;
     18 
     19 import android.app.Instrumentation;
     20 import android.view.accessibility.AccessibilityNodeInfo;
     21 
     22 import com.google.android.droiddriver.validators.DefaultAccessibilityValidator;
     23 import com.google.android.droiddriver.validators.ExemptRootValidator;
     24 import com.google.android.droiddriver.validators.FirstApplicableValidator;
     25 import com.google.android.droiddriver.validators.ExemptedClassesValidator;
     26 import com.google.android.droiddriver.validators.ExemptScrollActionValidator;
     27 import com.google.android.droiddriver.validators.Validator;
     28 
     29 /**
     30  * A UiAutomationDriver that validates accessibility.
     31  */
     32 public class AccessibilityDriver extends UiAutomationDriver {
     33   private Validator validator = new FirstApplicableValidator(new ExemptRootValidator(),
     34       new ExemptScrollActionValidator(), new ExemptedClassesValidator(),
     35       // TODO: ImageViewValidator
     36       new DefaultAccessibilityValidator());
     37 
     38   public AccessibilityDriver(Instrumentation instrumentation) {
     39     super(instrumentation);
     40   }
     41 
     42   @Override
     43   protected UiAutomationElement newUiElement(AccessibilityNodeInfo rawElement,
     44       UiAutomationElement parent) {
     45     UiAutomationElement newUiElement = super.newUiElement(rawElement, parent);
     46     newUiElement.setValidator(validator);
     47     return newUiElement;
     48   }
     49 
     50   /**
     51    * Gets the current validator.
     52    */
     53   public Validator getValidator() {
     54     return validator;
     55   }
     56 
     57   /**
     58    * Sets the validator to check.
     59    */
     60   public void setValidator(Validator validator) {
     61     this.validator = validator;
     62   }
     63 }
     64