Search in sources :

Example 6 with Site

use of org.mozilla.focus.history.model.Site 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 7 with Site

use of org.mozilla.focus.history.model.Site in project Rocket by mozilla-tw.

the class RemoveTopSitesTest method deleteTopSite_deleteSuccessfully.

@Test
public void deleteTopSite_deleteSuccessfully() {
    // Pick a test site to delete
    final int siteIndex = new Random().nextInt(siteList.size());
    final Site testSite = siteList.get(siteIndex);
    onView(withId(R.id.main_list)).check(matches(isDisplayed()));
    // Check the title of test site is matched
    onView(withId(R.id.main_list)).check(matches(atPosition(siteIndex, hasDescendant(withText(testSite.getTitle())))));
    // Long click the test site
    onView(ViewMatchers.withId(R.id.main_list)).perform(RecyclerViewActions.actionOnItemAtPosition(siteIndex, longClick()));
    // Check the remove button is displayed
    onView(withText(removeLabel)).check(matches(isDisplayed()));
    // Click the remove button
    onView(withText(removeLabel)).inRoot(RootMatchers.isPlatformPopup()).perform(click());
    // Check the test site is removed
    onView(withId(R.id.main_list)).check(matches(not(atPosition(siteIndex, hasDescendant(withText(testSite.getTitle()))))));
}
Also used : Site(org.mozilla.focus.history.model.Site) Random(java.util.Random) Test(org.junit.Test)

Example 8 with Site

use of org.mozilla.focus.history.model.Site in project Rocket by mozilla-tw.

the class RemoveTopSitesTest method deleteTopSiteAndCancel_topSiteIsStillThere.

@Test
public void deleteTopSiteAndCancel_topSiteIsStillThere() {
    // Pick a test site to test
    final int siteIndex = new Random().nextInt(siteList.size());
    final Site testSite = siteList.get(siteIndex);
    onView(withId(R.id.main_list)).check(matches(isDisplayed()));
    // Check the title of test site is matched
    onView(withId(R.id.main_list)).check(matches(atPosition(siteIndex, hasDescendant(withText(testSite.getTitle())))));
    // Long click the test site
    onView(ViewMatchers.withId(R.id.main_list)).perform(RecyclerViewActions.actionOnItemAtPosition(siteIndex, longClick()));
    // Check the remove button is displayed
    onView(withText(removeLabel)).check(matches(isDisplayed()));
    // Press the back key
    Espresso.pressBack();
    // Check the title of test site is matched
    onView(withId(R.id.main_list)).check(matches(atPosition(siteIndex, hasDescendant(withText(testSite.getTitle())))));
}
Also used : Site(org.mozilla.focus.history.model.Site) Random(java.util.Random) Test(org.junit.Test)

Example 9 with Site

use of org.mozilla.focus.history.model.Site in project Rocket by mozilla-tw.

the class HistoryItemAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
    if (holder instanceof SiteItemViewHolder) {
        final Site item = (Site) mItems.get(position);
        if (item != null) {
            final SiteItemViewHolder siteVH = (SiteItemViewHolder) holder;
            siteVH.rootView.setOnClickListener(this);
            siteVH.textMain.setText(item.getTitle());
            siteVH.textSecondary.setText(item.getUrl());
            Bitmap bmpFav = item.getFavIcon();
            if (bmpFav != null) {
                siteVH.imgFav.setImageBitmap(bmpFav);
            } else {
                siteVH.imgFav.setImageResource(R.drawable.ic_globe);
            }
            final PopupMenu popupMenu = new PopupMenu(mContext, siteVH.btnMore);
            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem menuItem) {
                    if (menuItem.getItemId() == R.id.browsing_history_menu_delete) {
                        BrowsingHistoryManager.getInstance().delete(item.getId(), HistoryItemAdapter.this);
                        TelemetryWrapper.historyRemoveLink();
                    }
                    return false;
                }
            });
            popupMenu.inflate(R.menu.menu_browsing_history_option);
            siteVH.btnMore.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    popupMenu.show();
                    TelemetryWrapper.showHistoryContextMenu();
                }
            });
        }
    } else if (holder instanceof DateItemViewHolder) {
        final DateSection item = (DateSection) mItems.get(position);
        if (item != null) {
            final DateItemViewHolder dateVH = (DateItemViewHolder) holder;
            dateVH.textDate.setText(DateUtils.getRelativeTimeSpanString(item.getTimestamp(), System.currentTimeMillis(), DateUtils.DAY_IN_MILLIS));
        }
    }
}
Also used : Site(org.mozilla.focus.history.model.Site) Bitmap(android.graphics.Bitmap) DateSection(org.mozilla.focus.history.model.DateSection) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) PopupMenu(android.support.v7.widget.PopupMenu)

Example 10 with Site

use of org.mozilla.focus.history.model.Site in project Rocket by mozilla-tw.

the class HistoryItemAdapter method add.

private void add(Object item) {
    if (mItems.size() > 0 && isSameDay(((Site) mItems.get(mItems.size() - 1)).getLastViewTimestamp(), ((Site) item).getLastViewTimestamp())) {
        mItems.add(item);
        notifyItemInserted(mItems.size());
    } else {
        mItems.add(new DateSection(((Site) item).getLastViewTimestamp()));
        mItems.add(item);
        notifyItemRangeInserted(mItems.size() - 2, 2);
    }
    ++mCurrentCount;
}
Also used : Site(org.mozilla.focus.history.model.Site) DateSection(org.mozilla.focus.history.model.DateSection)

Aggregations

Site (org.mozilla.focus.history.model.Site)12 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 JSONException (org.json.JSONException)2 DateSection (org.mozilla.focus.history.model.DateSection)2 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 PopupMenu (android.support.v7.widget.PopupMenu)1 RecyclerView (android.support.v7.widget.RecyclerView)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 SessionLoadedIdlingResource (org.mozilla.focus.helper.SessionLoadedIdlingResource)1