Bug 899182 - Re-write testBookmark to work with the new about:home. r=lucasr

This commit is contained in:
Adrian Tamas 2013-08-19 17:11:09 +03:00
Родитель 8e9b6e6c59
Коммит e0dff986cf
5 изменённых файлов: 134 добавлений и 143 удалений

Просмотреть файл

@ -10,9 +10,13 @@ import android.net.Uri;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TabWidget;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.lang.reflect.Method;
import java.util.ArrayList;
@ -56,6 +60,72 @@ abstract class AboutHomeTest extends BaseTest {
return null;
}
// Returns true if the bookmark is displayed in the bookmarks tab, false otherwise - does not check in folders
protected boolean isBookmarkDisplayed(String url) {
View bookmark = getDisplayedBookmark(url);
if (bookmark != null) {
return true;
} else {
return false;
}
}
// Loads a bookmark by tapping on the bookmark view in the Bookmarks tab
protected void loadBookmark(String url) {
View bookmark = getDisplayedBookmark(url);
if (bookmark != null) {
Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
mSolo.clickOnView(bookmark);
contentEventExpecter.blockForEvent();
contentEventExpecter.unregisterListener();
} else {
mAsserter.ok(false, url + " is not one of the displayed bookmarks", "Please make sure the url provided is ookmarked");
}
}
// Opens the bookmark context menu by long-tapping on it
protected void openBookmarkContextMenu(String url) {
View bookmark = getDisplayedBookmark(url);
if (bookmark != null) {
mSolo.clickLongOnView(bookmark);
waitForText("Share");
} else {
mAsserter.ok(false, url + " is not one of the displayed bookmarks", "Please make sure the url provided is bookmarked");
}
}
// @return the View associated with bookmark for the provided url or null if the link is not bookmarked
protected View getDisplayedBookmark(String url) {
openAboutHomeTab(AboutHomeTabs.BOOKMARKS);
ListView bookmarksTabList = findListViewWithTag("bookmarks");
waitForListToLoad(bookmarksTabList);
ListAdapter adapter = bookmarksTabList.getAdapter();
if (adapter != null) {
for (int i = 0; i < adapter.getCount(); i++ ) {
// I am unable to click the view taken with getView for some reason so getting the child at i
bookmarksTabList.smoothScrollToPosition(i);
View bookmarkView = bookmarksTabList.getChildAt(i);
if (bookmarkView instanceof android.widget.LinearLayout) {
ViewGroup bookmarkItemView = (ViewGroup) bookmarkView;
for (int j = 0 ; j < bookmarkItemView.getChildCount(); j++) {
View bookmarkContent = bookmarkItemView.getChildAt(j);
if (bookmarkContent instanceof android.widget.LinearLayout) {
ViewGroup bookmarkItemLayout = (ViewGroup) bookmarkContent;
for (int k = 0 ; k < bookmarkItemLayout.getChildCount(); k++) {
// Both the title and url are represented as text views so we can cast the view without any ssues
TextView bookmarkTextContent = (TextView)bookmarkItemLayout.getChildAt(k);
if (url.equals(bookmarkTextContent.getText().toString())) {
return bookmarkView;
}
}
}
}
}
}
}
return null;
}
/**
* Waits for the given ListView to have a non-empty adapter.
*

Просмотреть файл

@ -713,28 +713,18 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
// DEPRECATED!
// Use BaseTest.toggleBookmark() in new code.
public void bookmark() {
if (devType.equals("tablet")) {
if (!osVersion.equals("4.x")){
Element bookmarkBtn = mDriver.findElement(getActivity(), "bookmark");
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
waitForText("^New Tab$");
if (mSolo.searchText("^Bookmark$")) {
// This is the Android 2.x so the button has text
mSolo.clickOnText("^Bookmark$");
} else {
Element bookmarkBtn = mDriver.findElement(getActivity(), "bookmark");
if (bookmarkBtn != null) {
// We are on Android 4.x so the button is an image button
bookmarkBtn.click();
}
else {
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
mSolo.waitForText("^New Tab$");
mSolo.clickOnText("^Bookmark$");
}
}
else {
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
mSolo.waitForText("^New Tab$");
if (!osVersion.equals("2.x")) {
Element bookmarkBtn = mDriver.findElement(getActivity(), "bookmark");
bookmarkBtn.click();
}
else {
mSolo.clickOnText("^Bookmark$");
}
}
}
}
}
}

Просмотреть файл

@ -123,4 +123,16 @@ class StringHelper {
public static final String RELOAD_LABEL = "Reload";
public static final String FORWARD_LABEL = "Forward";
public static final String BOOKMARK_LABEL = "Bookmark";
// Bookmark Toast Notification
public static final String BOOKMARK_ADDED_LABEL = "Bookmark added";
public static final String BOOKMARK_REMOVED_LABEL = "Bookmark removed";
public static final String BOOKMARK_UPDATED_LABEL = "Bookmark updated";
public static final String BOOKMARK_OPTIONS_LABEL = "Options";
// Bookmark Options Context Menu items
public static final String[] BOOKMARKS_OPTIONS_CONTEXTMENU_ITEMS = new String[] {
"Edit",
"Add to Home Screen"
};
}

Просмотреть файл

@ -1,6 +1,6 @@
[testAwesomebar]
# [testAwesomebarSwipes] # disabled on fig - bug 880060
# [testBookmark] # disabled on fig - bug 880060
[testBookmark]
# [testBookmarklets] # see bug 915350
# [testBookmarkKeyword] # see bug 915350
[testBrowserSearchVisibility]

Просмотреть файл

@ -2,21 +2,18 @@
package @ANDROID_PACKAGE_NAME@.tests;
import @ANDROID_PACKAGE_NAME@.*;
import android.database.Cursor;
import android.view.View;
import android.widget.ListView;
import java.util.Arrays;
import java.lang.reflect.Method;
import android.content.ContentResolver;
public class testBookmark extends PixelTest {
private static final String ABOUT_HOME_URL = "about:firefox";
private static String BOOKMARK_URL = "/robocop/robocop_blank_01.html";
private static String BOOKMARK_TITLE = "Browser Blank Page 01";
private ClassLoader mClassLoader;
private Method mAddBookmark;
private Method mRemoveBookmark;
private Method mIsBookmarked;
import java.util.Arrays;
import java.util.ArrayList;
public class testBookmark extends AboutHomeTest {
private static String BOOKMARK_URL;
private static int WAIT_FOR_BOOKMARKED_TIMEOUT = 10000;
Navigation nav;
@Override
protected int getTestType() {
@ -24,140 +21,62 @@ public class testBookmark extends PixelTest {
}
public void testBookmark() {
BOOKMARK_URL = getAbsoluteUrl(BOOKMARK_URL);
mClassLoader = getActivity().getApplicationContext().getClassLoader();
try {
Class browserDB = mClassLoader.loadClass("org.mozilla.gecko.db.BrowserDB");
mAddBookmark = browserDB.getMethod("addBookmark", ContentResolver.class, String.class, String.class);
mRemoveBookmark = browserDB.getMethod("removeBookmarksWithURL", ContentResolver.class, String.class);
mIsBookmarked = browserDB.getMethod("isBookmark", ContentResolver.class, String.class);
} catch (java.lang.ClassNotFoundException ex) {
mAsserter.is(true, false, "Unable to find class");
} catch (java.lang.NoSuchMethodException ex) {
mAsserter.is(true, false, "Unable to find method");
}
runAwesomeScreenTest();
BOOKMARK_URL = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL);
nav = new Navigation(mDevice);
runAboutHomeTest();
runMenuTest();
}
public void runMenuTest() {
try {
boolean isbookmark = (Boolean)mIsBookmarked.invoke(null, getActivity().getContentResolver(), BOOKMARK_URL);
mAsserter.is(isbookmark, false, "Page is not bookmarked initially");
setUpBookmark(); // loads the page, taps the star button, and waits for the "Bookmark Added" message
mAsserter.is(waitForBookmarked(true), true, "Tapping star button bookmarked page");
mAsserter.is(mDatabaseHelper.isBookmark(BOOKMARK_URL), false, "Page is not bookmarked initially");
setUpBookmark(); // loads the page, taps the star button, and waits for the "Bookmark Added" message
waitForBookmarked(true);
cleanUpBookmark(); // loads the page, taps the star button, and waits for the "Bookmark Removed" message
mAsserter.is(waitForBookmarked(false), false, "Tapping star button bookmarked page");
} catch(java.lang.IllegalAccessException ex) {
mAsserter.is(true, false, "Can not call addBookmark");
} catch(java.lang.reflect.InvocationTargetException ex) {
mAsserter.is(true, false, "Error calling addBookmark");
}
cleanUpBookmark(); // loads the page, taps the star button, and waits for the "Bookmark Removed" message
waitForBookmarked(false);
}
public void runAwesomeScreenTest() {
final long PAINT_CLEAR_DELAY = 1000; // milliseconds
public void runAboutHomeTest() {
blockForGeckoReady();
/* Removed by Bug 896576 - [fig] Remove [getBookmarksList] from BaseTest
// Open the bookmark list and check the root folder view
ListView bookmarksList = getBookmarksList(ABOUT_HOME_URL, DEFAULT_BOOKMARKS_COUNT);
mAsserter.ok(bookmarksList != null, "checking that bookmarks list exists", "bookmarks list exists and has " +
DEFAULT_BOOKMARKS_COUNT + " children (the default bookmarks)");
// No folders should be visible if no desktop bookmarks exist
int count = bookmarksList.getAdapter().getCount();
for (int i = 0; i < count; i++) {
Cursor c = (Cursor)bookmarksList.getItemAtPosition(i);
String url = c.getString(c.getColumnIndexOrThrow("url"));
mAsserter.ok(Arrays.binarySearch(DEFAULT_BOOKMARKS_URLS, url) > -1,
"Find default bookmark", "Default bookmark for " + url + " found");
for (String url:StringHelper.DEFAULT_BOOKMARKS_URLS) {
mAsserter.ok(mDatabaseHelper.isBookmark(url), "Checking that " + url + " is bookmarked by default", url + " is bookmarked");
}
insertOneBookmark();
waitForText(BOOKMARK_TITLE);
mDatabaseHelper.addOrUpdateMobileBookmark(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE, BOOKMARK_URL);
waitForBookmarked(true);
final int bookmarksCount = DEFAULT_BOOKMARKS_COUNT + 1;
mAsserter.is(bookmarksList.getAdapter().getCount(), bookmarksCount, "bookmarks list has " +
bookmarksCount + " children (the default bookmarks and the new one)");
mAsserter.ok(isBookmarkDisplayed(BOOKMARK_URL), "Checking if " + BOOKMARK_URL + " is displayed in the Bookmarks Tab", "The bookmark is displayed");
loadBookmark(BOOKMARK_URL);
waitForText(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE);
verifyPageTitle(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE);
// Click on the bookmark we created and wait for the bookmarked page to load
Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
View child = bookmarksList.getChildAt(1);
mAsserter.ok(child != null, "list item can be retrieved", child != null ? child.toString() : "null!");
mSolo.clickOnView(child);
paintExpecter.blockUntilClear(PAINT_CLEAR_DELAY);
paintExpecter.unregisterListener();
// Clean up the bookmark we created
deleteBookmark();
*/
mDatabaseHelper.deleteBookmark(BOOKMARK_URL);
waitForBookmarked(false);
}
private boolean waitForBookmarked(final boolean isBookmarked) {
waitForTest(new BooleanTest() {
private void waitForBookmarked(final boolean isBookmarked) {
boolean bookmarked = waitForTest(new BooleanTest() {
@Override
public boolean test() {
try {
return isBookmarked == (Boolean)mIsBookmarked.invoke(null, getActivity().getContentResolver(), BOOKMARK_URL);
} catch(java.lang.IllegalAccessException ex) {
mAsserter.is(true, false, "Can not call isBookmarked");
} catch(java.lang.reflect.InvocationTargetException ex) {
mAsserter.is(true, false, "Error calling isBookmarked");
}
return false;
return mDatabaseHelper.isBookmark(BOOKMARK_URL);
}
}, 10000);
try {
Boolean res = (Boolean)mIsBookmarked.invoke(null, getActivity().getContentResolver(), BOOKMARK_URL);
return res.booleanValue();
} catch(java.lang.IllegalAccessException ex) {
mAsserter.is(true, false, "Can not call isBookmarked");
} catch(java.lang.reflect.InvocationTargetException ex) {
mAsserter.is(true, false, "Error calling isBookmarked");
}
return !isBookmarked;
}
private void insertOneBookmark() {
try {
mAddBookmark.invoke(null, getActivity().getContentResolver(), BOOKMARK_TITLE, BOOKMARK_URL);
} catch(java.lang.IllegalAccessException ex) {
mAsserter.is(true, false, "Can not call addBookmark");
} catch(java.lang.reflect.InvocationTargetException ex) {
mAsserter.is(true, false, "Error calling addBookmark");
}
}
private void deleteBookmark() {
try {
mRemoveBookmark.invoke(null, getActivity().getContentResolver(), BOOKMARK_URL);
} catch(java.lang.IllegalAccessException ex) {
mAsserter.is(true, false, "Can not call removeBookmark");
} catch(java.lang.reflect.InvocationTargetException ex) {
mAsserter.is(true, false, "Error calling removeBookmark");
}
}, WAIT_FOR_BOOKMARKED_TIMEOUT);
mAsserter.is(bookmarked, isBookmarked, BOOKMARK_URL + " was " + (bookmarked ? "added as a bookmark" : "removed from bookmarks"));
}
private void setUpBookmark() {
// Bookmark a page for the test
loadAndPaint(BOOKMARK_URL);
toggleBookmark();
mAsserter.is(mSolo.waitForText("Bookmark added"), true, "bookmark added successfully");
// Navigate back to about:home for the test
loadAndPaint(ABOUT_HOME_URL);
loadUrl(BOOKMARK_URL);
waitForText(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE);
nav.bookmark();
mAsserter.is(waitForText(StringHelper.BOOKMARK_ADDED_LABEL), true, "bookmark added successfully");
}
private void cleanUpBookmark() {
// Go back to the page we bookmarked
loadAndPaint(BOOKMARK_URL);
toggleBookmark();
mAsserter.is(mSolo.waitForText("Bookmark removed"), true, "bookmark removed successfully");
loadUrl(BOOKMARK_URL);
waitForText(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE);
nav.bookmark();
mAsserter.is(waitForText(StringHelper.BOOKMARK_REMOVED_LABEL), true, "bookmark removed successfully");
}
}