From 4af4f096f475ed1197dbee7965cce1de448cc605 Mon Sep 17 00:00:00 2001 From: Geoff Brown Date: Fri, 1 Mar 2013 17:02:52 -0700 Subject: [PATCH] Bug 769919: Allow retry when getting awesomebar ListView in robocop tests; r=jmaher --- mobile/android/base/tests/BaseTest.java.in | 86 ++++++++++++------- mobile/android/base/tests/robocop.ini | 2 +- .../base/tests/testAllPagesTab.java.in | 5 +- .../android/base/tests/testBookmark.java.in | 10 +-- .../base/tests/testBookmarklets.java.in | 6 +- .../base/tests/testBookmarksTab.java.in | 25 ++---- .../base/tests/testClearPrivateData.java.in | 8 +- .../android/base/tests/testHistoryTab.java.in | 20 +---- .../android/base/tests/testShareLink.java.in | 6 +- 9 files changed, 79 insertions(+), 89 deletions(-) diff --git a/mobile/android/base/tests/BaseTest.java.in b/mobile/android/base/tests/BaseTest.java.in index 71829f65bb4f..172fcd66ea97 100755 --- a/mobile/android/base/tests/BaseTest.java.in +++ b/mobile/android/base/tests/BaseTest.java.in @@ -37,6 +37,7 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2 { private static final String TARGET_PACKAGE_ID = "org.mozilla.gecko"; private static final String LAUNCH_ACTIVITY_FULL_CLASSNAME="@ANDROID_PACKAGE_NAME@.App"; private static final int VERIFY_URL_TIMEOUT = 2000; + private static final int MAX_LIST_ATTEMPTS = 3; public static final int MAX_WAIT_MS = 3000; private static Class mLauncherActivityClass; @@ -406,55 +407,74 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2 { mAsserter.is(tabCountInt, expectedTabCount, "The correct number of tabs are opened"); } - /** - * Click on the awesome bar, and return the ListView for the - * All Pages ("Top Sites") tab. - */ - protected ListView getAllPagesList(String waitText) { - Activity awesomeBarActivity = clickOnAwesomeBar(); - waitForText(waitText); - - ArrayList views = mSolo.getCurrentListViews(); - for (ListView view : views) { - if (view.getTag() == "allPages") { - return view; + private ListView getAwesomeList(String waitText, int expectedChildCount, + String clickText, String tagName, String callerName) { + ArrayList views; + ListView tabView = null; + int childCount = 0; + for (int i = 0; i < MAX_LIST_ATTEMPTS; i++) { + tabView = null; + childCount = 0; + Activity awesomeBarActivity = clickOnAwesomeBar(); + mSolo.clickOnText(clickText); + if (waitForText(waitText)) { + views = mSolo.getCurrentListViews(); + for (ListView view : views) { + if (view.getTag().equals(tagName)) { + tabView = view; + childCount = view.getAdapter().getCount(); + if (expectedChildCount < 0 || expectedChildCount == childCount) { + return view; + } + } + } } } + if (tabView == null) { + mAsserter.dumpLog(callerName+" did not find ListView"); + } else if (expectedChildCount >= 0) { + mAsserter.dumpLog(callerName+" found ListView with "+childCount+" children"); + } return null; } + /** + * Click on the awesome bar, click on the Top Sites tab, and return + * the ListView for the All Pages ("Top Sites") tab. + */ + protected ListView getAllPagesList(String waitText, int expectedChildCount) { + return getAwesomeList(waitText, expectedChildCount, + "Top Sites", "allPages", "getAllPagesList"); + } + + protected ListView getAllPagesList(String waitText) { + return getAllPagesList(waitText, -1); + } + /** * Click on the awesome bar, click on the Bookmarks tab, and return * the ListView for the Bookmarks tab. */ - protected ListView getBookmarksList() { - Activity awesomeBarActivity = clickOnAwesomeBar(); - mSolo.clickOnText("Bookmarks"); + protected ListView getBookmarksList(String waitText, int expectedChildCount) { + return getAwesomeList(waitText, expectedChildCount, + "Bookmarks", "bookmarks", "getBookmarksList"); + } - ArrayList views = mSolo.getCurrentListViews(); - for (ListView view : views) { - if (view.getTag().equals("bookmarks")) { - return view; - } - } - return null; + protected ListView getBookmarksList(String waitText) { + return getBookmarksList(waitText, -1); } /** * Click on the awesome bar, click on the History tab, and return * the ListView for the History tab. */ - protected ListView getHistoryList() { - Activity awesomeBarActivity = clickOnAwesomeBar(); - mSolo.clickOnText("History"); - waitForText("Today|Yesterday"); - ArrayList views = mSolo.getCurrentListViews(); - for (ListView view : views) { - if (view.getTag().equals("history")) { - return view; - } - } - return null; + protected ListView getHistoryList(String waitText, int expectedChildCount) { + return getAwesomeList(waitText, expectedChildCount, + "History", "history", "getHistoryList"); + } + + protected ListView getHistoryList(String waitText) { + return getHistoryList(waitText, -1); } public long addOrUpdateBookmark(String title, String url, boolean bookmarklet) { diff --git a/mobile/android/base/tests/robocop.ini b/mobile/android/base/tests/robocop.ini index a9492e063227..79bac88a4181 100644 --- a/mobile/android/base/tests/robocop.ini +++ b/mobile/android/base/tests/robocop.ini @@ -1,4 +1,4 @@ -# [testAllPagesTab] # see bug 825152 +[testAllPagesTab] [testHistoryTab] [testBookmarksTab] [testAwesomebar] diff --git a/mobile/android/base/tests/testAllPagesTab.java.in b/mobile/android/base/tests/testAllPagesTab.java.in index 226d8b5e6d5c..b3a29aca5154 100644 --- a/mobile/android/base/tests/testAllPagesTab.java.in +++ b/mobile/android/base/tests/testAllPagesTab.java.in @@ -56,7 +56,7 @@ public class testAllPagesTab extends BaseTest { } private void testList(String url) { - final ListView list = getAllPagesList(bookmarks[0]); + final ListView list = getAllPagesList(bookmarks[0], 5); // some basic checks for the tab strip TabWidget tabwidget = (TabWidget)mSolo.getView(TabWidget.class, 0); @@ -68,9 +68,8 @@ public class testAllPagesTab extends BaseTest { // This test fails, only when we're running tests // mAsserter.is(host.getCurrentTab(), 0, "All pages tab is selected in tab strip"); - mAsserter.isnot(list, null, "checking that all pages list exists"); + mAsserter.isnot(list, null, "checking that all pages list exists and has 5 children (the default bookmarks)"); final int count = list.getAdapter().getCount(); - mAsserter.is(count, 5, "all pages list has 5 children (the default bookmarks)"); String loadUrl = ""; for (int i = count - 1; i >= 0; i--) { diff --git a/mobile/android/base/tests/testBookmark.java.in b/mobile/android/base/tests/testBookmark.java.in index 7995647d064c..0063abda6b68 100644 --- a/mobile/android/base/tests/testBookmark.java.in +++ b/mobile/android/base/tests/testBookmark.java.in @@ -76,18 +76,12 @@ public class testBookmark extends PixelTest { blockForGeckoReady(); // Open the bookmark list and check the root folder view - ListView bookmarksList = getBookmarksList(); + ListView bookmarksList = getBookmarksList(ABOUT_HOME_URL, 4); - // Wait for bookmark to appear in list - waitForText(ABOUT_HOME_URL); - - mAsserter.ok(bookmarksList != null, "checking that bookmarks list exists", "bookmarks list exists"); + mAsserter.ok(bookmarksList != null, "checking that bookmarks list exists", "bookmarks list exists and has 4 children (the default bookmarks)"); // No folders should be visible if no desktop bookmarks exist int count = bookmarksList.getAdapter().getCount(); - mAsserter.is(count, 4, - "bookmarks list has 4 children (the default bookmarks)"); - for (int i = 0; i < count; i++) { Cursor c = (Cursor)bookmarksList.getItemAtPosition(i); String url = c.getString(c.getColumnIndexOrThrow("url")); diff --git a/mobile/android/base/tests/testBookmarklets.java.in b/mobile/android/base/tests/testBookmarklets.java.in index fdbbb80d31f9..6a336514f280 100644 --- a/mobile/android/base/tests/testBookmarklets.java.in +++ b/mobile/android/base/tests/testBookmarklets.java.in @@ -43,12 +43,12 @@ public class testBookmarklets extends PixelTest { addOrUpdateBookmark(title, js, true); // verify that bookmarklets clicked in awesomescreen work - ListView bookmarks = getBookmarksList(); + ListView bookmarks = getBookmarksList(title); Boolean found = false; if (bookmarks == null) { mAsserter.is(true, true, "Did not find the bookmarks section in the awesomebar"); - } else if (mSolo.waitForText(title)) { + } else { for (int i = 0; i < bookmarks.getAdapter().getCount(); i++) { Cursor c = (Cursor)bookmarks.getItemAtPosition(i); String turl = c.getString(c.getColumnIndexOrThrow("url")); @@ -58,8 +58,6 @@ public class testBookmarklets extends PixelTest { mSolo.clickOnView(bookmarks.getChildAt(i)); } } - } else { - mAsserter.is(true, true, "Did not find the title '" + title + "' of the bookmark in the list"); } if (!found) { mAsserter.is(found, true, "Found the bookmark: " + js + " and clicked on it"); diff --git a/mobile/android/base/tests/testBookmarksTab.java.in b/mobile/android/base/tests/testBookmarksTab.java.in index bbe616a29d9e..bf725dd9153c 100644 --- a/mobile/android/base/tests/testBookmarksTab.java.in +++ b/mobile/android/base/tests/testBookmarksTab.java.in @@ -18,7 +18,7 @@ import java.util.ArrayList; import java.io.File; /** - * Tests the Bookamrks Tab + * Tests the Bookmarks Tab * - opening the bookmarks tab * - items look correct * - clicking on an item @@ -26,7 +26,6 @@ import java.io.File; * - editing the name, url and keyword of a bookmark from the context menu * - removing a bookmark */ - public class testBookmarksTab extends BaseTest { private View mFirstChild; private ListView list; @@ -49,14 +48,10 @@ public class testBookmarksTab extends BaseTest { private void testList(String url) { View child; - ListView list = getBookmarksList(); - - waitForText("Desktop Bookmarks"); - mAsserter.isnot(list, null, "checking that bookmarks list exists"); + ListView list = getBookmarksList("about:firefox", 5); + mAsserter.isnot(list, null, "checking that bookmarks list exists and has 5 children (defaults + a folder)"); int count = list.getAdapter().getCount(); - mAsserter.is(count, 5, "bookmarks list has 5 children (defaults + a folder)"); - for (int i = count - 1; i >= 0; i--) { child = list.getChildAt(i); compareRow(child, i == 0 ? 1 : 2, 1); @@ -95,9 +90,7 @@ public class testBookmarksTab extends BaseTest { } private void testContextMenu(String url) { - list = getBookmarksList(); - waitForText(url); - + list = getBookmarksList(url); // wait for the bookmarks list to be populated View child; mFirstChild = null; @@ -150,7 +143,7 @@ public class testBookmarksTab extends BaseTest { mAsserter.ok(false, "waiting for bookmark item", "bookmark item available"); } - list = getBookmarksList(); + list = getBookmarksList(url); // Test edit bookmark name editBookmark(1,0," Bookmark Name "); @@ -191,7 +184,7 @@ public class testBookmarksTab extends BaseTest { View child; mSolo.clickOnText("Bookmarks"); child = list.getChildAt(bookmarkIndex); - waitForText("Desktop Bookmarks"); + waitForText("about:firefox"); mSolo.clickLongOnView(child); waitForText("Open in New Tab"); mSolo.clickOnText("Edit"); @@ -214,7 +207,7 @@ public class testBookmarksTab extends BaseTest { View child; mSolo.clickOnText("Bookmarks"); child = list.getChildAt(bookmarkIndex); - waitForText("Desktop Bookmarks"); + waitForText("about:firefox"); mSolo.clickLongOnView(child); waitForText("Open in New Tab"); mSolo.clickOnText("Edit"); @@ -228,12 +221,12 @@ public class testBookmarksTab extends BaseTest { // Check if the new text was added if (mSolo.searchText(addedText)) { mSolo.clickOnText("Cancel"); - waitForText("Desktop Bookmarks"); + waitForText("about:firefox"); mActions.sendSpecialKey(Actions.SpecialKey.BACK); // close the VKB return true; } else { mSolo.clickOnText("Cancel"); - waitForText("Desktop Bookmarks"); + waitForText("about:firefox"); mActions.sendSpecialKey(Actions.SpecialKey.BACK); // close the VKB return false; } diff --git a/mobile/android/base/tests/testClearPrivateData.java.in b/mobile/android/base/tests/testClearPrivateData.java.in index 1d2fc6d37727..01cc1bb87904 100644 --- a/mobile/android/base/tests/testClearPrivateData.java.in +++ b/mobile/android/base/tests/testClearPrivateData.java.in @@ -28,8 +28,8 @@ public class testClearPrivateData extends PixelTest { String url = getAbsoluteUrl("/robocop/robocop_blank_01.html"); loadAndPaint(url); - // Checking that the history list in not empty - ListView hList = getHistoryList(); + // Checking that the history list is not empty + ListView hList = getHistoryList("Today|Yesterday"); mAsserter.ok(hList.getAdapter().getCount() > 0,"checking history exists","history exists"); // Quit the awesomescreen @@ -46,7 +46,7 @@ public class testClearPrivateData extends PixelTest { mAsserter.is(mSolo.waitForText("Private data cleared"),true,"private data cleared successfully"); // Checking that history list is empty - hList = getHistoryList(); - mAsserter.ok(hList.getAdapter().getCount() == 0,"checking history is cleared ","history is cleared"); + hList = getHistoryList("History", 0); + mAsserter.ok(hList != null,"checking history is cleared ","history is cleared"); } } diff --git a/mobile/android/base/tests/testHistoryTab.java.in b/mobile/android/base/tests/testHistoryTab.java.in index b3148f8f8db2..6837f67e7144 100644 --- a/mobile/android/base/tests/testHistoryTab.java.in +++ b/mobile/android/base/tests/testHistoryTab.java.in @@ -98,25 +98,14 @@ public class testHistoryTab extends PixelTest { } private void testList(String url) { - listview = getHistoryList(); - - // Around midnight we will switch from Today -> Yesterday, account for both - if (!mSolo.waitForText("Today")) { - waitForText("Yesterday"); - } - - mAsserter.isnot(listview, null, "checking that history list exists"); - + listview = getHistoryList("Today|Yesterday", 3); + mAsserter.isnot(listview, null, "checking that history list exists and has 3 children"); final int count = listview.getAdapter().getCount(); - mAsserter.is(count, 3, "history list has 3 children"); - String loadUrl = ""; for (int i = count - 1; i >= 0; i--) { View child = listview.getChildAt(i); - ArrayList views = mSolo.getViews(child); ArrayList imageViews = new ArrayList(); - int expectedImages = 1; for (int j = 0; j < views.size(); j++) { View v = views.get(j); @@ -160,7 +149,7 @@ public class testHistoryTab extends PixelTest { } private void testContextMenu(String url) { - listview = getHistoryList(); + listview = getHistoryList("Today|Yesterday"); waitForText(url); // wait for the history list to be populated @@ -213,8 +202,7 @@ public class testHistoryTab extends PixelTest { } private void testClick(String url) { - listview = getHistoryList(); - + listview = getHistoryList("Today|Yesterday"); waitForText(url); View child = listview.getChildAt(0); diff --git a/mobile/android/base/tests/testShareLink.java.in b/mobile/android/base/tests/testShareLink.java.in index 03fcd3b3b83e..d8b6a86a277d 100644 --- a/mobile/android/base/tests/testShareLink.java.in +++ b/mobile/android/base/tests/testShareLink.java.in @@ -79,15 +79,13 @@ public class testShareLink extends BaseTest { } // Test the share popup in the Bookmarks tab - ListView blist = getBookmarksList(); - mSolo.clickOnText("Bookmarks"); + ListView blist = getBookmarksList("about:firefox"); View bookmark = blist.getChildAt(1); // Getting child at 1 because 0 might be the Desktop folder mSolo.clickLongOnView(bookmark); verifySharePopup(shareOptions,"bookmarks"); // Test the share popup in the History tab - ListView hlist = getHistoryList(); - mSolo.clickOnText("History"); + ListView hlist = getHistoryList("Today|Yesterday"); View history = hlist.getChildAt(1); // Getting child at 1 because 0 might be the "Today" label mSolo.clickLongOnView(history); verifySharePopup(shareOptions,"history");