Bug 896565 - Update testAwesomebarSwipes for new about:home (r=margaret)
--- a/mobile/android/base/resources/layout-large-v11/home_pager.xml
+++ b/mobile/android/base/resources/layout-large-v11/home_pager.xml
@@ -9,15 +9,16 @@
<org.mozilla.gecko.home.HomePager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res-auto"
android:id="@+id/home_pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:visibility="gone">
- <org.mozilla.gecko.home.TabMenuStrip android:layout_width="fill_parent"
+ <org.mozilla.gecko.home.TabMenuStrip android:id="@+id/home_pager_tabs"
+ android:layout_width="fill_parent"
android:layout_height="32dip"
android:background="@color/background_light"
android:layout_gravity="top"
gecko:strip="@drawable/home_tab_menu_strip"/>
</org.mozilla.gecko.home.HomePager>
--- a/mobile/android/base/resources/layout/home_pager.xml
+++ b/mobile/android/base/resources/layout/home_pager.xml
@@ -9,17 +9,18 @@
<org.mozilla.gecko.home.HomePager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res-auto"
android:id="@+id/home_pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:visibility="gone">
- <org.mozilla.gecko.home.HomePagerTabStrip android:layout_width="fill_parent"
+ <org.mozilla.gecko.home.HomePagerTabStrip android:id="@+id/home_pager_tabs"
+ android:layout_width="fill_parent"
android:layout_height="32dip"
android:layout_gravity="top"
android:gravity="bottom"
android:background="@color/background_light"
gecko:tabIndicatorColor="@color/text_color_highlight"
android:textAppearance="@style/TextAppearance.Widget.HomePagerTabStrip"/>
</org.mozilla.gecko.home.HomePager>
--- a/mobile/android/base/tests/AboutHomeTest.java.in
+++ b/mobile/android/base/tests/AboutHomeTest.java.in
@@ -22,21 +22,21 @@ import java.util.ArrayList;
* This class contains methods that access the different tabs from about:home, methods that get information like history and bookmarks from the database, edit and remove bookmarks and history items
* The purpose of this class is to collect all the logically connected methods that deal with about:home
* To use any of these methods in your test make sure it extends AboutHomeTest instead of BaseTest
*/
abstract class AboutHomeTest extends BaseTest {
protected enum BrowserDataType {BOOKMARKS, HISTORY};
protected enum AboutHomeTabs {MOST_VISITED, MOST_RECENT, TABS_FROM_LAST_TIME, BOOKMARKS, READING_LIST};
protected ArrayList<String> aboutHomeTabs = new ArrayList<String>() {{
- add("HISTORY");
- add("BOOKMARKS");
- add("READING_LIST");
+ add(HISTORY_LABEL);
+ add(BOOKMARKS_LABEL);
+ add(READING_LIST_LABEL);
}};
-
+
// Labels for the about:home tabs
protected static final String HISTORY_LABEL = "HISTORY";
protected static final String BOOKMARKS_LABEL = "BOOKMARKS";
protected static final String READING_LIST_LABEL = "READING LIST";
protected static final String MOST_RECENT_LABEL = "Most recent";
protected static final String TABS_FROM_LAST_TIME_LABEL = "Open all tabs from last time";
/**
@@ -325,17 +325,17 @@ abstract class AboutHomeTest extends Bas
} else {
clickOnButton("Cancel");
waitForText("about:home");
return false;
}
}
// A wait in order for the about:home tab to be rendered after drag/tab selection
- private void waitForAboutHomeTab(final int tabIndex) {
+ protected void waitForAboutHomeTab(final int tabIndex) {
boolean correctTab = waitForCondition(new Condition() {
@Override
public boolean isSatisfied() {
ViewPager pager = (ViewPager)mSolo.getView(ViewPager.class, 0);
return (pager.getCurrentItem() == tabIndex);
}
}, MAX_WAIT_MS);
mAsserter.ok(correctTab, "Checking that the correct tab is displayed", "The " + aboutHomeTabs.get(tabIndex) + " tab is displayed");
--- a/mobile/android/base/tests/robocop.ini
+++ b/mobile/android/base/tests/robocop.ini
@@ -1,10 +1,10 @@
[testAwesomebar]
-# [testAwesomebarSwipes] # disabled on fig - bug 880060
+[testAboutHomeSwipes]
# [testBookmark] # disabled on fig - bug 880060
[testBookmarklets]
[testBookmarkKeyword]
[testBrowserSearchVisibility]
[testJNI]
# [testLoad] # see bug 851861
[testNewTab]
[testOrderedBroadcast]
rename from mobile/android/base/tests/testAwesomebarSwipes.java.in
rename to mobile/android/base/tests/testAboutHomeSwipes.java.in
--- a/mobile/android/base/tests/testAwesomebarSwipes.java.in
+++ b/mobile/android/base/tests/testAboutHomeSwipes.java.in
@@ -1,56 +1,84 @@
#filter substitution
package @ANDROID_PACKAGE_NAME@.tests;
import com.jayway.android.robotium.solo.Solo;
+import android.app.Activity;
+import android.text.TextUtils;
+import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TabWidget;
+import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.ViewPager;
import @ANDROID_PACKAGE_NAME@.*;
/* Tests swiping between tabs on the awesome bar and other basic
awesome bar tab selections.
*/
-public class testAwesomebarSwipes extends BaseTest {
+public class testAboutHomeSwipes extends AboutHomeTest {
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
- public void testAwesomebarSwipes() {
+ public void testAboutHomeSwipes() {
blockForGeckoReady();
- // Removed by Bug 896576 - [fig] Remove [getAllPagesList] from BaseTest
- // ListView list = getAllPagesList("about:firefox");
-
// Test normal sliding of the list left and right
- ViewPager pager = (ViewPager)mSolo.getView(ViewPager.class, 0);
- mAsserter.is(pager.getCurrentItem(), 0, "All pages is selected");
-
- int width = mDriver.getGeckoWidth() / 2;
- int y = mDriver.getGeckoHeight() / 2;
- mActions.drag(width, 0, y, y);
- mAsserter.is(pager.getCurrentItem(), 1, "Bookmarks page is selected");
-
- mActions.drag(0, width, y, y);
- mAsserter.is(pager.getCurrentItem(), 0, "All pages is selected");
+ dragTo(Solo.LEFT, aboutHomeTabs.indexOf(HISTORY_LABEL));
+ dragTo(Solo.RIGHT, aboutHomeTabs.indexOf(BOOKMARKS_LABEL));
+ dragTo(Solo.RIGHT, aboutHomeTabs.indexOf(READING_LIST_LABEL));
+ dragTo(Solo.LEFT, aboutHomeTabs.indexOf(BOOKMARKS_LABEL));
// Test tapping on the tab strip changes tabs
- TabWidget tabwidget = (TabWidget)mSolo.getView(TabWidget.class, 0);
- mSolo.clickOnView(tabwidget.getChildAt(1));
- mAsserter.is(pager.getCurrentItem(), 1, "Clicking on tab selected bookmarks page");
+ ViewPager pager = (ViewPager) mSolo.getView(ViewPager.class, 0);
+ ViewGroup tabStrip = getTabStripView();
+
+ selectOnTabsStrip(pager, tabStrip, Solo.LEFT, aboutHomeTabs.indexOf(HISTORY_LABEL));
+ selectOnTabsStrip(pager, tabStrip, Solo.RIGHT, aboutHomeTabs.indexOf(BOOKMARKS_LABEL));
+ selectOnTabsStrip(pager, tabStrip, Solo.RIGHT, aboutHomeTabs.indexOf(READING_LIST_LABEL));
+ selectOnTabsStrip(pager, tabStrip, Solo.LEFT, aboutHomeTabs.indexOf(BOOKMARKS_LABEL));
+ }
+
+ private void dragTo(int direction, int expectedPage) {
+ final int centerX = mDriver.getGeckoWidth() / 2;
+ final int centerY = mDriver.getGeckoHeight() / 2;
+
+ mActions.drag(direction == Solo.LEFT ? 0 : centerX,
+ direction == Solo.LEFT ? centerX : 0,
+ centerY, centerY);
+
+ waitForAboutHomeTab(expectedPage);
+ }
- // Test typing in the awesomebar changes tabs and prevents panning
- mSolo.typeText(0, "woot");
- mAsserter.is(pager.getCurrentItem(), 0, "Searching switched to all pages tab");
- mSolo.scrollToSide(Solo.LEFT);
- mAsserter.is(pager.getCurrentItem(), 0, "Dragging left is not allowed when searching");
+ private ViewGroup getTabStripView() {
+ if (TextUtils.equals(mDevice.type, "phone")) {
+ // On phones, fetch tab strip by class type
+ return (ViewGroup) mSolo.getView(PagerTabStrip.class, 0);
+ } else {
+ // On tablets, fetch tab strip by id to avoid using reflection
+ final Activity activity = getActivity();
+ final int tabStripId = mDriver.findElement(activity, "home_pager_tabs").getId();
+ return (ViewGroup) activity.findViewById(tabStripId);
+ }
+ }
- mSolo.scrollToSide(Solo.RIGHT);
- mAsserter.is(pager.getCurrentItem(), 0, "Dragging right is not allowed when searching");
+ private void selectOnTabsStrip(ViewPager pager, ViewGroup tabStrip, int direction, int expectedPage) {
+ // On phones, we use a pager strip, first child points to previous page,
+ // last child points to next page. On tablets, we use a tab strip where
+ // each child's position matches the corresponding page position in the
+ // ViewPager.
+ final int childIndex;
+ if (TextUtils.equals(mDevice.type, "phone")) {
+ childIndex = (direction == Solo.LEFT ? 0 : 2);
+ } else {
+ childIndex = pager.getCurrentItem() + (direction == Solo.LEFT ? -1 : 1);
+ }
- mActions.sendSpecialKey(Actions.SpecialKey.BACK);
+ // Tap on the tab strip
+ mSolo.clickOnView(tabStrip.getChildAt(childIndex));
+ waitForAboutHomeTab(expectedPage);
}
}