Backout 4e7de85bedc2, ceb1e4a434a0, Adding context menus back r=wesj

This commit is contained in:
Mark Finkle 2013-11-27 14:09:38 -05:00
Родитель 18c49d8e6d
Коммит 5146ac7c05
4 изменённых файлов: 104 добавлений и 3 удалений

Просмотреть файл

@ -6,6 +6,7 @@
package org.mozilla.gecko.home;
import org.mozilla.gecko.EditBookmarkDialog;
import org.mozilla.gecko.favicons.Favicons;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoProfile;
@ -40,6 +41,9 @@ abstract class HomeFragment extends Fragment {
// Log Tag.
private static final String LOGTAG="GeckoHomeFragment";
// Share MIME type.
private static final String SHARE_MIME_TYPE = "text/plain";
// Whether the fragment can load its content or not
// This is used to defer data loading until the editing
// mode animation ends.
@ -91,6 +95,8 @@ abstract class HomeFragment extends Fragment {
menu.findItem(R.id.home_remove).setVisible(false);
}
menu.findItem(R.id.home_share).setVisible(!GeckoProfile.get(getActivity()).inGuestMode());
final boolean canOpenInReader = (info.display == Combined.DISPLAY_READER);
menu.findItem(R.id.home_open_in_reader).setVisible(canOpenInReader);
}
@ -111,6 +117,25 @@ abstract class HomeFragment extends Fragment {
final Context context = getActivity().getApplicationContext();
final int itemId = item.getItemId();
if (itemId == R.id.home_share) {
if (info.url == null) {
Log.e(LOGTAG, "Can't share because URL is null");
} else {
GeckoAppShell.openUriExternal(info.url, SHARE_MIME_TYPE, "", "",
Intent.ACTION_SEND, info.getDisplayTitle());
}
}
if (itemId == R.id.home_add_to_launcher) {
if (info.url == null) {
Log.e(LOGTAG, "Can't add to home screen because URL is null");
return false;
}
// Fetch the largest cacheable icon size.
Favicons.getLargestFaviconForPage(info.url, new GeckoAppShell.CreateShortcutFaviconLoadedListener(info.url, info.getDisplayTitle()));
return true;
}
if (itemId == R.id.home_open_private_tab || itemId == R.id.home_open_new_tab) {
if (info.url == null) {

Просмотреть файл

@ -14,10 +14,16 @@
<item android:id="@+id/home_open_in_reader"
android:title="@string/contextmenu_open_in_reader"/>
<item android:id="@+id/home_share"
android:title="@string/contextmenu_share"/>
<item android:id="@+id/home_edit_bookmark"
android:title="@string/contextmenu_edit_bookmark"/>
<item android:id="@+id/home_remove"
android:title="@string/contextmenu_remove"/>
<item android:id="@+id/home_add_to_launcher"
android:title="@string/contextmenu_add_to_launcher"/>
</menu>

Просмотреть файл

@ -43,7 +43,9 @@ class StringHelper {
"Open in New Tab",
"Open in Private Tab",
"Edit",
"Remove"
"Remove",
"Share",
"Add to Home Screen"
};
public static final String TITLE_PLACE_HOLDER = "Enter Search or Address";

Просмотреть файл

@ -21,9 +21,9 @@ import java.util.List;
/**
* This test covers the opening and content of the Share Link pop-up list
* The test opens the Share menu from the app menu, the URL bar, and a link context menu.
* The test opens the Share menu from the app menu, the URL bar, a link context menu and the Awesomescreen tabs
*/
public class testShareLink extends BaseTest {
public class testShareLink extends AboutHomeTest {
String url;
String urlTitle = "Big Link";
@ -37,6 +37,9 @@ public class testShareLink extends BaseTest {
ArrayList<String> shareOptions;
blockForGeckoReady();
// FIXME: This is a temporary hack workaround for a permissions problem.
openAboutHomeTab(AboutHomeTabs.READING_LIST);
inputAndLoadUrl(url);
verifyPageTitle(urlTitle); // Waiting for page title to ensure the page is loaded
@ -66,6 +69,71 @@ public class testShareLink extends BaseTest {
float left = mDriver.getGeckoLeft() + mDriver.getGeckoWidth() / 2;
mSolo.clickLongOnScreen(left, top);
verifySharePopup("Share Link",shareOptions,"Link");
// Test the share popup in the Bookmarks page
openAboutHomeTab(AboutHomeTabs.BOOKMARKS);
final ListView bookmarksList = findListViewWithTag("bookmarks");
mAsserter.is(waitForNonEmptyListToLoad(bookmarksList), true, "list is properly loaded");
int headerViewsCount = bookmarksList.getHeaderViewsCount();
View bookmarksItem = bookmarksList.getChildAt(headerViewsCount);
if (bookmarksItem == null) {
mAsserter.dumpLog("no child at index " + headerViewsCount + "; waiting for one...");
Condition listWaitCondition = new Condition() {
@Override
public boolean isSatisfied() {
if (bookmarksList.getChildAt(bookmarksList.getHeaderViewsCount()) == null)
return false;
return true;
}
};
waitForCondition(listWaitCondition, MAX_WAIT_MS);
headerViewsCount = bookmarksList.getHeaderViewsCount();
bookmarksItem = bookmarksList.getChildAt(headerViewsCount);
}
mSolo.clickLongOnView(bookmarksItem);
verifySharePopup(shareOptions,"bookmarks");
// Prepopulate top sites with history items to overflow tiles.
// We are trying to move away from using reflection and doing more black-box testing.
inputAndLoadUrl(getAbsoluteUrl("/robocop/robocop_blank_01.html"));
inputAndLoadUrl(getAbsoluteUrl("/robocop/robocop_blank_02.html"));
inputAndLoadUrl(getAbsoluteUrl("/robocop/robocop_blank_03.html"));
inputAndLoadUrl(getAbsoluteUrl("/robocop/robocop_blank_04.html"));
if (mDevice.type.equals("tablet")) {
// Tablets have more tile spaces to fill.
inputAndLoadUrl(getAbsoluteUrl("/robocop/robocop_blank_05.html"));
inputAndLoadUrl(getAbsoluteUrl("/robocop/robocop_boxes.html"));
inputAndLoadUrl(getAbsoluteUrl("/robocop/robocop_search.html"));
inputAndLoadUrl(getAbsoluteUrl("/robocop/robocop_text_page.html"));
}
// Test the share popup in Top Sites.
openAboutHomeTab(AboutHomeTabs.TOP_SITES);
// Scroll down a bit so that the top sites list has more items on screen.
int width = mDriver.getGeckoWidth();
int height = mDriver.getGeckoHeight();
mActions.drag(width / 2, width / 2, height - 10, height / 2);
ListView topSitesList = findListViewWithTag("top_sites");
mAsserter.is(waitForNonEmptyListToLoad(topSitesList), true, "list is properly loaded");
View mostVisitedItem = topSitesList.getChildAt(topSitesList.getHeaderViewsCount());
mSolo.clickLongOnView(mostVisitedItem);
verifySharePopup(shareOptions,"top_sites");
// Test the share popup in the Most Recent tab
openAboutHomeTab(AboutHomeTabs.MOST_RECENT);
ListView mostRecentList = findListViewWithTag("most_recent");
mAsserter.is(waitForNonEmptyListToLoad(mostRecentList), true, "list is properly loaded");
// Getting second child after header views because the first is the "Today" label
View mostRecentItem = mostRecentList.getChildAt(mostRecentList.getHeaderViewsCount() + 1);
mSolo.clickLongOnView(mostRecentItem);
verifySharePopup(shareOptions,"most recent");
}
public void verifySharePopup(ArrayList<String> shareOptions, String openedFrom) {