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

117 lines
4.2 KiB
Java

#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();
checkRootFolderView(bookmarksList);
// Move to the "Mobile Bookmarks" folder (the first item is the header view)
mSolo.clickInList(2);
// Check that header view says "Mobile Bookmarks"
mAsserter.ok(mSolo.getText("Mobile Bookmarks") != null, "checking that header is correct", "bookmarks folder header is correct");
// Check that pressing the back buton goes up a folder level
mSolo.goBack();
checkRootFolderView(bookmarksList);
// Move back to the "Mobile Bookmarks" folder
mSolo.clickInList(2);
// 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;
}
private void checkRootFolderView(ListView bookmarksList) {
// Wait for the folders to be displayed
mSolo.waitForText("Mobile Bookmarks");
mAsserter.ok(bookmarksList != null, "checking that bookmarks list exists", "bookmarks list exists");
// The root view should have 5 children
mAsserter.is(bookmarksList.getChildCount(), 5, "bookmarks list has 5 children (a header and 4 folders)");
}
// 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();
// Move to the "Mobile Bookmarks" folder (the first item is the header view)
mSolo.clickInList(2);
final ListAdapter adapter = bookmarkList.getAdapter();
waitForTest(new BooleanTest() {
public boolean test() {
return adapter != null && adapter.isEmpty();
}
}, MAX_WAIT_MS);
}
}