mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
96 lines
3.9 KiB
Java
96 lines
3.9 KiB
Java
#filter substitution
|
|
package @ANDROID_PACKAGE_NAME@.tests;
|
|
|
|
import @ANDROID_PACKAGE_NAME@.*;
|
|
import android.app.Activity;
|
|
import android.widget.TextView;
|
|
import android.os.SystemClock;
|
|
import java.util.ArrayList;
|
|
|
|
public class testBookmark extends BaseTest {
|
|
private static final long MAX_WAIT_MS = 10 * 1000;
|
|
|
|
public void testBookmark() {
|
|
setTestType("mochitest");
|
|
String url = getAbsoluteUrl("/robocop/robocop_blank_02.html");
|
|
enterUrl(url);
|
|
|
|
//Click the top item in the awesome list.
|
|
mActions.sendSpecialKey(Actions.SpecialKey.DOWN);
|
|
hitEnterAndWait();
|
|
|
|
//Click the top item in the bookmark list.
|
|
clickOnAwesomeBar();
|
|
mActions.sendSpecialKey(Actions.SpecialKey.RIGHT);
|
|
|
|
Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
|
|
|
|
boolean selected = selectFirstItemInList();
|
|
boolean created = false;
|
|
if (!selected) {
|
|
//Bookmark selection will fail if there are no bookmarks defined;
|
|
//create a bookmark and then try selecting again.
|
|
mActions.sendSpecialKey(Actions.SpecialKey.BACK);
|
|
getInstrumentation().waitForIdleSync();
|
|
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
|
|
mSolo.waitForText("Bookmark");
|
|
mSolo.clickOnText("Bookmark");
|
|
created = true;
|
|
clickOnAwesomeBar();
|
|
mActions.sendSpecialKey(Actions.SpecialKey.RIGHT);
|
|
contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
|
|
selected = selectFirstItemInList();
|
|
}
|
|
mAsserter.is(selected, true, "Bookmark was selected");
|
|
|
|
contentEventExpecter.blockForEvent();
|
|
|
|
//Items in bookmarks aren't constant so URL can't be tested.
|
|
|
|
//If a bookmark was created by this test, remove it now.
|
|
if (created) {
|
|
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
|
|
mSolo.waitForText("Bookmark");
|
|
mSolo.clickOnText("Bookmark");
|
|
mAsserter.is(mSolo.waitForText("Bookmark removed"), true, "Bookmark removal verified");
|
|
//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.
|
|
Activity awesomeBarActivity = clickOnAwesomeBar();
|
|
mActions.sendSpecialKey(Actions.SpecialKey.RIGHT);
|
|
boolean listIsEmpty = false;
|
|
Element bookmarkList = mDriver.findElement(awesomeBarActivity, "bookmarks_list");
|
|
while (listIsEmpty == false) {
|
|
if (bookmarkList != null) {
|
|
ArrayList<android.widget.ListView> views = mSolo.getCurrentListViews();
|
|
for (android.widget.ListView v : views) {
|
|
if (v.getId() == bookmarkList.getId()) {
|
|
android.widget.ListAdapter adapter = v.getAdapter();
|
|
if (adapter != null && adapter.isEmpty()) {
|
|
listIsEmpty = true;
|
|
} else {
|
|
// wait a little while before trying again
|
|
try { Thread.sleep(100); } catch(Exception e) {}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private boolean selectFirstItemInList() {
|
|
long waitStart = SystemClock.uptimeMillis();
|
|
ArrayList<TextView> l = null;
|
|
while (l == null || l.size() < 1) {
|
|
if (SystemClock.uptimeMillis() - waitStart > MAX_WAIT_MS) {
|
|
mAsserter.dumpLog("testBookmark: timed out waiting for list -- no bookmarks defined?");
|
|
return false;
|
|
}
|
|
l = mSolo.clickInList(1);
|
|
}
|
|
return true;
|
|
}
|
|
}
|