2011-12-16 11:27:52 -08:00
|
|
|
#filter substitution
|
|
|
|
package @ANDROID_PACKAGE_NAME@.tests;
|
|
|
|
|
|
|
|
import @ANDROID_PACKAGE_NAME@.*;
|
2012-02-07 11:12:23 -08:00
|
|
|
import android.app.Activity;
|
2012-02-23 10:48:48 -08:00
|
|
|
import android.widget.ListAdapter;
|
|
|
|
import android.widget.ListView;
|
2012-01-18 10:44:47 -08:00
|
|
|
import android.widget.TextView;
|
|
|
|
import java.util.ArrayList;
|
2011-12-16 11:27:52 -08:00
|
|
|
|
2012-01-05 07:20:22 -08:00
|
|
|
public class testBookmark extends BaseTest {
|
2012-02-23 10:48:48 -08:00
|
|
|
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";
|
2012-01-05 07:20:22 -08:00
|
|
|
|
2012-01-05 07:20:22 -08:00
|
|
|
public void testBookmark() {
|
2012-02-02 07:09:26 -08:00
|
|
|
setTestType("mochitest");
|
2012-02-10 06:44:06 -08:00
|
|
|
mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();
|
|
|
|
|
2012-02-23 10:48:48 -08:00
|
|
|
setUpBookmark();
|
|
|
|
|
|
|
|
// Open the bookmark list and check the root folder view
|
|
|
|
ListView bookmarksList = openBookmarksList();
|
2012-03-19 11:22:36 -07:00
|
|
|
mAsserter.ok(bookmarksList != null, "checking that bookmarks list exists", "bookmarks list exists");
|
2012-02-23 10:48:48 -08:00
|
|
|
|
2012-03-19 11:22:36 -07:00
|
|
|
// 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)");
|
2012-02-23 10:48:48 -08:00
|
|
|
|
|
|
|
// 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;
|
2012-02-07 11:12:23 -08:00
|
|
|
}
|
2012-02-23 10:48:48 -08:00
|
|
|
|
|
|
|
// 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();
|
2012-02-02 07:09:24 -08:00
|
|
|
}
|
2012-02-23 10:48:48 -08:00
|
|
|
}, MAX_WAIT_MS);
|
2012-01-05 07:20:22 -08:00
|
|
|
}
|
2011-12-16 11:27:52 -08:00
|
|
|
}
|