Bug 896560 - Update testSearchSuggestions test for new about:home (r=margaret)

This commit is contained in:
Lucas Rocha 2013-08-14 22:53:34 +01:00
Родитель 16f5081288
Коммит c0a13cd224
3 изменённых файлов: 35 добавлений и 21 удалений

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

@ -16,6 +16,9 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.SystemClock;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.test.ActivityInstrumentationTestCase2;
import android.util.DisplayMetrics;
import android.view.inputmethod.InputMethodManager;
@ -222,6 +225,11 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
mAsserter.is(url, urlBarText, "URL typed properly");
}
protected final Fragment getBrowserSearch() {
final FragmentManager fm = ((FragmentActivity) getActivity()).getSupportFragmentManager();
return fm.findFragmentByTag("browser_search");
}
protected final void hitEnterAndWait() {
Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
mActions.sendSpecialKey(Actions.SpecialKey.ENTER);

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

@ -18,7 +18,7 @@
# [testPasswordEncrypt] # see bug 824067
[testFormHistory]
[testBrowserProvider]
# [testSearchSuggestions] # disabled on fig - bug 880060
[testSearchSuggestions]
[testSharedPreferences]
# [testThumbnails] # see bug 813107
[testAddonManager]

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

@ -4,6 +4,7 @@ package @ANDROID_PACKAGE_NAME@.tests;
import @ANDROID_PACKAGE_NAME@.*;
import android.app.Activity;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
@ -40,15 +41,26 @@ public class testSearchSuggestions extends BaseTest {
final int suggestionLayoutId = mDriver.findElement(getActivity(), "suggestion_layout").getId();
final int suggestionTextId = mDriver.findElement(getActivity(), "suggestion_text").getId();
Actions.EventExpecter enginesEventExpecter = mActions.expectGeckoEvent("SearchEngines:Data");
focusUrlBar();
enginesEventExpecter.blockForEvent();
enginesEventExpecter.unregisterListener();
connectSuggestClient(getActivity());
for (int i = 0; i < TEST_QUERY.length(); i++) {
Actions.EventExpecter enginesEventExpecter = null;
if (i == 0) {
enginesEventExpecter = mActions.expectGeckoEvent("SearchEngines:Data");
}
mActions.sendKeys(TEST_QUERY.substring(i, i+1));
// The BrowserSearch UI only shows up once a non-empty
// search term is entered
if (enginesEventExpecter != null) {
connectSuggestClient(getActivity());
enginesEventExpecter.blockForEvent();
enginesEventExpecter.unregisterListener();
enginesEventExpecter = null;
}
final String query = TEST_QUERY.substring(0, i+1);
boolean success = waitForTest(new BooleanTest() {
@Override
@ -72,6 +84,7 @@ public class testSearchSuggestions extends BaseTest {
return true;
}
}, SUGGESTION_TIMEOUT);
mAsserter.is(success, true, "Results for query '" + query + "' matched expected suggestions");
}
}
@ -89,12 +102,10 @@ public class testSearchSuggestions extends BaseTest {
}
private void connectSuggestClient(final Activity activity) {
final int awesomeBarTabsId = mDriver.findElement(getActivity(), "awesomebar_tabs").getId();
try {
// create a SuggestClient that uses robocop_suggestions.sjs
ClassLoader classLoader = getActivity().getApplicationContext().getClassLoader();
Class suggestClass = classLoader.loadClass("org.mozilla.gecko.SuggestClient");
Class suggestClass = classLoader.loadClass("org.mozilla.gecko.home.SuggestClient");
Constructor suggestConstructor = suggestClass.getConstructor(
new Class[] { Context.class, String.class, int.class, int.class });
String suggestTemplate = getAbsoluteRawUrl(SUGGESTION_TEMPLATE);
@ -106,25 +117,20 @@ public class testSearchSuggestions extends BaseTest {
checkNetworkField.setBoolean(client, false);
// replace mSuggestClient with test client
final Class awesomeBarTabsClass = classLoader.loadClass("org.mozilla.gecko.AwesomeBarTabs");
final Method getAllPagesTabMethod = awesomeBarTabsClass.getMethod("getAllPagesTab");
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);
final Class browserSearchClass = classLoader.loadClass("org.mozilla.gecko.home.BrowserSearch");
final Field suggestClientField = browserSearchClass.getDeclaredField("mSuggestClient");
suggestClientField.setAccessible(true);
waitForTest(new BooleanTest() {
@Override
public boolean test() {
// wait for mSuggestClient to be set before we replace it
try {
return suggestClientField.get(allPagesTab) != null;
} catch (IllegalAccessException e) {
return false;
}
final Fragment browserSearch = getBrowserSearch();
return (browserSearch != null);
}
}, SUGGESTION_TIMEOUT);
suggestClientField.set(allPagesTab, client);
final Fragment browserSearch = getBrowserSearch();
suggestClientField.set(browserSearch, client);
} catch (Exception e) {
throw new RuntimeException("Error setting SuggestClient", e);
}