Bug 729463 - Fix tests for switch to tab. r=gbrown

This commit is contained in:
Wes Johnston 2013-05-09 17:42:14 -07:00
Родитель 41a6f05b5a
Коммит eecfe73ec8
5 изменённых файлов: 78 добавлений и 59 удалений

Просмотреть файл

@ -190,16 +190,27 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
* Click on the awesome bar element and return the resulting activity.
* @return The created activity, or null if the awesome bar cannot be clicked.
*/
private Activity mAwesomeActivity;
protected final Activity clickOnAwesomeBar() {
Activity activity = null;
Element awesomebar = mDriver.findElement(mActivity, "browser_toolbar");
if (awesomebar != null) {
activity = getActivityFromClick(awesomebar);
if (activity == null) {
mAsserter.dumpLog("failed to click on awesome bar!");
mAwesomeActivity = null;
boolean success = waitForTest(new BooleanTest() {
@Override
public boolean test() {
Element awesomebar = mDriver.findElement(mActivity, "browser_toolbar");
if (awesomebar != null) {
mAwesomeActivity = getActivityFromClick(awesomebar);
if (mAwesomeActivity == null) {
mAsserter.dumpLog("failed to click on awesome bar!");
}
return mSolo.waitForText("History", 1, MAX_WAIT_MS);
}
return false;
}
}
return activity;
}, MAX_WAIT_MS*5);
if (!success)
mAsserter.dumpLog("failed to find History");
return mAwesomeActivity;
}
protected final void enterUrl(String url) {
@ -434,6 +445,14 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
mAsserter.is(tabCountInt, expectedTabCount, "The correct number of tabs are opened");
}
protected boolean isBookmark(String[] bookmarks, String aValue) {
for (int i = 0; i < bookmarks.length; i++) {
if (bookmarks[i].equals(aValue))
return true;
}
return false;
}
private ListView getAwesomeList(String waitText, int expectedChildCount,
String clickText, String tagName, String callerName) {
ArrayList<ListView> views;
@ -613,7 +632,7 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
mSolo.clickOnText("Bookmarks");
child = list.getChildAt(bookmarkIndex);
mAsserter.ok(child != null, "edit item can be retrieved", child != null ? child.toString() : "null!");
waitForText("about:home|Firefox");
waitForText("Switch to tab");
mSolo.clickLongOnView(child);
waitForText("Share");
mSolo.clickOnText("Edit");
@ -637,13 +656,14 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
mSolo.clickOnText("Bookmarks");
child = list.getChildAt(bookmarkIndex);
mAsserter.ok(child != null, "check item can be retrieved", child != null ? child.toString() : "null!");
waitForText("about:home|Firefox");
waitForText("Switch to tab");
mSolo.clickLongOnView(child);
waitForText("Share");
mSolo.clickOnText("Edit");
waitForText("Edit Bookmark");
// If the OS is not Gingerbread the vkb will be opened so we need to close it in order to press the "Cancel" button
// XXX: This is not true on all devices, but is true on our current automation test machines...
if (!(mDevice.version.equals("2.x"))) {
mActions.sendSpecialKey(Actions.SpecialKey.BACK); // close the VKB
}

Просмотреть файл

@ -24,11 +24,11 @@ public class testAllPagesTab extends BaseTest {
private static final String ABOUT_HOME_URL = "about:home";
private static ListView listview = null;
private String[] bookmarks = new String[] {
"about:firefox",
"about:home",
"http://support.mozilla.org/en-US/products/mobile",
"https://addons.mozilla.org/en-US/android/"
private String[] mBookmarks = new String[] {
"Firefox: About your browser",
"Firefox Start",
"Firefox: Support",
"Firefox: Customize with add-ons"
};
@Override
@ -44,12 +44,12 @@ public class testAllPagesTab extends BaseTest {
loadUrl(url);
testList(url);
testClick(url);
testClick("about:firefox");
testContextMenu(url);
}
private void testList(String url) {
final ListView list = getAllPagesList(bookmarks[0], 5);
final ListView list = getAllPagesList(mBookmarks[0], 5);
// some basic checks for the tab strip
TabWidget tabwidget = (TabWidget)mSolo.getView(TabWidget.class, 0);
@ -87,8 +87,7 @@ public class testAllPagesTab extends BaseTest {
loadUrl = string;
}
int index = Arrays.binarySearch(bookmarks, string);
if (index > -1) {
if (isBookmark(mBookmarks, string)) {
expectedImages = 2;
}
} else if (v instanceof ImageView) {
@ -109,13 +108,14 @@ public class testAllPagesTab extends BaseTest {
}
private void testContextMenu(String url) {
ListView list = getAllPagesList(bookmarks[0], 5);
ListView list = getAllPagesList(mBookmarks[0], 5);
View child = list.getChildAt(0);
mAsserter.ok(child != null, "first list item can be retrieved", child != null ? child.toString() : "null!");
mSolo.clickLongOnView(child);
// TODO: Test clicking these does the right thing
mAsserter.ok(mSolo.waitForText("Open in New Tab"), "Context menu has Open in New Tab option", "Open in New Tab");
mAsserter.ok(mSolo.waitForText("Share"), "Context menu has Share option", "Share");
mAsserter.ok(mSolo.searchText("Remove", true), "Context menu has Remove option", "Remove");
mAsserter.ok(mSolo.searchText("Add to Home Screen", true), "Context menu has Add to Home Screen option", "Add to Home Screen");
@ -125,10 +125,12 @@ public class testAllPagesTab extends BaseTest {
}
private void testClick(String url) {
ListView list = getAllPagesList(bookmarks[0], 5);
ListView list = getAllPagesList(mBookmarks[0], 5);
Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
View child = list.getChildAt(0);
// Avoid clicking the first item. Its the first item because its in an open tab, and will just switch to it
View child = list.getChildAt(1);
mAsserter.ok(child != null, "first list item can be retrieved", child != null ? child.toString() : "null!");
// dump text for this child, to be sure of which list item is clicked
ArrayList<View> views = mSolo.getViews(child);
@ -143,6 +145,7 @@ public class testAllPagesTab extends BaseTest {
mSolo.clickOnView(child);
contentEventExpecter.blockForEvent();
contentEventExpecter.unregisterListener();
mSolo.sleep(500);
verifyUrl(url);
}

Просмотреть файл

@ -122,6 +122,7 @@ public class testBookmarksTab extends BaseTest {
mSolo.clickLongOnView(mFirstChild);
// TODO: Test clicking these does the right thing
mAsserter.ok(mSolo.waitForText("Open in New Tab"), "Context menu has Open in New Tab option", "Open in New Tab");
mAsserter.ok(mSolo.waitForText("Share"), "Context menu has Share option", "Share");
mAsserter.ok(mSolo.searchText("Edit", true), "Context menu has Edit option", "Edit");
mAsserter.ok(mSolo.searchText("Remove", true), "Context menu has Remove option", "Remove");
@ -158,7 +159,7 @@ public class testBookmarksTab extends BaseTest {
child = list.getChildAt(1);
mAsserter.ok(child != null, "second list item can be retrieved", child != null ? child.toString() : "null!");
mSolo.clickLongOnView(child);
waitForText("Share");
waitForText("Remove");
mSolo.clickOnText("Remove");
// Wait for the toaster notification

Просмотреть файл

@ -30,7 +30,7 @@ public class testHistory extends PixelTest {
loadAndPaint(url3);
verifyPageTitle("Browser Blank Page 03");
final ListView hList = openHistoryList();
final ListView hList = getHistoryList("Today|Yesterday");
mAsserter.ok(hList != null, "checking history exists", "history exists");
// Click on the history item and wait for the page to load
@ -62,23 +62,11 @@ public class testHistory extends PixelTest {
}
}, MAX_WAIT_MS);
Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
mAsserter.isnot(mFirstChild, null, "Got history item");
mSolo.clickOnView(mFirstChild);
contentEventExpecter.blockForEvent();
contentEventExpecter.unregisterListener();
// The first item here (since it was just visited) should be a "Switch to tab" item
// i.e. don't expect a DOMCOntentLoaded event
verifyPageTitle("Browser Blank Page 03");
verifyUrl(url3);
}
protected ListView openHistoryList() {
Activity awesomeBarActivity = clickOnAwesomeBar();
mSolo.clickOnText("History");
ArrayList<ListView> views = mSolo.getCurrentListViews();
for (ListView view : views) {
if (view.getTag() == "history")
return view;
}
return null;
}
}

Просмотреть файл

@ -25,10 +25,11 @@ import java.util.GregorianCalendar;
public class testHistoryTab extends PixelTest {
private static final String ABOUT_HOME_URL = "about:home";
private static ListView listview = null;
private String[] bookmarks = new String[] {
"http://mochi.test:8888/tests/robocop/robocop_blank_01.html"
private String[] mBookmarks = new String[] {
"Browser Blank Page 01",
"Firefox: Customize with add-ons"
};
private View mFirstChild;
private View mChild;
private boolean mNearMidnight;
@Override
@ -86,7 +87,7 @@ public class testHistoryTab extends PixelTest {
testList(url);
testContextMenu(url);
testClick(url);
testClick(getAbsoluteUrl("/robocop/robocop_big_link.html"));
}
private void testList(String url) {
@ -107,6 +108,8 @@ public class testHistoryTab extends PixelTest {
int expectedImages = 1;
for (int j = 0; j < views.size(); j++) {
View v = views.get(j);
// First row is going to be a header row
if (i == 0) {
ArrayList<TextView> views2 = mSolo.getCurrentTextViews(v);
TextView t = views2.get(0);
@ -118,6 +121,7 @@ public class testHistoryTab extends PixelTest {
mAsserter.ok(headerTextOK, "First row has Today header", string);
expectedImages = 0;
} else if (v instanceof TextView) {
// if this is a textview, its either the title or the url. In either case, both should be filled in
TextView t = (TextView)v;
String string = t.getText().toString();
mAsserter.ok(!TextUtils.isEmpty(string), "TextView is filled in", string);
@ -125,8 +129,8 @@ public class testHistoryTab extends PixelTest {
loadUrl = string;
}
int index = Arrays.binarySearch(bookmarks, string);
if (index > -1) {
// if this was a url, check if its a bookmark and should have more than one image view present
if (isBookmark(mBookmarks, string)) {
expectedImages = 2;
}
} else if (v instanceof ImageView) {
@ -151,16 +155,16 @@ public class testHistoryTab extends PixelTest {
waitForText(url);
// wait for the history list to be populated
mFirstChild = null;
mChild = null;
boolean success = waitForTest(new BooleanTest() {
@Override
public boolean test() {
mFirstChild = listview.getChildAt(1);
if (mFirstChild == null) {
mChild = listview.getChildAt(1);
if (mChild == null) {
return false;
}
if (mFirstChild instanceof android.view.ViewGroup) {
ViewGroup group = (ViewGroup)mFirstChild;
if (mChild instanceof android.view.ViewGroup) {
ViewGroup group = (ViewGroup)mChild;
if (group.getChildCount() < 1) {
return false;
}
@ -171,17 +175,18 @@ public class testHistoryTab extends PixelTest {
}
}
} else {
mAsserter.dumpLog("first child not a ViewGroup: "+mFirstChild);
mAsserter.dumpLog("first child not a ViewGroup: "+mChild);
return false;
}
return true;
}
}, MAX_WAIT_MS);
if (success == true && mFirstChild != null) {
mAsserter.dumpLog("clickLongOnView: "+mFirstChild);
mSolo.clickLongOnView(mFirstChild);
if (success == true && mChild != null) {
mAsserter.dumpLog("clickLongOnView: "+mChild);
mSolo.clickLongOnView(mChild);
// TODO: Test clicking these does the right thing
mAsserter.ok(mSolo.waitForText("Open in New Tab"), "Context menu has Open in New Tab option", "Open in New Tab");
mAsserter.ok(mSolo.waitForText("Share"), "Context menu has Share option", "Share");
mAsserter.ok(mSolo.searchText("Remove", true), "Context menu has Remove option", "Remove");
mAsserter.ok(mSolo.searchText("Add to Home Screen", true), "Context menu has Add to Home Screen option", "Add to Home Screen");
@ -209,20 +214,22 @@ public class testHistoryTab extends PixelTest {
// nothing should happen
Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
mFirstChild = null;
mChild = null;
boolean success = waitForTest(new BooleanTest() {
@Override
public boolean test() {
mFirstChild = listview.getChildAt(1);
if (mFirstChild == null) {
// Avoid clicking on the first entry, which is already open and will just switch to the tab
mChild = listview.getChildAt(2);
if (mChild == null) {
return false;
}
return true;
}
}, MAX_WAIT_MS);
if (success == true && mFirstChild != null) {
mSolo.clickOnView(mFirstChild);
if (success == true && mChild != null) {
mSolo.clickOnView(mChild);
contentEventExpecter.blockForEvent();
mSolo.sleep(500);
verifyUrl(url);
} else {
mAsserter.ok(false, "waiting for history item", "history item available");