diff options
author | Kevin Jin <kjin@google.com> | 2014-05-29 15:35:31 -0700 |
---|---|---|
committer | Kevin Jin <kjin@google.com> | 2014-06-05 14:01:34 -0700 |
commit | a738fe74f57f48dde2dd7a28479bab3f5441dadb (patch) | |
tree | 6bcb449c5545660d5057a6323e0e95c5eda0cf5c /src/com/google/android/droiddriver/uiautomation/UiAutomationContext.java | |
parent | b4e825291041d963c5bda0349638565949d999f6 (diff) | |
download | droiddriver-a738fe74f57f48dde2dd7a28479bab3f5441dadb.tar.gz |
add AccessibilityDriver for testing Accessibility
This is the first cut with known issues, e.g. needs to handle
click on EditText differently, etc. Thic cl sets up the architecture
of AccessibilityDriver; details will be filled in follow-up cls.
Change-Id: I2881b28075eba478a5aad9d7e945b5d55e78da89
Diffstat (limited to 'src/com/google/android/droiddriver/uiautomation/UiAutomationContext.java')
-rw-r--r-- | src/com/google/android/droiddriver/uiautomation/UiAutomationContext.java | 76 |
1 files changed, 6 insertions, 70 deletions
diff --git a/src/com/google/android/droiddriver/uiautomation/UiAutomationContext.java b/src/com/google/android/droiddriver/uiautomation/UiAutomationContext.java index fcb7a94..04df113 100644 --- a/src/com/google/android/droiddriver/uiautomation/UiAutomationContext.java +++ b/src/com/google/android/droiddriver/uiautomation/UiAutomationContext.java @@ -17,81 +17,17 @@ package com.google.android.droiddriver.uiautomation; import android.app.Instrumentation; -import android.app.UiAutomation; -import android.view.InputEvent; import android.view.accessibility.AccessibilityNodeInfo; -import com.google.android.droiddriver.actions.InputInjector; -import com.google.android.droiddriver.base.DroidDriverContext; -import com.google.android.droiddriver.exceptions.UnrecoverableException; -import com.google.android.droiddriver.finders.ByXPath; +import com.google.android.droiddriver.uiautomation.base.BaseUiAutomationContext; -import java.util.Map; -import java.util.WeakHashMap; - -class UiAutomationContext extends DroidDriverContext { - private final Map<AccessibilityNodeInfo, UiAutomationElement> map = - new WeakHashMap<AccessibilityNodeInfo, UiAutomationElement>(); - private final UiAutomation uiAutomation; - private final InputInjector injector; - private final UiAutomationDriver driver; - - UiAutomationContext(final Instrumentation instrumentation, UiAutomationDriver driver) { - super(instrumentation); - this.uiAutomation = instrumentation.getUiAutomation(); - this.driver = driver; - this.injector = new InputInjector() { - @Override - public boolean injectInputEvent(final InputEvent event) { - return callUiAutomation(new UiAutomationCallable<Boolean>() { - @Override - public Boolean call(UiAutomation uiAutomation) { - return uiAutomation.injectInputEvent(event, true /* sync */); - } - }); - } - }; - } - - @Override - public UiAutomationDriver getDriver() { - return driver; - } - - @Override - public InputInjector getInjector() { - return injector; - } - - UiAutomationElement getUiElement(AccessibilityNodeInfo node, UiAutomationElement parent) { - UiAutomationElement element = map.get(node); - if (element == null) { - element = new UiAutomationElement(this, node, parent); - map.put(node, element); - } - return element; +class UiAutomationContext extends BaseUiAutomationContext<UiAutomationElement> { + UiAutomationContext(Instrumentation instrumentation, UiAutomationDriver driver) { + super(instrumentation, driver); } @Override - public void clearData() { - map.clear(); - ByXPath.clearData(); - } - - interface UiAutomationCallable<T> { - T call(UiAutomation uiAutomation); - } - - /* - * Wraps calls to UiAutomation API. Currently supports fail-fast if - * UiAutomation throws IllegalStateException, which occurs when the connection - * to UiAutomation service is lost. - */ - <T> T callUiAutomation(UiAutomationCallable<T> uiAutomationCallable) { - try { - return uiAutomationCallable.call(uiAutomation); - } catch (IllegalStateException e) { - throw new UnrecoverableException(e); - } + protected UiAutomationElement newUiElement(AccessibilityNodeInfo node, UiAutomationElement parent) { + return new UiAutomationElement(this, node, parent); } } |