mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
Bug 896574 - Fix testAddSearchEngine to work with the new about:home. r=lucasr
This commit is contained in:
parent
7fc29f20ec
commit
6037be2b03
@ -39,7 +39,7 @@
|
||||
[testDistribution]
|
||||
[testFindInPage]
|
||||
[testInputUrlBar]
|
||||
# [testAddSearchEngine] # disabled on fig - bug 880060
|
||||
[testAddSearchEngine]
|
||||
[testImportFromAndroid]
|
||||
[testMasterPassword]
|
||||
[testDeviceSearchEngine]
|
||||
|
@ -4,7 +4,7 @@
|
||||
</header>
|
||||
<body>
|
||||
<form method="get" action="http://www.google.com/search">
|
||||
<input type="text" name="q" size="50" maxlength="255" value="" />
|
||||
<input type="text" name="q" style="width:300px; height:500px;" maxlength="255" value="" />
|
||||
<input type="submit" value="Google Search" />
|
||||
</form>
|
||||
</body>
|
||||
|
@ -5,7 +5,6 @@ import @ANDROID_PACKAGE_NAME@.*;
|
||||
import android.view.View;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.util.Log;
|
||||
import java.util.ArrayList;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@ -13,29 +12,36 @@ import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Test adding a search engine from an input field context menu.
|
||||
* 1. Get the number of existing search engines (As shown in the AwesomeScreen).
|
||||
* 1. Get the number of existing search engines from the SearchEngine:Data event and as displayed in about:home.
|
||||
* 2. Load a page with a text field, open the context menu and add a search engine from the page.
|
||||
* 3. Get the number of search engines after adding the new one and verify it has increased by 1.
|
||||
*/
|
||||
public class testAddSearchEngine extends PixelTest {
|
||||
public class testAddSearchEngine extends AboutHomeTest {
|
||||
private final int MAX_WAIT_TEST_MS = 5000;
|
||||
private final String SEARCH_TEXT = "Firefox for Android";
|
||||
private final String ADD_SEARCHENGINE_OPTION_TEXT = "Add Search Engine";
|
||||
|
||||
@Override
|
||||
protected int getTestType() {
|
||||
return TEST_MOCHITEST;
|
||||
}
|
||||
|
||||
public void testAddSearchEngine() {
|
||||
String blankPageURL = getAbsoluteUrl("/robocop/robocop_blank_01.html");
|
||||
String searchEngineURL = getAbsoluteUrl("/robocop/robocop_search.html");
|
||||
String blankPageURL = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL);
|
||||
String searchEngineURL = getAbsoluteUrl(StringHelper.ROBOCOP_SEARCH_URL);
|
||||
|
||||
blockForGeckoReady();
|
||||
int height = mDriver.getGeckoTop() + 150;
|
||||
int width = mDriver.getGeckoLeft() + 150;
|
||||
|
||||
inputAndLoadUrl(blankPageURL);
|
||||
waitForText("Browser Blank Page 01");
|
||||
waitForText(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE);
|
||||
|
||||
// Get the searchengine data by clicking the awesomebar - this causes Gecko to send Java the list
|
||||
// of search engines.
|
||||
Actions.EventExpecter searchEngineDataEventExpector = mActions.expectGeckoEvent("SearchEngines:Data");
|
||||
focusUrlBar();
|
||||
mActions.sendKeys(SEARCH_TEXT);
|
||||
String eventData = searchEngineDataEventExpector.blockForEventData();
|
||||
searchEngineDataEventExpector.unregisterListener();
|
||||
|
||||
@ -51,38 +57,36 @@ public class testAddSearchEngine extends PixelTest {
|
||||
mAsserter.dumpLog("Search Engines list = " + searchEngines.toString());
|
||||
|
||||
// Verify that the number of displayed search engines is the same as the one received through the SearchEngines:Data event.
|
||||
verifyDisplayedSearchEnginesCount("Browser Blank Page 01", initialNumSearchEngines);
|
||||
verifyDisplayedSearchEnginesCount(initialNumSearchEngines);
|
||||
|
||||
// Load the page for the search engine to add.
|
||||
inputAndLoadUrl(searchEngineURL);
|
||||
waitForText("Robocop Search Engine");
|
||||
waitForText(StringHelper.ROBOCOP_SEARCH_TITLE);
|
||||
verifyPageTitle(StringHelper.ROBOCOP_SEARCH_TITLE);
|
||||
|
||||
// Used to long-tap on the search input box for the search engine to add.
|
||||
int height = mDriver.getGeckoTop() + 10;
|
||||
int width = mDriver.getGeckoLeft() + 20;
|
||||
getInstrumentation().waitForIdleSync();
|
||||
mAsserter.dumpLog("Long Clicking at width = " + String.valueOf(width) + " and height = " + String.valueOf(height));
|
||||
mSolo.clickLongOnScreen(width,height);
|
||||
if (!waitForText("Add Search Engine")) {
|
||||
// TODO: clickLongOnScreen does not always work - known Robotium issue - . Clicking a second time seems to work.
|
||||
mAsserter.dumpLog("Something went wrong and the context menu was not opened. Trying again");
|
||||
mSolo.clickLongOnScreen(width,height);
|
||||
}
|
||||
mAsserter.ok(waitForText("Add Search Engine"), "Waiting for the context menu to be opened", "The context menu was opened");
|
||||
|
||||
mAsserter.ok(waitForText(ADD_SEARCHENGINE_OPTION_TEXT), "Waiting for the context menu to be opened", "The context menu was opened");
|
||||
|
||||
// Add the search engine
|
||||
mSolo.clickOnText("Add Search Engine");
|
||||
mSolo.clickOnText(ADD_SEARCHENGINE_OPTION_TEXT);
|
||||
waitForText("Cancel");
|
||||
clickOnButton("OK");
|
||||
mAsserter.ok(!mSolo.searchText("Add Search Engine"), "Adding the Search Engine", "The add Search Engine pop-up has been closed");
|
||||
mAsserter.ok(!mSolo.searchText(ADD_SEARCHENGINE_OPTION_TEXT), "Adding the Search Engine", "The add Search Engine pop-up has been closed");
|
||||
waitForText(StringHelper.ROBOCOP_SEARCH_TITLE); // Make sure the pop-up is closed and we are back at the searchengine page
|
||||
|
||||
// Load Robocop Blank 1 again to give the time for the searchengine to be added
|
||||
// TODO: This is a potential source of intermittent oranges - it's a race condition!
|
||||
loadAndPaint(blankPageURL);
|
||||
waitForText("Browser Blank Page 01");
|
||||
loadUrl(blankPageURL);
|
||||
waitForText(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE);
|
||||
|
||||
// Load search engines again and check that the quantity of engines has increased by 1.
|
||||
searchEngineDataEventExpector = mActions.expectGeckoEvent("SearchEngines:Data");
|
||||
focusUrlBar();
|
||||
mActions.sendKeys(SEARCH_TEXT);
|
||||
eventData = searchEngineDataEventExpector.blockForEventData();
|
||||
|
||||
try {
|
||||
@ -97,7 +101,7 @@ public class testAddSearchEngine extends PixelTest {
|
||||
mAsserter.is(searchEngines.size(), initialNumSearchEngines + 1, "Checking the number of Search Engines has increased");
|
||||
|
||||
// Verify that the number of displayed searchengines is the same as the one received through the SearchEngines:Data event.
|
||||
verifyDisplayedSearchEnginesCount("Browser Blank Page 01", initialNumSearchEngines + 1);
|
||||
verifyDisplayedSearchEnginesCount(initialNumSearchEngines + 1);
|
||||
searchEngineDataEventExpector.unregisterListener();
|
||||
}
|
||||
|
||||
@ -123,51 +127,21 @@ public class testAddSearchEngine extends PixelTest {
|
||||
|
||||
/**
|
||||
* Method to verify that the displayed number of search engines matches the expected number.
|
||||
* Uses a BooleanTest which counts how many SearchEngineRow instances are being displayed
|
||||
* in the Awesomescreen.
|
||||
* @param waitText Text from the loaded page to expect. Used to detect when the Awesomescreen
|
||||
* close animation has completed.
|
||||
* @param expectedCountParam The expected number of search engines.
|
||||
* @param expectedCount The expected number of search engines.
|
||||
*/
|
||||
public void verifyDisplayedSearchEnginesCount(String waitText, int expectedCountParam) {
|
||||
final int expectedCount = expectedCountParam;
|
||||
mActions.sendKeys("Firefox for Android");
|
||||
public void verifyDisplayedSearchEnginesCount(final int expectedCount) {
|
||||
mSolo.clearEditText(0);
|
||||
mActions.sendKeys(SEARCH_TEXT);
|
||||
boolean correctNumSearchEnginesDisplayed = waitForTest(new BooleanTest() {
|
||||
@Override
|
||||
public boolean test() {
|
||||
ArrayList<ListView> views;
|
||||
int searchEngineCount = 0;
|
||||
views = mSolo.getCurrentViews(ListView.class);
|
||||
for (ListView view : views) {
|
||||
ListAdapter adapter = view.getAdapter();
|
||||
if (adapter != null) {
|
||||
// Only count SearchEngineRow views - other views are not relavent to this test.
|
||||
try {
|
||||
ClassLoader classLoader = getActivity().getClassLoader();
|
||||
Class searchEngineRow = classLoader.loadClass("org.mozilla.gecko.SearchEngineRow");
|
||||
for (int i = 0; i < adapter.getCount(); i++ ) {
|
||||
View item = view.getChildAt(i);
|
||||
if (searchEngineRow.isInstance(item)) {
|
||||
searchEngineCount++;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
mAsserter.dumpLog("Exception in verifyDisplayedSearchEnginesCount", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (searchEngineCount == expectedCount) {
|
||||
return true;
|
||||
} else {
|
||||
mAsserter.dumpLog("The wrong number of search engines was found. Found " + searchEngineCount + " search engines");
|
||||
return false;
|
||||
}
|
||||
return (findListViewWithTag("browser_search").getAdapter().getCount() == expectedCount);
|
||||
}
|
||||
}, MAX_WAIT_TEST_MS);
|
||||
|
||||
// Close the Awesomescreen
|
||||
// Exit about:home
|
||||
mActions.sendSpecialKey(Actions.SpecialKey.BACK);
|
||||
waitForText(waitText);
|
||||
waitForText(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE);
|
||||
mAsserter.ok(correctNumSearchEnginesDisplayed, expectedCount + " Search Engines should be displayed" , "The correct number of Search Engines has been displayed");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user