gecko/mobile/android/base/tests/testBookmark.java.in

95 lines
3.4 KiB
Java
Raw Normal View History

#filter substitution
package @ANDROID_PACKAGE_NAME@.tests;
import @ANDROID_PACKAGE_NAME@.*;
import android.app.Activity;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
public class testBookmark extends BaseTest {
private static final int MAX_WAIT_MS = 3000;
private static final String ABOUT_HOME_URL = "about:home";
private static final String BOOKMARK_URL = "/robocop/robocop_blank_01.html";
public void testBookmark() {
setTestType("mochitest");
mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();
setUpBookmark();
// Open the bookmark list and check the root folder view
ListView bookmarksList = openBookmarksList();
mAsserter.ok(bookmarksList != null, "checking that bookmarks list exists", "bookmarks list exists");
// No folders should be visible if no desktop bookmarks exist
mAsserter.is(bookmarksList.getChildCount(), 2,
"bookmarks list has 2 children (the bookmark we added and the hidden header)");
// Click on the bookmark we created (the first item is the header view)
mSolo.clickInList(2);
// Wait for the bookmarked page to load
mActions.expectGeckoEvent("DOMContentLoaded").blockForEvent();
// Clean up the bookmark we created
cleanUpBookmark();
}
private ListView openBookmarksList() {
Activity awesomeBarActivity = clickOnAwesomeBar();
// Click the "Bookmarks" tab to switch to bookmarks list
mSolo.clickOnText("Bookmarks");
Element bookmarkList = mDriver.findElement(awesomeBarActivity, "bookmarks_list");
ArrayList<ListView> lists = mSolo.getCurrentListViews();
for (ListView list : lists) {
if (list.getId() == bookmarkList.getId())
return list;
}
// Just return null if we can't find the bookmarks list view
return null;
}
// This method opens the menu and selects the "Bookmark" menu item
private void toggleBookmark() {
getInstrumentation().waitForIdleSync();
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
mSolo.waitForText("Bookmark");
mSolo.clickOnText("Bookmark");
}
private void setUpBookmark() {
// Bookmark a page for the test
loadUrl(getAbsoluteUrl(BOOKMARK_URL));
toggleBookmark();
mAsserter.is(mSolo.waitForText("Bookmark added"), true, "bookmark added sucessfully");
// Navigate back to about:home for the test
loadUrl(ABOUT_HOME_URL);
}
private void cleanUpBookmark() {
// Go back to the page we bookmarked
loadUrl(getAbsoluteUrl(BOOKMARK_URL));
toggleBookmark();
mAsserter.is(mSolo.waitForText("Bookmark removed"), true, "bookmark removed successfully");
//If the test ends too quickly, the bookmark database may not be updated correctly
//before the Fennec process is killed, and the item will not be removed. To
//guard against this, navigate back to the bookmarks list and wait until
//it is empty.
ListView bookmarkList = openBookmarksList();
final ListAdapter adapter = bookmarkList.getAdapter();
waitForTest(new BooleanTest() {
public boolean test() {
return adapter != null && adapter.isEmpty();
}
}, MAX_WAIT_MS);
}
}