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);
}
}
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()))))));
}
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())))));
}
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));
}
}
}
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;
}
Aggregations