mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
96e7dd21de
--HG-- rename : build/mobile/robocop/Actions.java.in => build/mobile/robocop/Actions.java rename : build/mobile/robocop/Assert.java.in => build/mobile/robocop/Assert.java rename : build/mobile/robocop/Driver.java.in => build/mobile/robocop/Driver.java rename : build/mobile/robocop/Element.java.in => build/mobile/robocop/Element.java rename : build/mobile/robocop/FennecInstrumentationTestRunner.java.in => build/mobile/robocop/FennecInstrumentationTestRunner.java rename : build/mobile/robocop/FennecMochitestAssert.java.in => build/mobile/robocop/FennecMochitestAssert.java rename : build/mobile/robocop/FennecNativeActions.java.in => build/mobile/robocop/FennecNativeActions.java rename : build/mobile/robocop/FennecNativeDriver.java.in => build/mobile/robocop/FennecNativeDriver.java rename : build/mobile/robocop/FennecNativeElement.java.in => build/mobile/robocop/FennecNativeElement.java rename : build/mobile/robocop/FennecTalosAssert.java.in => build/mobile/robocop/FennecTalosAssert.java rename : build/mobile/robocop/PaintedSurface.java.in => build/mobile/robocop/PaintedSurface.java rename : build/mobile/robocop/RoboCopException.java.in => build/mobile/robocop/RoboCopException.java rename : build/mobile/robocop/RobocopUtils.java.in => build/mobile/robocop/RobocopUtils.java rename : mobile/android/base/tests/AboutHomeTest.java.in => mobile/android/base/tests/AboutHomeTest.java rename : mobile/android/base/tests/BaseTest.java.in => mobile/android/base/tests/BaseTest.java rename : mobile/android/base/tests/ContentContextMenuTest.java.in => mobile/android/base/tests/ContentContextMenuTest.java rename : mobile/android/base/tests/ContentProviderTest.java.in => mobile/android/base/tests/ContentProviderTest.java rename : mobile/android/base/tests/DatabaseHelper.java.in => mobile/android/base/tests/DatabaseHelper.java rename : mobile/android/base/tests/JavascriptTest.java.in => mobile/android/base/tests/JavascriptTest.java rename : mobile/android/base/tests/MotionEventHelper.java.in => mobile/android/base/tests/MotionEventHelper.java rename : mobile/android/base/tests/MotionEventReplayer.java.in => mobile/android/base/tests/MotionEventReplayer.java rename : mobile/android/base/tests/PixelTest.java.in => mobile/android/base/tests/PixelTest.java rename : mobile/android/base/tests/StringHelper.java.in => mobile/android/base/tests/StringHelper.java rename : mobile/android/base/tests/testAboutPage.java.in => mobile/android/base/tests/testAboutPage.java rename : mobile/android/base/tests/testAddSearchEngine.java.in => mobile/android/base/tests/testAddSearchEngine.java rename : mobile/android/base/tests/testAddonManager.java.in => mobile/android/base/tests/testAddonManager.java rename : mobile/android/base/tests/testAwesomebar.java.in => mobile/android/base/tests/testAwesomebar.java rename : mobile/android/base/tests/testAwesomebarSwipes.java.in => mobile/android/base/tests/testAwesomebarSwipes.java rename : mobile/android/base/tests/testAxisLocking.java.in => mobile/android/base/tests/testAxisLocking.java rename : mobile/android/base/tests/testBookmark.java.in => mobile/android/base/tests/testBookmark.java rename : mobile/android/base/tests/testBookmarkFolders.java.in => mobile/android/base/tests/testBookmarkFolders.java rename : mobile/android/base/tests/testBookmarkKeyword.java.in => mobile/android/base/tests/testBookmarkKeyword.java rename : mobile/android/base/tests/testBookmarklets.java.in => mobile/android/base/tests/testBookmarklets.java rename : mobile/android/base/tests/testBookmarksPage.java.in => mobile/android/base/tests/testBookmarksPage.java rename : mobile/android/base/tests/testBrowserProvider.java.in => mobile/android/base/tests/testBrowserProvider.java rename : mobile/android/base/tests/testBrowserProviderPerf.java.in => mobile/android/base/tests/testBrowserProviderPerf.java rename : mobile/android/base/tests/testBrowserSearchVisibility.java.in => mobile/android/base/tests/testBrowserSearchVisibility.java rename : mobile/android/base/tests/testCheck.java.in => mobile/android/base/tests/testCheck.java rename : mobile/android/base/tests/testCheck2.java.in => mobile/android/base/tests/testCheck2.java rename : mobile/android/base/tests/testClearPrivateData.java.in => mobile/android/base/tests/testClearPrivateData.java rename : mobile/android/base/tests/testDeviceSearchEngine.java.in => mobile/android/base/tests/testDeviceSearchEngine.java rename : mobile/android/base/tests/testDistribution.java.in => mobile/android/base/tests/testDistribution.java rename : mobile/android/base/tests/testDoorHanger.java.in => mobile/android/base/tests/testDoorHanger.java rename : mobile/android/base/tests/testFindInPage.java.in => mobile/android/base/tests/testFindInPage.java rename : mobile/android/base/tests/testFlingCorrectness.java.in => mobile/android/base/tests/testFlingCorrectness.java rename : mobile/android/base/tests/testFormHistory.java.in => mobile/android/base/tests/testFormHistory.java rename : mobile/android/base/tests/testGetUserMedia.java.in => mobile/android/base/tests/testGetUserMedia.java rename : mobile/android/base/tests/testHistory.java.in => mobile/android/base/tests/testHistory.java rename : mobile/android/base/tests/testHomeBanner.java.in => mobile/android/base/tests/testHomeBanner.java rename : mobile/android/base/tests/testImportFromAndroid.java.in => mobile/android/base/tests/testImportFromAndroid.java rename : mobile/android/base/tests/testInputUrlBar.java.in => mobile/android/base/tests/testInputUrlBar.java rename : mobile/android/base/tests/testJNI.java.in => mobile/android/base/tests/testJNI.java rename : mobile/android/base/tests/testJarReader.java.in => mobile/android/base/tests/testJarReader.java rename : mobile/android/base/tests/testLinkContextMenu.java.in => mobile/android/base/tests/testLinkContextMenu.java rename : mobile/android/base/tests/testLoad.java.in => mobile/android/base/tests/testLoad.java rename : mobile/android/base/tests/testMailToContextMenu.java.in => mobile/android/base/tests/testMailToContextMenu.java rename : mobile/android/base/tests/testMasterPassword.java.in => mobile/android/base/tests/testMasterPassword.java rename : mobile/android/base/tests/testNewTab.java.in => mobile/android/base/tests/testNewTab.java rename : mobile/android/base/tests/testOrderedBroadcast.java.in => mobile/android/base/tests/testOrderedBroadcast.java rename : mobile/android/base/tests/testOverscroll.java.in => mobile/android/base/tests/testOverscroll.java rename : mobile/android/base/tests/testPan.java.in => mobile/android/base/tests/testPan.java rename : mobile/android/base/tests/testPanCorrectness.java.in => mobile/android/base/tests/testPanCorrectness.java rename : mobile/android/base/tests/testPasswordEncrypt.java.in => mobile/android/base/tests/testPasswordEncrypt.java rename : mobile/android/base/tests/testPasswordProvider.java.in => mobile/android/base/tests/testPasswordProvider.java rename : mobile/android/base/tests/testPermissions.java.in => mobile/android/base/tests/testPermissions.java rename : mobile/android/base/tests/testPictureLinkContextMenu.java.in => mobile/android/base/tests/testPictureLinkContextMenu.java rename : mobile/android/base/tests/testPrefsObserver.java.in => mobile/android/base/tests/testPrefsObserver.java rename : mobile/android/base/tests/testPrivateBrowsing.java.in => mobile/android/base/tests/testPrivateBrowsing.java rename : mobile/android/base/tests/testPromptGridInput.java.in => mobile/android/base/tests/testPromptGridInput.java rename : mobile/android/base/tests/testReaderMode.java.in => mobile/android/base/tests/testReaderMode.java rename : mobile/android/base/tests/testSearchSuggestions.java.in => mobile/android/base/tests/testSearchSuggestions.java rename : mobile/android/base/tests/testSettingsMenuItems.java.in => mobile/android/base/tests/testSettingsMenuItems.java rename : mobile/android/base/tests/testShareLink.java.in => mobile/android/base/tests/testShareLink.java rename : mobile/android/base/tests/testSharedPreferences.java.in => mobile/android/base/tests/testSharedPreferences.java rename : mobile/android/base/tests/testSystemPages.java.in => mobile/android/base/tests/testSystemPages.java rename : mobile/android/base/tests/testTabHistory.java.in => mobile/android/base/tests/testTabHistory.java rename : mobile/android/base/tests/testThumbnails.java.in => mobile/android/base/tests/testThumbnails.java rename : mobile/android/base/tests/testVkbOverlap.java.in => mobile/android/base/tests/testVkbOverlap.java rename : mobile/android/base/tests/test_bug720538.java.in => mobile/android/base/tests/test_bug720538.java extra : rebase_source : c8d715aa110b07c6010054a674879e143a5f04e7 extra : amend_source : fb5714b78e055e336b5e0c6a0da8eb8c931ff09e extra : histedit_source : ec57d8ba94000092438a2ba0bf4fb66091e98513%2C114ade72bb9b72b96557da74f1179734fa347e5c
147 lines
7.0 KiB
Java
147 lines
7.0 KiB
Java
package org.mozilla.gecko.tests;
|
|
|
|
import org.mozilla.gecko.*;
|
|
import android.view.View;
|
|
import android.widget.ListAdapter;
|
|
import android.widget.ListView;
|
|
import java.util.ArrayList;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
/**
|
|
* Test adding a search engine from an input field context menu.
|
|
* 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 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(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(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();
|
|
|
|
ArrayList<String> searchEngines;
|
|
try {
|
|
// Parse the data to get the number of searchengines.
|
|
searchEngines = getSearchEnginesNames(eventData);
|
|
} catch (JSONException e) {
|
|
mAsserter.ok(false, "Fatal exception in testAddSearchEngine while decoding JSON search engine string from Gecko prior to addition of new engine.", e.toString());
|
|
return;
|
|
}
|
|
final int initialNumSearchEngines = searchEngines.size();
|
|
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(initialNumSearchEngines);
|
|
|
|
// Load the page for the search engine to add.
|
|
inputAndLoadUrl(searchEngineURL);
|
|
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.
|
|
getInstrumentation().waitForIdleSync();
|
|
mAsserter.dumpLog("Long Clicking at width = " + String.valueOf(width) + " and height = " + String.valueOf(height));
|
|
mSolo.clickLongOnScreen(width,height);
|
|
|
|
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_SEARCHENGINE_OPTION_TEXT);
|
|
waitForText("Cancel");
|
|
clickOnButton("OK");
|
|
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!
|
|
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 {
|
|
// Parse the data to get the number of searchengines
|
|
searchEngines = getSearchEnginesNames(eventData);
|
|
} catch (JSONException e) {
|
|
mAsserter.ok(false, "Fatal exception in testAddSearchEngine while decoding JSON search engine string from Gecko after adding of new engine.", e.toString());
|
|
return;
|
|
}
|
|
|
|
mAsserter.dumpLog("Search Engines list = " + searchEngines.toString());
|
|
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(initialNumSearchEngines + 1);
|
|
searchEngineDataEventExpector.unregisterListener();
|
|
}
|
|
|
|
/**
|
|
* Helper method to decode a list of search engine names from the provided search engine information
|
|
* JSON string sent from Gecko.
|
|
* @param searchEngineData The JSON string representing the search engine array to process
|
|
* @return An ArrayList<String> containing the names of all the search engines represented in
|
|
* the provided JSON message.
|
|
* @throws JSONException In the event that the JSON provided cannot be decoded.
|
|
*/
|
|
public ArrayList<String> getSearchEnginesNames(String searchEngineData) throws JSONException {
|
|
JSONObject data = new JSONObject(searchEngineData);
|
|
JSONArray engines = data.getJSONArray("searchEngines");
|
|
|
|
ArrayList<String> searchEngineNames = new ArrayList<String>();
|
|
for (int i = 0; i < engines.length(); i++) {
|
|
JSONObject engineJSON = engines.getJSONObject(i);
|
|
searchEngineNames.add(engineJSON.getString("name"));
|
|
}
|
|
return searchEngineNames;
|
|
}
|
|
|
|
/**
|
|
* Method to verify that the displayed number of search engines matches the expected number.
|
|
* @param expectedCount The expected number of search engines.
|
|
*/
|
|
public void verifyDisplayedSearchEnginesCount(final int expectedCount) {
|
|
mSolo.clearEditText(0);
|
|
mActions.sendKeys(SEARCH_TEXT);
|
|
boolean correctNumSearchEnginesDisplayed = waitForTest(new BooleanTest() {
|
|
@Override
|
|
public boolean test() {
|
|
return (findListViewWithTag("browser_search").getAdapter().getCount() == expectedCount);
|
|
}
|
|
}, MAX_WAIT_TEST_MS);
|
|
|
|
// Exit about:home
|
|
mActions.sendSpecialKey(Actions.SpecialKey.BACK);
|
|
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");
|
|
}
|
|
}
|