mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 720930 - Robocop: create bookmark in testBookmark if none exists; r=jmaher
This commit is contained in:
parent
4d13691e3a
commit
03bb4b41ae
@ -42,7 +42,7 @@ import java.util.List;
|
||||
|
||||
public interface Actions {
|
||||
public enum SpecialKey {
|
||||
DOWN, UP, LEFT, RIGHT, ENTER
|
||||
DOWN, UP, LEFT, RIGHT, ENTER, MENU, BACK
|
||||
}
|
||||
|
||||
public interface EventExpecter {
|
||||
|
@ -46,4 +46,6 @@ public interface Element {
|
||||
boolean isDisplayed();
|
||||
//Returns the text currently displayed on the element.
|
||||
String getText();
|
||||
//Returns view ID.
|
||||
Integer getId();
|
||||
}
|
||||
|
@ -338,6 +338,12 @@ public class FennecNativeActions implements Actions {
|
||||
case ENTER:
|
||||
instr.sendCharacterSync(KeyEvent.KEYCODE_ENTER);
|
||||
break;
|
||||
case MENU:
|
||||
instr.sendCharacterSync(KeyEvent.KEYCODE_MENU);
|
||||
break;
|
||||
case BACK:
|
||||
instr.sendCharacterSync(KeyEvent.KEYCODE_BACK);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
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;
|
||||
@ -24,18 +25,71 @@ public class testBookmark extends BaseTest {
|
||||
|
||||
Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
|
||||
|
||||
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 bookmark list -- no bookmarks defined?");
|
||||
return;
|
||||
}
|
||||
l = mSolo.clickInList(1);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user