use of org.mozilla.focus.helper.SessionLoadedIdlingResource in project Rocket by mozilla-tw.
the class HomeTest method clickTopSite_loadTopSite.
@Test
public void clickTopSite_loadTopSite() {
// Now start the activity
activityRule.launchActivity(new Intent());
loadingIdlingResource = new SessionLoadedIdlingResource(activityRule.getActivity());
final MainActivity context = activityRule.getActivity();
try {
// Get test top sites
final JSONArray jsonDefault = new JSONArray(Inject.getDefaultTopSites(context));
final List<Site> defaultSites = TopSitesUtils.paresJsonToList(context, jsonDefault);
// Check the title of the sample top site is correct
onView(withId(R.id.main_list)).check(matches(atPosition(0, hasDescendant(withText(defaultSites.get(0).getTitle())))));
// Click and load the sample top site
onView(ViewMatchers.withId(R.id.main_list)).perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
// After page loading completes
IdlingRegistry.getInstance().register(loadingIdlingResource);
// Check if the url is displayed correctly
onView(withText(defaultSites.get(0).getUrl())).check(matches(isDisplayed()));
// Always remember to unregister idling resource
IdlingRegistry.getInstance().unregister(loadingIdlingResource);
} catch (JSONException e) {
e.printStackTrace();
throw new AssertionError("testTopSite failed:", e);
}
}
use of org.mozilla.focus.helper.SessionLoadedIdlingResource in project Rocket by mozilla-tw.
the class NavigationTest method browsingWebsiteBackAndForward_backAndFrowardToWebsite.
@Test
public void browsingWebsiteBackAndForward_backAndFrowardToWebsite() {
final SessionLoadedIdlingResource loadingIdlingResource = new SessionLoadedIdlingResource(activityTestRule.getActivity());
// Click search field
onView(withId(R.id.home_fragment_fake_input)).perform(click());
// Enter site 1 url
onView(withId(R.id.url_edit)).check(matches(isDisplayed()));
onView(withId(R.id.url_edit)).perform(typeText(TARGET_URL_SITE_1));
onView(withId(R.id.url_edit)).perform(pressKey(KeyEvent.KEYCODE_ENTER));
// Check if site 1 url is loaded
IdlingRegistry.getInstance().register(loadingIdlingResource);
onView(withId(R.id.display_url)).check(matches(isDisplayed())).check(matches(withText(TARGET_URL_SITE_1)));
IdlingRegistry.getInstance().unregister(loadingIdlingResource);
// Click search button and clear existing text in search field
onView(withId(R.id.btn_search)).perform(click());
onView(withId(R.id.url_edit)).perform(clearText());
// Enter site 2 url
onView(withId(R.id.url_edit)).perform(typeText(TARGET_URL_SITE_2));
onView(withId(R.id.url_edit)).perform(pressKey(KeyEvent.KEYCODE_ENTER));
// Check if site 2 url is loaded
IdlingRegistry.getInstance().register(loadingIdlingResource);
onView(withId(R.id.display_url)).check(matches(isDisplayed())).check(matches(withText(TARGET_URL_SITE_2)));
IdlingRegistry.getInstance().unregister(loadingIdlingResource);
// Press back and check if go back to site 1
Espresso.pressBack();
IdlingRegistry.getInstance().register(loadingIdlingResource);
onView(withId(R.id.display_url)).check(matches(isDisplayed())).check(matches(withText(TARGET_URL_SITE_1)));
IdlingRegistry.getInstance().unregister(loadingIdlingResource);
// Open menu and click next button
onView(withId(R.id.btn_menu)).check(matches(isDisplayed())).perform(click());
onView(withId(R.id.action_next)).check(matches(isDisplayed())).perform(click());
// Check if site 2 is loaded again
IdlingRegistry.getInstance().register(loadingIdlingResource);
onView(withId(R.id.display_url)).check(matches(isDisplayed())).check(matches(withText(TARGET_URL_SITE_2)));
IdlingRegistry.getInstance().unregister(loadingIdlingResource);
// Press back and check if site 1 is loading again
Espresso.pressBack();
IdlingRegistry.getInstance().register(loadingIdlingResource);
onView(withId(R.id.display_url)).check(matches(isDisplayed())).check(matches(withText(TARGET_URL_SITE_1)));
IdlingRegistry.getInstance().unregister(loadingIdlingResource);
}
use of org.mozilla.focus.helper.SessionLoadedIdlingResource in project Rocket by mozilla-tw.
the class ScreenNavigatorTest method assertNewPageLoaded.
private void assertNewPageLoaded(MainThreadScreenNavigator navigator, String url) {
final SessionLoadedIdlingResource loadingIdlingResource = new SessionLoadedIdlingResource(activityTestRule.getActivity());
navigator.showBrowserScreen(url, true, false);
IdlingRegistry.getInstance().register(loadingIdlingResource);
onView(withId(R.id.display_url)).check(matches(isDisplayed()));
onView(withId(R.id.display_url)).check(matches(isDisplayed())).check(matches(withText(url)));
Assert.assertEquals(true, navigator.isBrowserInForeground());
IdlingRegistry.getInstance().unregister(loadingIdlingResource);
}
use of org.mozilla.focus.helper.SessionLoadedIdlingResource in project Rocket by mozilla-tw.
the class WebGeolocationPermissionTest method webPopupGeoPermissionRequest_clickAllowAndUpdateGeoData.
@Test
public void webPopupGeoPermissionRequest_clickAllowAndUpdateGeoData() {
// Start the activity
activityRule.launchActivity(new Intent());
final SessionLoadedIdlingResource sessionLoadedIdlingResource = new SessionLoadedIdlingResource(activityRule.getActivity());
// Click and prepare to enter the URL
onView(withId(R.id.home_fragment_fake_input)).perform(click());
// Enter URL and load the page
onView(withId(R.id.url_edit)).perform(replaceText(webServer.url(TEST_PATH).toString()), pressImeActionButton());
// Waiting for page loading completes
IdlingRegistry.getInstance().register(sessionLoadedIdlingResource);
// Find the element in HTML with id "get_button" and click it. "get_button" will try to access user's current location
onWebView().withElement(findElement(Locator.ID, HTML_ELEMENT_ID_GET_BUTTON)).perform(webClick());
// Check the Geolocation permission dialog is popup and click allow button
onView(withText(R.string.geolocation_dialog_allow)).check(matches(isDisplayed())).perform(click());
// Once the permission is granted, web page will start updating Geolocation
onWebView().withElement(findElement(Locator.ID, HTML_ELEMENT_ID_RESULT)).check(webMatches(getText(), containsString(RESULT_CHECK_TEXT)));
// Unregister session loaded idling resource
IdlingRegistry.getInstance().unregister(sessionLoadedIdlingResource);
}
use of org.mozilla.focus.helper.SessionLoadedIdlingResource in project Rocket by mozilla-tw.
the class BrowsingHistoryTest method browsingWebsiteThenTapTheFirstHistoryItem_browsingHistoryRecordCorrectly.
@Test
public void browsingWebsiteThenTapTheFirstHistoryItem_browsingHistoryRecordCorrectly() {
activityTestRule.launchActivity(new Intent());
// loadingIdlingResource needs to be initialized here cause activity only exist till above line is called.
loadingIdlingResource = new SessionLoadedIdlingResource(activityTestRule.getActivity());
final String targerUrl = webServer.url(TEST_PATH).toString();
// Click search field
onView(withId(R.id.home_fragment_fake_input)).perform(click());
// Enter target url
onView(allOf(withId(R.id.url_edit), isDisplayed())).perform(replaceText(targerUrl), pressImeActionButton());
// Check if target url is loaded
IdlingRegistry.getInstance().register(loadingIdlingResource);
onView(allOf(withId(R.id.display_url), isDisplayed())).check(matches(withText(targerUrl)));
// Open menu
onView(allOf(withId(R.id.btn_menu), isDisplayed())).perform(click());
// Open history panel
onView(allOf(withId(R.id.menu_history), isDisplayed())).perform(click());
// Click the first item in history panel
onView(ViewMatchers.withId(R.id.browsing_history_recycler_view)).perform(RecyclerViewActions.actionOnItemAtPosition(1, click()));
// Check if this history record is target url and loaded again
onView(allOf(withId(R.id.display_url), isDisplayed())).check(matches(withText(targerUrl)));
}
Aggregations