Search in sources :

Example 1 with SessionLoadedIdlingResource

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);
    }
}
Also used : Site(org.mozilla.focus.history.model.Site) SessionLoadedIdlingResource(org.mozilla.focus.helper.SessionLoadedIdlingResource) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Intent(android.content.Intent) Test(org.junit.Test)

Example 2 with SessionLoadedIdlingResource

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);
}
Also used : SessionLoadedIdlingResource(org.mozilla.focus.helper.SessionLoadedIdlingResource) Test(org.junit.Test)

Example 3 with SessionLoadedIdlingResource

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);
}
Also used : SessionLoadedIdlingResource(org.mozilla.focus.helper.SessionLoadedIdlingResource)

Example 4 with SessionLoadedIdlingResource

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);
}
Also used : SessionLoadedIdlingResource(org.mozilla.focus.helper.SessionLoadedIdlingResource) Intent(android.content.Intent) Test(org.junit.Test)

Example 5 with 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)));
}
Also used : SessionLoadedIdlingResource(org.mozilla.focus.helper.SessionLoadedIdlingResource) Intent(android.content.Intent) Test(org.junit.Test)

Aggregations

SessionLoadedIdlingResource (org.mozilla.focus.helper.SessionLoadedIdlingResource)7 Test (org.junit.Test)6 Intent (android.content.Intent)5 UiCollection (android.support.test.uiautomator.UiCollection)1 UiObject (android.support.test.uiautomator.UiObject)1 UiSelector (android.support.test.uiautomator.UiSelector)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 File (java.io.File)1 Random (java.util.Random)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 Ignore (org.junit.Ignore)1 Site (org.mozilla.focus.history.model.Site)1 SearchEngine (org.mozilla.focus.search.SearchEngine)1 NoRemovableStorageException (org.mozilla.focus.utils.NoRemovableStorageException)1