diff options
author | Kevin Jin <kjin@google.com> | 2014-02-04 15:51:06 -0800 |
---|---|---|
committer | Kevin Jin <kjin@google.com> | 2014-02-04 15:51:06 -0800 |
commit | 39b609194aea07e7f1d8ead084d48d1171198f02 (patch) | |
tree | 1a51f2dfea4cc4ca1c45a092558a32d65604fe28 /src | |
parent | 5d6ce8025e73d9f7f1631bfe05cff32b055d1939 (diff) | |
download | droiddriver-39b609194aea07e7f1d8ead084d48d1171198f02.tar.gz |
delete DroidDriver samples to remove dep on actionbarsherlock
add sync on UI thread idle in UiAutomationDriver
refine AccessibilityEventScrollStepStrategy api
Change-Id: I176eb1a40f0a914121c60b887784760ebe354ae4
Diffstat (limited to 'src')
3 files changed, 20 insertions, 19 deletions
diff --git a/src/com/google/android/droiddriver/instrumentation/InstrumentationDriver.java b/src/com/google/android/droiddriver/instrumentation/InstrumentationDriver.java index c8630ec..460817c 100644 --- a/src/com/google/android/droiddriver/instrumentation/InstrumentationDriver.java +++ b/src/com/google/android/droiddriver/instrumentation/InstrumentationDriver.java @@ -35,7 +35,7 @@ import com.google.common.base.Preconditions; import com.google.common.primitives.Longs; /** - * Implementation of a UiDriver that is driven via instrumentation. + * Implementation of DroidDriver that is driven via instrumentation. */ public class InstrumentationDriver extends BaseDroidDriver { private final InstrumentationContext context; diff --git a/src/com/google/android/droiddriver/scroll/AccessibilityEventScrollStepStrategy.java b/src/com/google/android/droiddriver/scroll/AccessibilityEventScrollStepStrategy.java index 447ee08..0c96134 100644 --- a/src/com/google/android/droiddriver/scroll/AccessibilityEventScrollStepStrategy.java +++ b/src/com/google/android/droiddriver/scroll/AccessibilityEventScrollStepStrategy.java @@ -45,9 +45,8 @@ import java.util.concurrent.TimeoutException; */ public class AccessibilityEventScrollStepStrategy implements ScrollStepStrategy { /** - * Stores the data if we reached end at the last - * {@link AccessibilityEventScrollStepStrategy#scroll}. If the data match when - * a new scroll is requested, we can return immediately. + * Stores the data if we reached end at the last {@link #scroll}. If the data + * match when a new scroll is requested, we can return immediately. */ private static class EndData { private Finder containerFinderAtEnd; @@ -79,11 +78,7 @@ public class AccessibilityEventScrollStepStrategy implements ScrollStepStrategy private final long scrollEventTimeoutMillis; private final DirectionConverter directionConverter; private final EndData endData = new EndData(); - private AccessibilityEvent event; - protected AccessibilityEvent getLastEvent() { - return event; - } public AccessibilityEventScrollStepStrategy(UiAutomation uiAutomation, long scrollEventTimeoutMillis, DirectionConverter converter) { this.uiAutomation = uiAutomation; @@ -99,16 +94,15 @@ public class AccessibilityEventScrollStepStrategy implements ScrollStepStrategy return false; } - doScroll(driver.on(containerFinder), direction); - if (detectEnd(direction.axis())) { + AccessibilityEvent event = doScrollAndReturnEvent(driver.on(containerFinder), direction); + if (detectEnd(event, direction.axis())) { endData.set(containerFinder, direction); - Logs.log(Log.DEBUG, "reached scroll end"); + Logs.log(Log.DEBUG, "reached scroll end with event: " + event); } // Clean up the event after use. if (event != null) { - event.recycle(); - event = null; + event.recycle(); } return true; @@ -116,7 +110,7 @@ public class AccessibilityEventScrollStepStrategy implements ScrollStepStrategy // Copied from UiAutomator. // AdapterViews have indices we can use to check for the beginning. - protected boolean detectEnd(Axis axis) { + protected boolean detectEnd(AccessibilityEvent event, Axis axis) { if (event == null) { return true; } @@ -154,18 +148,24 @@ public class AccessibilityEventScrollStepStrategy implements ScrollStepStrategy public void endScrolling(DroidDriver driver, Finder containerFinder, Finder itemFinder, PhysicalDirection direction) {} - @Override - public void doScroll(final UiElement container, final PhysicalDirection direction) { - event = null; + protected AccessibilityEvent doScrollAndReturnEvent(final UiElement container, + final PhysicalDirection direction) { + AccessibilityEvent event = null; try { event = uiAutomation.executeAndWaitForEvent(new Runnable() { @Override public void run() { - SwipeAction.toScroll(direction).perform(container.getInjector(), container); + doScroll(container, direction); } }, SCROLL_EVENT_FILTER, scrollEventTimeoutMillis); } catch (TimeoutException e) { // If no TYPE_VIEW_SCROLLED event, no more scrolling is possible } + return event; + } + + @Override + public void doScroll(final UiElement container, final PhysicalDirection direction) { + SwipeAction.toScroll(direction).perform(container.getInjector(), container); } } diff --git a/src/com/google/android/droiddriver/uiautomation/UiAutomationDriver.java b/src/com/google/android/droiddriver/uiautomation/UiAutomationDriver.java index 0e5ea78..f6c6c62 100644 --- a/src/com/google/android/droiddriver/uiautomation/UiAutomationDriver.java +++ b/src/com/google/android/droiddriver/uiautomation/UiAutomationDriver.java @@ -30,7 +30,7 @@ import com.google.android.droiddriver.util.Logs; import com.google.common.primitives.Longs; /** - * Implementation of a DroidDriver that is driven via the accessibility layer. + * Implementation of DroidDriver that is driven via the accessibility layer. */ public class UiAutomationDriver extends BaseDroidDriver { // TODO: magic const from UiAutomator, but may not be useful @@ -64,6 +64,7 @@ public class UiAutomationDriver extends BaseDroidDriver { private AccessibilityNodeInfo getRootNode() { long timeoutMillis = getPoller().getTimeoutMillis(); try { + context.getInstrumentation().waitForIdleSync(); uiAutomation.waitForIdle(QUIET_TIME_TO_BE_CONSIDERD_IDLE_STATE, timeoutMillis); } catch (java.util.concurrent.TimeoutException e) { throw new TimeoutException(e); |