Bug 947550 - Use Robotium side swipe methods. r=margaret

This commit is contained in:
Michael Comella 2013-12-11 14:31:55 -08:00
parent 480820bbf7
commit c17f347219
3 changed files with 16 additions and 59 deletions

View File

@ -126,7 +126,6 @@ abstract class UITest extends ActivityInstrumentationTestCase2<Activity>
DeviceHelper.init(this);
GeckoHelper.init(this);
GestureHelper.init(this);
NavigationHelper.init(this);
WaitHelper.init(this);
}

View File

@ -41,6 +41,10 @@ public class AboutHomeComponent extends BaseComponent {
HISTORY
}
// The percentage of the page to swipe between 0 and 1. This value was set through
// testing: 0.55f was tested on try and fails on armv6 devices.
private static final float SWIPE_PERCENTAGE = 0.70f;
public AboutHomeComponent(final UITestContext testContext) {
super(testContext);
}
@ -70,35 +74,33 @@ public class AboutHomeComponent extends BaseComponent {
return this;
}
// TODO: Take specific page as parameter rather than swipe in a direction?
public AboutHomeComponent swipeToPageOnRight() {
mTestContext.dumpLog("Swiping to the page on the right.");
swipe(Solo.LEFT);
swipeToPage(Solo.RIGHT);
return this;
}
public AboutHomeComponent swipeToPageOnLeft() {
mTestContext.dumpLog("Swiping to the page on the left.");
swipe(Solo.RIGHT);
swipeToPage(Solo.LEFT);
return this;
}
private void swipe(final int direction) {
private void swipeToPage(final int pageDirection) {
assertTrue("Swiping in a vaild direction",
pageDirection == Solo.LEFT || pageDirection == Solo.RIGHT);
assertVisible();
final int pageIndex = getHomePagerView().getCurrentItem();
if (direction == Solo.LEFT) {
GestureHelper.swipeLeft();
} else {
GestureHelper.swipeRight();
}
final PagerAdapter adapter = getHomePagerView().getAdapter();
assertNotNull("The HomePager's PagerAdapter is not null", adapter);
mSolo.scrollViewToSide(getHomePagerView(), pageDirection, SWIPE_PERCENTAGE);
// Swiping left goes to next, swiping right goes to previous
final int unboundedPageIndex = pageIndex + (direction == Solo.LEFT ? 1 : -1);
final int expectedPageIndex = Math.min(Math.max(0, unboundedPageIndex), adapter.getCount() - 1);
// The page on the left is a lower index and vice versa.
final int unboundedPageIndex = pageIndex + (pageDirection == Solo.LEFT ? -1 : 1);
final int pageCount = DeviceHelper.isTablet() ?
TabletPage.values().length : PhonePage.values().length;
final int maxPageIndex = pageCount - 1;
final int expectedPageIndex = Math.min(Math.max(0, unboundedPageIndex), maxPageIndex);
waitForPageIndex(expectedPageIndex);
}

View File

@ -1,44 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.tests.helpers;
import org.mozilla.gecko.Driver;
import org.mozilla.gecko.tests.UITestContext;
import com.jayway.android.robotium.solo.Solo;
/**
* Provides simplified gestures wrapping the Robotium gestures API.
*/
public final class GestureHelper {
private static int DEFAULT_DRAG_STEP_COUNT = 10;
private static Solo sSolo;
private static Driver sDriver;
private GestureHelper() { /* To disallow instantation. */ }
public static void init(final UITestContext context) {
sSolo = context.getSolo();
sDriver = context.getDriver();
}
private static void swipeOnScreen(final int direction) {
final int halfWidth = sDriver.getGeckoWidth() / 2;
final int halfHeight = sDriver.getGeckoHeight() / 2;
sSolo.drag(direction == Solo.LEFT ? halfWidth : 0,
direction == Solo.LEFT ? 0 : halfWidth,
halfHeight, halfHeight, DEFAULT_DRAG_STEP_COUNT);
}
public static void swipeLeft() {
swipeOnScreen(Solo.LEFT);
}
public static void swipeRight() {
swipeOnScreen(Solo.RIGHT);
}
}