mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-14 22:05:44 +00:00
Bug 917398 - Update tests for the new tabs in about:home. r=margaret
This commit is contained in:
parent
749f66757b
commit
cee0b3dd6e
@ -49,7 +49,7 @@ public class HomePager extends ViewPager {
|
||||
static final String LIST_TAG_HISTORY = "history";
|
||||
static final String LIST_TAG_BOOKMARKS = "bookmarks";
|
||||
static final String LIST_TAG_READING_LIST = "reading_list";
|
||||
static final String LIST_TAG_MOST_VISITED = "most_visited";
|
||||
static final String LIST_TAG_TOP_SITES = "top_sites";
|
||||
static final String LIST_TAG_MOST_RECENT = "most_recent";
|
||||
static final String LIST_TAG_LAST_TABS = "last_tabs";
|
||||
|
||||
|
@ -175,7 +175,7 @@ public class TopSitesPage extends HomeFragment {
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
mPinSiteListener = new PinSiteListener();
|
||||
|
||||
mList.setTag(HomePager.LIST_TAG_MOST_VISITED);
|
||||
mList.setTag(HomePager.LIST_TAG_TOP_SITES);
|
||||
mList.setHeaderDividersEnabled(false);
|
||||
|
||||
mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
|
@ -24,13 +24,28 @@ import java.util.ArrayList;
|
||||
* To use any of these methods in your test make sure it extends AboutHomeTest instead of BaseTest
|
||||
*/
|
||||
abstract class AboutHomeTest extends BaseTest {
|
||||
protected enum AboutHomeTabs {MOST_VISITED, MOST_RECENT, TABS_FROM_LAST_TIME, BOOKMARKS, READING_LIST};
|
||||
protected ArrayList<String> aboutHomeTabs = new ArrayList<String>() {{
|
||||
add("HISTORY");
|
||||
protected enum AboutHomeTabs {HISTORY, MOST_RECENT, TABS_FROM_LAST_TIME, TOP_SITES, BOOKMARKS, READING_LIST};
|
||||
private ArrayList<String> aboutHomeTabs = new ArrayList<String>() {{
|
||||
add("TOP_SITES");
|
||||
add("BOOKMARKS");
|
||||
add("READING_LIST");
|
||||
}};
|
||||
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
if (aboutHomeTabs.size() < 4) {
|
||||
// Update it for tablets vs. phones.
|
||||
if (mDevice.type.equals("phone")) {
|
||||
aboutHomeTabs.add(0, AboutHomeTabs.HISTORY.toString());
|
||||
} else {
|
||||
aboutHomeTabs.add(AboutHomeTabs.HISTORY.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME: Write new versions of these methods and update their consumers to use the new about:home pages.
|
||||
*/
|
||||
@ -85,7 +100,6 @@ abstract class AboutHomeTest extends BaseTest {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* FIXME: rewrite this to work with fig when rewriting the testBookmarksTab test
|
||||
* This method will edit the bookmark with index = bookmarkIndex from the list of bookmarks
|
||||
@ -142,69 +156,120 @@ abstract class AboutHomeTest extends BaseTest {
|
||||
}
|
||||
}
|
||||
|
||||
// A wait in order for the about:home tab to be rendered after drag/tab selection
|
||||
// A wait in order for the about:home tab to be rendered after drag/tab selection
|
||||
private 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);
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
private void clickAboutHomeTab(AboutHomeTabs tab) {
|
||||
mSolo.clickOnText(tab.toString().replace("_", " "));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method can be used to open the different tabs of about:home
|
||||
* @param AboutHomeTabs enum item {MOST_VISITED, MOST_RECENT, TABS_FROM_LAST_TIME, BOOKMARKS, READING_LIST}
|
||||
* Swipes to an about:home tab.
|
||||
* @param int swipeVector Value and direction to swipe (go left for negative, right for positive).
|
||||
*/
|
||||
private void swipeAboutHome(int swipeVector) {
|
||||
// Increase swipe width, which will especially impact tablets.
|
||||
int swipeWidth = mDriver.getGeckoWidth() - 1;
|
||||
int swipeHeight = mDriver.getGeckoHeight() / 2;
|
||||
|
||||
if (swipeVector >= 0) {
|
||||
// Emulate swipe motion from right to left.
|
||||
for (int i = 0; i < swipeVector; i++) {
|
||||
mActions.drag(swipeWidth, 0, swipeHeight, swipeHeight);
|
||||
mSolo.sleep(100);
|
||||
}
|
||||
} else {
|
||||
// Emulate swipe motion from left to right.
|
||||
for (int i = 0; i > swipeVector; i--) {
|
||||
mActions.drag(0, swipeWidth, swipeHeight, swipeHeight);
|
||||
mSolo.sleep(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method can be used to open the different tabs of about:home.
|
||||
*
|
||||
* @param AboutHomeTabs enum item {MOST_RECENT, TABS_FROM_LAST_TIME, TOP_SITES, BOOKMARKS, READING_LIST}
|
||||
*/
|
||||
protected void openAboutHomeTab(AboutHomeTabs tab) {
|
||||
int halfWidth = mDriver.getGeckoWidth() / 2;
|
||||
int halfHeight = mDriver.getGeckoHeight() / 2;
|
||||
focusUrlBar();
|
||||
ViewPager pager = (ViewPager)mSolo.getView(ViewPager.class, 0);
|
||||
|
||||
// Handle tablets by just clicking the visible tab title.
|
||||
if (mDevice.type.equals("tablet")) {
|
||||
// Just click for tablets, since all the titles are visible.
|
||||
if (AboutHomeTabs.MOST_RECENT == tab || AboutHomeTabs.TABS_FROM_LAST_TIME == tab) {
|
||||
mSolo.clickOnText(AboutHomeTabs.HISTORY.toString());
|
||||
TabWidget tabwidget = (TabWidget)mSolo.getView(TabWidget.class, 0);
|
||||
|
||||
switch (tab) {
|
||||
case MOST_RECENT: {
|
||||
mSolo.clickOnView(tabwidget.getChildAt(0));
|
||||
mAsserter.ok(waitForText(StringHelper.MOST_RECENT_LABEL), "Checking that we are in the most recent tab of about:home", "We are in the most recent tab");
|
||||
break;
|
||||
}
|
||||
case TABS_FROM_LAST_TIME: {
|
||||
mSolo.clickOnView(tabwidget.getChildAt(1));
|
||||
mAsserter.ok(waitForText(StringHelper.TABS_FROM_LAST_TIME_LABEL), "Checking that we are in the Tabs from last time tab of about:home", "We are in the Tabs from last time tab");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
clickAboutHomeTab(tab);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle phones (non-tablets).
|
||||
final int currentTabIndex = pager.getCurrentItem();
|
||||
int tabOffset = aboutHomeTabs.indexOf(tab.toString()) - currentTabIndex;
|
||||
switch (tab) {
|
||||
case TOP_SITES : {
|
||||
swipeAboutHome(tabOffset);
|
||||
waitForAboutHomeTab(aboutHomeTabs.indexOf(tab.toString()));
|
||||
break;
|
||||
}
|
||||
case BOOKMARKS : {
|
||||
mSolo.clickOnText(StringHelper.BOOKMARKS_LABEL);
|
||||
swipeAboutHome(tabOffset);
|
||||
waitForAboutHomeTab(aboutHomeTabs.indexOf(tab.toString()));
|
||||
break;
|
||||
}
|
||||
case MOST_RECENT: {
|
||||
mSolo.clickOnText(StringHelper.BOOKMARKS_LABEL);
|
||||
waitForAboutHomeTab(aboutHomeTabs.indexOf(StringHelper.BOOKMARKS_LABEL));
|
||||
mActions.drag(0, halfWidth, halfHeight, halfHeight);
|
||||
waitForAboutHomeTab(aboutHomeTabs.indexOf(StringHelper.HISTORY_LABEL));
|
||||
TabWidget tabwidget = (TabWidget)mSolo.getView(TabWidget.class, 0);
|
||||
mSolo.clickOnView(tabwidget.getChildAt(1));
|
||||
mAsserter.ok(waitForText(StringHelper.MOST_RECENT_LABEL), "Checking that we are in the most recent tab of about:home", "We are in the most recent tab");
|
||||
break;
|
||||
}
|
||||
case READING_LIST: {
|
||||
mSolo.clickOnText(StringHelper.BOOKMARKS_LABEL);
|
||||
waitForAboutHomeTab(aboutHomeTabs.indexOf(StringHelper.BOOKMARKS_LABEL));
|
||||
mActions.drag(halfWidth, 0, halfHeight, halfHeight);
|
||||
waitForAboutHomeTab(aboutHomeTabs.indexOf(tab.toString()));
|
||||
break;
|
||||
}
|
||||
case MOST_VISITED: {
|
||||
mSolo.clickOnText(StringHelper.BOOKMARKS_LABEL);
|
||||
waitForAboutHomeTab(aboutHomeTabs.indexOf(StringHelper.BOOKMARKS_LABEL));
|
||||
mActions.drag(0, halfWidth, halfHeight, halfHeight);
|
||||
// MOST_RECENT is contained in the HISTORY tab.
|
||||
tabOffset = aboutHomeTabs.indexOf(AboutHomeTabs.HISTORY.toString()) - currentTabIndex;
|
||||
swipeAboutHome(tabOffset);
|
||||
waitForAboutHomeTab(aboutHomeTabs.indexOf(StringHelper.HISTORY_LABEL));
|
||||
TabWidget tabwidget = (TabWidget)mSolo.getView(TabWidget.class, 0);
|
||||
mSolo.clickOnView(tabwidget.getChildAt(0));
|
||||
mAsserter.ok(waitForText(StringHelper.MOST_RECENT_LABEL), "Checking that we are in the most recent tab of about:home", "We are in the most recent tab");
|
||||
break;
|
||||
}
|
||||
case TABS_FROM_LAST_TIME: {
|
||||
mSolo.clickOnText(StringHelper.BOOKMARKS_LABEL);
|
||||
waitForAboutHomeTab(aboutHomeTabs.indexOf(StringHelper.BOOKMARKS_LABEL));
|
||||
mActions.drag(0, halfWidth, halfHeight, halfHeight);
|
||||
// TABS_FROM_LAST_TIME is contained in the HISTORY tab.
|
||||
tabOffset = aboutHomeTabs.indexOf(AboutHomeTabs.HISTORY.toString()) - currentTabIndex;
|
||||
swipeAboutHome(tabOffset);
|
||||
waitForAboutHomeTab(aboutHomeTabs.indexOf(StringHelper.HISTORY_LABEL));
|
||||
TabWidget tabwidget = (TabWidget)mSolo.getView(TabWidget.class, 0);
|
||||
mSolo.clickOnView(tabwidget.getChildAt(2));
|
||||
mSolo.clickOnView(tabwidget.getChildAt(1));
|
||||
mAsserter.ok(waitForText(StringHelper.TABS_FROM_LAST_TIME_LABEL), "Checking that we are in the Tabs from last time tab of about:home", "We are in the Tabs from last time tab");
|
||||
break;
|
||||
}
|
||||
case READING_LIST: {
|
||||
swipeAboutHome(tabOffset);
|
||||
waitForAboutHomeTab(aboutHomeTabs.indexOf(tab.toString()));
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -616,6 +616,7 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
|
||||
public String type; // "tablet" or "phone"
|
||||
public final int width;
|
||||
public final int height;
|
||||
public final float density;
|
||||
|
||||
public Device() {
|
||||
// Determine device version
|
||||
@ -634,6 +635,7 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
|
||||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
|
||||
height = dm.heightPixels;
|
||||
width = dm.widthPixels;
|
||||
density = dm.density;
|
||||
// Determine device type
|
||||
type = "phone";
|
||||
try {
|
||||
|
@ -90,6 +90,7 @@ class StringHelper {
|
||||
|
||||
// Labels for the about:home tabs
|
||||
public static final String HISTORY_LABEL = "HISTORY";
|
||||
public static final String TOP_SITES_LABEL = "TOP SITES";
|
||||
public static final String BOOKMARKS_LABEL = "BOOKMARKS";
|
||||
public static final String READING_LIST_LABEL = "READING LIST";
|
||||
public static final String MOST_RECENT_LABEL = "Most recent";
|
||||
|
@ -35,6 +35,9 @@ public class testShareLink extends AboutHomeTest {
|
||||
ArrayList<String> shareOptions;
|
||||
blockForGeckoReady();
|
||||
|
||||
// FIXME: This is a temporary hack workaround for a permissions problem.
|
||||
openAboutHomeTab(AboutHomeTabs.READING_LIST);
|
||||
|
||||
inputAndLoadUrl(url);
|
||||
verifyPageTitle(urlTitle); // Waiting for page title to ensure the page is loaded
|
||||
|
||||
@ -59,12 +62,8 @@ public class testShareLink extends AboutHomeTest {
|
||||
mSolo.clickLongOnText(urlTitle);
|
||||
verifySharePopup(shareOptions,"urlbar");
|
||||
|
||||
// Test link Context Menu
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
|
||||
|
||||
// The link has a 60px height, so let's try to hit the middle
|
||||
float top = mDriver.getGeckoTop() + 30 * dm.density;
|
||||
float top = mDriver.getGeckoTop() + 30 * mDevice.density;
|
||||
float left = mDriver.getGeckoLeft() + mDriver.getGeckoWidth() / 2;
|
||||
mSolo.clickLongOnScreen(left, top);
|
||||
verifySharePopup("Share Link",shareOptions,"Link");
|
||||
@ -75,26 +74,11 @@ public class testShareLink extends AboutHomeTest {
|
||||
ListView bookmarksList = findListViewWithTag("bookmarks");
|
||||
mAsserter.is(waitForListToLoad(bookmarksList), true, "list is properly loaded");
|
||||
|
||||
int width = mDriver.getGeckoWidth();
|
||||
int height = mDriver.getGeckoHeight();
|
||||
|
||||
// Scroll down a bit so that the bookmarks list has more
|
||||
// items on screen.
|
||||
mActions.drag(width / 2, width / 2, height - 10, height / 2);
|
||||
|
||||
View bookmarksItem = bookmarksList.getChildAt(bookmarksList.getHeaderViewsCount());
|
||||
mSolo.clickLongOnView(bookmarksItem);
|
||||
verifySharePopup(shareOptions,"bookmarks");
|
||||
|
||||
// Test the share popup in the Most Visited tab
|
||||
openAboutHomeTab(AboutHomeTabs.MOST_VISITED);
|
||||
|
||||
ListView mostVisitedList = findListViewWithTag("most_visited");
|
||||
mAsserter.is(waitForListToLoad(mostVisitedList), true, "list is properly loaded");
|
||||
|
||||
View mostVisitedItem = mostVisitedList.getChildAt(mostVisitedList.getHeaderViewsCount());
|
||||
mSolo.clickLongOnView(mostVisitedItem);
|
||||
verifySharePopup(shareOptions,"most visited");
|
||||
// TODO: Tests for new top sites list.
|
||||
|
||||
// Test the share popup in the Most Recent tab
|
||||
openAboutHomeTab(AboutHomeTabs.MOST_RECENT);
|
||||
|
Loading…
Reference in New Issue
Block a user