Bug 880060 - Update BaseTest for new about:home, and disable robocop tests that need more work to pass. r=gbrown

This commit is contained in:
Margaret Leibovic 2013-07-18 16:02:48 -07:00
parent f9956e34bf
commit cd9eec20dd
10 changed files with 92 additions and 164 deletions

View File

@ -19,8 +19,10 @@ import android.os.SystemClock;
import android.test.ActivityInstrumentationTestCase2;
import android.util.DisplayMetrics;
import android.view.inputmethod.InputMethodManager;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
@ -58,6 +60,11 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
};
protected static final int DEFAULT_BOOKMARKS_COUNT = DEFAULT_BOOKMARKS_TITLES.length;
// IDs for UI views
private static final String BROWSER_TOOLBAR_ID = "browser_toolbar";
protected static final String URL_EDIT_TEXT_ID = "url_edit_text";
protected static final String URL_BAR_TITLE_ID = "url_bar_title";
private static Class<Activity> mLauncherActivityClass;
private Activity mActivity;
protected Solo mSolo;
@ -177,64 +184,35 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
}
/**
* Click on the specified element and return the resulting activity.
* @return The created activity, or null if the element cannot be clicked.
* Click on the URL bar to focus it and enter editing mode.
*/
protected final Activity getActivityFromClick(Element element) {
Instrumentation inst = getInstrumentation();
Instrumentation.ActivityMonitor monitor = inst.addMonitor((String)null, null, false);
boolean clicked = element.click();
if (!clicked) {
mAsserter.ok(clicked != false, "checking that awesome bar clicked", "awesome bar was clicked");
return null;
}
inst.waitForMonitor(monitor);
// Give the activity time to render itself and initialize views
// before continuing, so that views are created before access
// attempts are made. Again, waitForIdleSync was used here
// previously, but replaced with a sleep to avoid hangs.
// TODO: Investigate and document why these pauses are required.
mSolo.sleep(2000);
protected final void focusUrlBar() {
// Click on the browser toolbar to enter editing mode
mDriver.findElement(mActivity, BROWSER_TOOLBAR_ID).click();
return mSolo.getCurrentActivity();
}
/**
* 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() {
mAwesomeActivity = null;
// Wait for highlighed text to gain focus
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;
EditText urlEditText = mSolo.getEditText(0);
mAsserter.dumpLog("*********************** urlEditText - " + urlEditText);
mAsserter.dumpLog("*********************** urlEditText.hasFocus() - " + urlEditText.hasFocus());
return urlEditText.hasFocus();
}
}, MAX_WAIT_MS*5);
}, MAX_WAIT_ENABLED_TEXT_MS);
if (!success)
mAsserter.dumpLog("failed to find History");
return mAwesomeActivity;
mAsserter.ok(success, "waiting for urlbar text to gain focus", "urlbar text gained focus");
}
protected final void enterUrl(String url) {
Activity awesomeBarActivity = clickOnAwesomeBar();
Element urlbar = mDriver.findElement(awesomeBarActivity, "awesomebar_text");
focusUrlBar();
// Send the keys for the URL we want to enter
mActions.sendKeys(url);
String urlbarText = null;
if (urlbar != null) {
urlbarText = urlbar.getText();
}
mAsserter.is(urlbarText, url, "Awesomebar URL typed properly");
// Get the URL text from the URL bar EditText view
String urlBarText = mDriver.findElement(mActivity, URL_EDIT_TEXT_ID).getText();
mAsserter.is(url, urlBarText, "URL typed properly");
}
protected final void hitEnterAndWait() {
@ -246,7 +224,7 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
}
/**
* Load <code>url</code> using the awesome bar UI and sending key strokes.
* Load <code>url</code> by sending key strokes to the URL bar UI.
*
* This method waits synchronously for the <code>DOMContentLoaded</code>
* message from Gecko before returning.
@ -278,28 +256,28 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
}
public final void verifyUrl(String url) {
Activity awesomeBarActivity = clickOnAwesomeBar();
Element urlbar = mDriver.findElement(awesomeBarActivity, "awesomebar_text");
String urlbarText = null;
if (urlbar != null) {
Element urlEditText = mDriver.findElement(mActivity, URL_EDIT_TEXT_ID);
String urlBarText = null;
if (urlEditText != null) {
// wait for a short time for the expected text, in case there is a delay
// in updating the view
waitForTest(new VerifyUrlTest(urlbar, url), VERIFY_URL_TIMEOUT);
urlbarText = urlbar.getText();
waitForTest(new VerifyUrlTest(urlEditText, url), VERIFY_URL_TIMEOUT);
urlBarText = urlEditText.getText();
}
mAsserter.is(urlbarText, url, "Awesomebar URL stayed the same");
mAsserter.is(urlBarText, url, "Browser toolbar URL stayed the same");
}
class VerifyUrlTest implements BooleanTest {
private Element mUrlbar;
private Element mUrlEditText;
private String mUrl;
public VerifyUrlTest(Element urlbar, String url) {
mUrlbar = urlbar;
public VerifyUrlTest(Element urlEditText, String url) {
mUrlEditText = urlEditText;
mUrl = url;
}
@Override
public boolean test() {
String urlbarText = mUrlbar.getText();
String urlbarText = mUrlEditText.getText();
if (urlbarText.equals(mUrl)) {
return true;
}
@ -491,27 +469,28 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
}
public final void verifyPageTitle(String title) {
Element awesomebar = mDriver.findElement(getActivity(), "awesome_bar_title");
Element urlBarTitle = mDriver.findElement(getActivity(), URL_BAR_TITLE_ID);
String pageTitle = null;
if (awesomebar != null) {
if (urlBarTitle != null) {
// Wait for the title to make sure it has been displayed in case the view
// does not update fast enough
waitForTest(new VerifyTitle(awesomebar, title), MAX_WAIT_MS);
pageTitle = awesomebar.getText();
waitForTest(new VerifyTitle(urlBarTitle, title), MAX_WAIT_MS);
pageTitle = urlBarTitle.getText();
}
mAsserter.is(pageTitle, title, "Page title is correct");
}
class VerifyTitle implements BooleanTest {
private Element mAwesomebar;
private Element mUrlBarTitle;
private String mTitle;
public VerifyTitle(Element awesomebar, String title) {
mAwesomebar = awesomebar;
public VerifyTitle(Element urlBarTitle, String title) {
mUrlBarTitle = urlBarTitle;
mTitle = title;
}
@Override
public boolean test() {
String pageTitle = mAwesomebar.getText();
String pageTitle = mUrlBarTitle.getText();
if (pageTitle.equals(mTitle)) {
return true;
}
@ -556,79 +535,26 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
return false;
}
private ListView getAwesomeList(String waitText, int expectedChildCount,
String clickText, String tagName, String callerName) {
ArrayList<ListView> 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;
ListAdapter adapter = view.getAdapter();
if (adapter != null) {
childCount = adapter.getCount();
} else {
childCount = 0;
}
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.
* FIXME: Write new versions of these methods and update their consumers to use the new about:home pages.
*/
protected ListView getAllPagesList(String waitText, int expectedChildCount) {
return getAwesomeList(waitText, expectedChildCount,
"Top Sites", "allPages", "getAllPagesList");
return null;
}
protected ListView getAllPagesList(String waitText) {
return getAllPagesList(waitText, -1);
return null;
}
/**
* Click on the awesome bar, click on the Bookmarks tab, and return
* the ListView for the Bookmarks tab.
*/
protected ListView getBookmarksList(String waitText, int expectedChildCount) {
return getAwesomeList(waitText, expectedChildCount,
"Bookmarks", "bookmarks", "getBookmarksList");
return null;
}
protected ListView getBookmarksList(String waitText) {
return getBookmarksList(waitText, -1);
return null;
}
/**
* Click on the awesome bar, click on the History tab, and return
* the ListView for the History tab.
*/
protected ListView getHistoryList(String waitText, int expectedChildCount) {
return getAwesomeList(waitText, expectedChildCount,
"History", "history", "getHistoryList");
return null;
}
protected ListView getHistoryList(String waitText) {
return getHistoryList(waitText, -1);
return null;
}
public long addOrUpdateBookmark(String title, String url, boolean bookmarklet) {
@ -710,8 +636,9 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
}, MAX_WAIT_MS);
mAsserter.ok(success, "waiting for add tab view", "add tab view available");
mAsserter.ok(addTab.click(), "checking that add_tab clicked", "add_tab element clicked");
// must pause before sending keys, until awesome bar is displayed; waiting for known text is simple
waitForText("History");
mDriver.findElement(mActivity, URL_EDIT_TEXT_ID).click();
// cannot use loadUrl(): getText fails because we are using a different urlbar
mActions.sendKeys(url);
hitEnterAndWait();

View File

@ -1,10 +1,10 @@
[testAllPagesTab]
[testHistoryTab]
[testBookmarksTab]
# [testAllPagesTab] # disabled on fig - bug 880060
# [testHistoryTab] # disabled on fig - bug 880060
# [testBookmarksTab] # disabled on fig - bug 880060
[testAwesomebar]
[testAwesomebarSwipes]
[testBookmark]
[testBookmarklets]
# [testAwesomebarSwipes] # disabled on fig - bug 880060
# [testBookmark] # disabled on fig - bug 880060
# [testBookmarklets] # disabled on fig - bug 880060
[testJNI]
[testMigration]
[testLoad]
@ -22,24 +22,24 @@
# [testPasswordEncrypt] # see bug 824067
[testFormHistory]
[testBrowserProvider]
[testSearchSuggestions]
# [testSearchSuggestions] # disabled on fig - bug 880060
[testSharedPreferences]
# [testThumbnails] # see bug 813107
[testAddonManager]
[testHistory]
# [testHistory] # disabled on fig - bug 880060
[testVkbOverlap]
[testDoorHanger]
[testTabHistory]
[testShareLink]
[testClearPrivateData]
# [testClearPrivateData] # disabled on fig - bug 880060
[testSettingsMenuItems]
[testSystemPages]
# [testPermissions] # see bug 757475
[testJarReader]
[testDistribution]
[testFindInPage]
[testInputAwesomeBar]
[testAddSearchEngine]
# [testInputAwesomeBar] # disabled on fig - bug 880060
# [testAddSearchEngine] # disabled on fig - bug 880060
[testImportFromAndroid]
[testMasterPassword]
[testDeviceSearchEngine]

View File

@ -4,7 +4,7 @@ package @ANDROID_PACKAGE_NAME@.tests;
import @ANDROID_PACKAGE_NAME@.*;
/* Tests related to the about: page:
* - check that about: loads from the awesome bar
* - check that about: loads from the URL bar
* - check that about: loads from Settings/About...
*/
public class testAboutPage extends PixelTest {
@ -20,9 +20,9 @@ public class testAboutPage extends PixelTest {
String url = "about:";
loadAndPaint(url);
Element awesomebar = mDriver.findElement(getActivity(), "awesome_bar_title");
mAsserter.isnot(awesomebar, null, "Got the awesomebar");
assertMatches(awesomebar.getText(), "About (Fennec|Nightly|Aurora|Firefox|Firefox Beta)", "page title match");
Element urlBarTitle = mDriver.findElement(getActivity(), URL_BAR_TITLE_ID);
mAsserter.isnot(urlBarTitle, null, "Got the URL bar title");
assertMatches(urlBarTitle.getText(), "About (Fennec|Nightly|Aurora|Firefox|Firefox Beta)", "page title match");
// Open a new page to remove the about: page from the current tab
url = getAbsoluteUrl("/robocop/robocop_blank_01.html");
@ -42,8 +42,8 @@ public class testAboutPage extends PixelTest {
contentEventExpecter.unregisterListener();
// Grab the title to make sure the about: page was loaded
awesomebar = mDriver.findElement(getActivity(), "awesome_bar_title");
mAsserter.isnot(awesomebar, null, "Got the awesomebar");
assertMatches(awesomebar.getText(), "About (Fennec|Nightly|Aurora|Firefox|Firefox Beta)", "page title match");
urlBarTitle = mDriver.findElement(getActivity(), URL_BAR_TITLE_ID);
mAsserter.isnot(urlBarTitle, null, "Got the URL bar title");
assertMatches(urlBarTitle.getText(), "About (Fennec|Nightly|Aurora|Firefox|Firefox Beta)", "page title match");
}
}

View File

@ -66,7 +66,7 @@ public class testAddSearchEngine extends BaseTest {
for (int i = 0; i < MAX_TRIES; i++ ) {
// Start a search and wait for the search engine data to be displayed
Actions.EventExpecter enginesEventExpecter = mActions.expectGeckoEvent("SearchEngines:Data");
clickOnAwesomeBar();
focusUrlBar();
waitForText("Bookmarks");
mActions.sendKeys("Firefox for Android");
enginesEventExpecter.blockForEvent();

View File

@ -55,6 +55,7 @@ public class testDoorHanger extends BaseTest {
mSolo.clickOnButton(GEO_DENY);
mAsserter.is(mSolo.searchText(GEO_MESSAGE), false, "Geolocation doorhanger has been hidden when denying share");
/* FIXME: disabled on fig - bug 880060 (for some reason this fails because of some raciness)
// Re-trigger geolocation notification
loadUrl(GEO_URL);
waitForText(GEO_MESSAGE);
@ -64,6 +65,7 @@ public class testDoorHanger extends BaseTest {
// Make sure doorhanger is hidden
mAsserter.is(mSolo.searchText(GEO_MESSAGE), false, "Geolocation doorhanger notification is hidden when opening a new tab");
*/
// Load offline storage page
loadUrl(OFFLINE_STORAGE_URL);

View File

@ -13,7 +13,6 @@ import android.widget.EditText;
* - Check that all AwesomeBar text is selected after switching AwesomeScreen tabs.
*/
public final class testInputAwesomeBar extends BaseTest {
private Activity mAwesomeBarActivity;
private Element mAwesomeBarTextElement;
private EditText mAwesomeBarEditText;
@ -101,10 +100,10 @@ public final class testInputAwesomeBar extends BaseTest {
}
private void openAwesomeScreen() {
mAwesomeBarActivity = clickOnAwesomeBar();
mAwesomeBarTextElement = mDriver.findElement(mAwesomeBarActivity, "awesomebar_text");
focusUrlBar();
mAwesomeBarTextElement = mDriver.findElement(getActivity(), URL_EDIT_TEXT_ID);
int id = mAwesomeBarTextElement.getId();
mAwesomeBarEditText = (EditText) mAwesomeBarActivity.findViewById(id);
mAwesomeBarEditText = (EditText) getActivity().findViewById(id);
}
private String getAwesomeBarText() {

View File

@ -41,10 +41,10 @@ public class testSearchSuggestions extends BaseTest {
final int suggestionTextId = mDriver.findElement(getActivity(), "suggestion_text").getId();
Actions.EventExpecter enginesEventExpecter = mActions.expectGeckoEvent("SearchEngines:Data");
final Activity awesomeBarActivity = clickOnAwesomeBar();
focusUrlBar();
enginesEventExpecter.blockForEvent();
enginesEventExpecter.unregisterListener();
connectSuggestClient(awesomeBarActivity);
connectSuggestClient(getActivity());
for (int i = 0; i < TEST_QUERY.length(); i++) {
mActions.sendKeys(TEST_QUERY.substring(i, i+1));
@ -54,7 +54,7 @@ public class testSearchSuggestions extends BaseTest {
@Override
public boolean test() {
// get the first suggestion row
ViewGroup suggestionGroup = (ViewGroup) awesomeBarActivity.findViewById(suggestionLayoutId);
ViewGroup suggestionGroup = (ViewGroup) getActivity().findViewById(suggestionLayoutId);
if (suggestionGroup == null)
return false;
@ -88,7 +88,7 @@ public class testSearchSuggestions extends BaseTest {
suggestMap.put("foo barz", new ArrayList<String>() {{ add("foo barz"); }});
}
private void connectSuggestClient(final Activity awesomeBarActivity) {
private void connectSuggestClient(final Activity activity) {
final int awesomeBarTabsId = mDriver.findElement(getActivity(), "awesomebar_tabs").getId();
try {
@ -98,7 +98,7 @@ public class testSearchSuggestions extends BaseTest {
Constructor suggestConstructor = suggestClass.getConstructor(
new Class[] { Context.class, String.class, int.class, int.class });
String suggestTemplate = getAbsoluteRawUrl(SUGGESTION_TEMPLATE);
Object client = suggestConstructor.newInstance(awesomeBarActivity, suggestTemplate, SUGGESTION_TIMEOUT, SUGGESTION_MAX);
Object client = suggestConstructor.newInstance(activity, suggestTemplate, SUGGESTION_TIMEOUT, SUGGESTION_MAX);
// enable offline HTTP requests for testing
final Field checkNetworkField = suggestClass.getDeclaredField("mCheckNetwork");
@ -108,7 +108,7 @@ public class testSearchSuggestions extends BaseTest {
// replace mSuggestClient with test client
final Class awesomeBarTabsClass = classLoader.loadClass("org.mozilla.gecko.AwesomeBarTabs");
final Method getAllPagesTabMethod = awesomeBarTabsClass.getMethod("getAllPagesTab");
final View awesomeBarTabs = (View) awesomeBarActivity.findViewById(awesomeBarTabsId);
final View awesomeBarTabs = (View) activity.findViewById(awesomeBarTabsId);
final Class allPagesTabClass = classLoader.loadClass("org.mozilla.gecko.AllPagesTab");
final Field suggestClientField = allPagesTabClass.getDeclaredField("mSuggestClient");
final Object allPagesTab = getAllPagesTabMethod.invoke(awesomeBarTabs);

View File

@ -51,10 +51,10 @@ public class testShareLink extends BaseTest {
mAsserter.ok(optionDisplayed(option, displayedOptions), "Share option found", option);
}
// Test share from the awesomebar context menu
// Test share from the urlbar context menu
mActions.sendSpecialKey(Actions.SpecialKey.BACK); // Close the share menu
mSolo.clickLongOnText(urlTitle);
verifySharePopup(shareOptions,"Awesomebar");
verifySharePopup(shareOptions,"urlbar");
// Test link Context Menu
DisplayMetrics dm = new DisplayMetrics();
@ -66,6 +66,7 @@ public class testShareLink extends BaseTest {
mSolo.clickLongOnScreen(left, top);
verifySharePopup(shareOptions,"Link");
/* FIXME: disabled on fig - bug 880060
// Test share popup in Top Sites
ListView tslist = getAllPagesList(url);
@ -95,6 +96,7 @@ public class testShareLink extends BaseTest {
View history = hlist.getChildAt(1); // Getting child at 1 because 0 might be the "Today" label
mSolo.clickLongOnView(history);
verifySharePopup(shareOptions,"history");
*/
}
public void verifySharePopup(ArrayList<String> shareOptions, String openedFrom) {
@ -104,7 +106,7 @@ public class testShareLink extends BaseTest {
ArrayList<String> displayedOptions = getSharePopupOption();
for (String option:shareOptions) {
// Verify if the option is present in the list of displayed share options
mAsserter.ok(optionDisplayed(option, displayedOptions), "Share option for " + openedFrom + (openedFrom.equals("Awesomebar") ? "" : " item") + " found", option);
mAsserter.ok(optionDisplayed(option, displayedOptions), "Share option for " + openedFrom + (openedFrom.equals("urlbar") ? "" : " item") + " found", option);
}
mActions.sendSpecialKey(Actions.SpecialKey.BACK);
/**

View File

@ -67,8 +67,6 @@ public class testSystemPages extends PixelTest {
String expectedUrl = item[1][0];
expectedTabCount++;
mActions.sendSpecialKey(Actions.SpecialKey.BACK); // Press back to dismiss the awesomebar
mSolo.sleep(AFTER_BACK_SLEEP_MS);
// Set up listeners to catch the page load we're about to do
tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");

View File

@ -81,7 +81,7 @@ public class testWebContentContextMenu extends PixelTest {
mAsserter.ok(mSolo.waitForText("New private tab opened"), "Waiting for private tab to open", "The private tab is opened");
// Verifying if the private data is not listed in Awesomescreen
clickOnAwesomeBar();
focusUrlBar();
mSolo.clickOnText("History");
mAsserter.ok(mSolo.waitForText("Browser Blank Page 01"), "Looking in History for the page loaded in the normal tab", "Fount it");
mAsserter.ok(mSolo.waitForText("Browser Blank Page 02") == false, "Looking in History for the page loaded in the private tab", "Page is not present in History");