use of org.mozilla.focus.search.SearchEngine in project Rocket by mozilla-tw.
the class TelemetryWrapper method searchSelectEvent.
public static void searchSelectEvent() {
Telemetry telemetry = TelemetryHolder.get();
TelemetryEvent.create(Category.ACTION, Method.TYPE_SELECT_QUERY, Object.SEARCH_BAR).queue();
SearchEngine searchEngine = SearchEngineManager.getInstance().getDefaultSearchEngine(telemetry.getConfiguration().getContext());
telemetry.recordSearch(SearchesMeasurement.LOCATION_SUGGESTION, searchEngine.getIdentifier());
}
use of org.mozilla.focus.search.SearchEngine in project Rocket by mozilla-tw.
the class SearchSuggestionTest method clickSearchSuggestion_browseByDefaultSearchEngine.
@Test
@Ignore
public void clickSearchSuggestion_browseByDefaultSearchEngine() throws UiObjectNotFoundException, UnsupportedEncodingException {
activityTestRule.launchActivity(new Intent());
final SessionLoadedIdlingResource loadingIdlingResource = new SessionLoadedIdlingResource(activityTestRule.getActivity());
// Click search field
onView(withId(R.id.home_fragment_fake_input)).perform(click());
onView(withId(R.id.url_edit)).check(matches(isDisplayed()));
// Check if the soft keyboard is shown
final InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
Assert.assertTrue(inputMethodManager.isAcceptingText());
onView(withId(R.id.url_edit)).perform(typeText("rocket"));
onView(withId(R.id.search_suggestion)).check(matches(isDisplayed()));
// Check if the suggestion count is shown at most 5
final UiCollection suggestionCollection = new UiCollection(new UiSelector().resourceId(getResourceId("search_suggestion")));
Assert.assertTrue(suggestionCollection.exists());
final int suggestionCount = suggestionCollection.getChildCount(new UiSelector().resourceId(getResourceId("suggestion_item")));
Assert.assertTrue(suggestionCount <= 5);
// Pick a suggestion
final UiObject suggestionItem = suggestionCollection.getChild(new UiSelector().index(new Random().nextInt(suggestionCount)));
final String suggestionText = suggestionItem.getText();
suggestionItem.click();
// Get default search engine
final SearchEngine defaultSearchEngine = SearchEngineManager.getInstance().getDefaultSearchEngine(context);
// After page loading completes
IdlingRegistry.getInstance().register(loadingIdlingResource);
onView(withId(R.id.display_url)).check(matches(isDisplayed()));
// Check if the search result is using default search engine
final String[] searchEngine = defaultSearchEngine.getName().toLowerCase().split(" ");
onView(withId(R.id.display_url)).check(matches(withText(containsString(searchEngine[0]))));
// Check if the search result is matched the suggestion we picked
onView(withId(R.id.display_url)).check(matches(DecodedTextMatcher.withText(containsString(searchEngine[0]))));
IdlingRegistry.getInstance().unregister(loadingIdlingResource);
}
use of org.mozilla.focus.search.SearchEngine in project Rocket by mozilla-tw.
the class TelemetryWrapper method searchEnterEvent.
private static void searchEnterEvent() {
Telemetry telemetry = TelemetryHolder.get();
TelemetryEvent.create(Category.ACTION, Method.TYPE_QUERY, Object.SEARCH_BAR).queue();
SearchEngine searchEngine = SearchEngineManager.getInstance().getDefaultSearchEngine(telemetry.getConfiguration().getContext());
telemetry.recordSearch(SearchesMeasurement.LOCATION_ACTIONBAR, searchEngine.getIdentifier());
}
Aggregations