Backout 187487847908, 890695773e56, Adding context menus back r=wesj, a=lsblakk
authorMark Finkle <mfinkle@mozilla.com>
Tue, 26 Nov 2013 14:53:53 -0500
changeset 166614 0e9f0f7a0f733347fb76f952209e8ed6bc729726
parent 166613 9cf07c05aaceec18614a7d0059abd53836afabf1
child 166615 ac60100646dd12dcd62936f5380d4dddfd0b3d3d
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj, lsblakk
milestone27.0a2
backs out187487847908e206df27bede829162428a0e112c
Backout 187487847908, 890695773e56, Adding context menus back r=wesj, a=lsblakk
mobile/android/base/home/HomeFragment.java
mobile/android/base/resources/menu/home_contextmenu.xml
mobile/android/base/tests/StringHelper.java.in
mobile/android/base/tests/testShareLink.java.in
--- a/mobile/android/base/home/HomeFragment.java
+++ b/mobile/android/base/home/HomeFragment.java
@@ -1,16 +1,17 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 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;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.ReaderModeUtils;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.db.BrowserContract.Combined;
 import org.mozilla.gecko.db.BrowserDB;
@@ -35,16 +36,19 @@ import android.widget.Toast;
 /**
  * HomeFragment is an empty fragment that can be added to the HomePager.
  * Subclasses can add their own views. 
  */
 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.
     private boolean mCanLoadHint;
 
     // Whether the fragment has loaded its content
     private boolean mIsLoaded;
 
@@ -86,16 +90,18 @@ abstract class HomeFragment extends Frag
             menu.findItem(R.id.home_edit_bookmark).setVisible(false);
         }
 
         // Hide the "Remove" menuitem if this item doesn't have a bookmark or history ID.
         if (info.bookmarkId < 0 && info.historyId < 0) {
             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);
     }
 
     @Override
     public boolean onContextItemSelected(MenuItem item) {
         // onContextItemSelected() is first dispatched to the activity and
         // then dispatched to its fragments. Since fragments cannot "override"
@@ -106,16 +112,35 @@ abstract class HomeFragment extends Frag
         if (menuInfo == null || !(menuInfo instanceof HomeContextMenuInfo)) {
             return false;
         }
 
         final HomeContextMenuInfo info = (HomeContextMenuInfo) menuInfo;
         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) {
                 Log.e(LOGTAG, "Can't open in new tab because URL is null");
                 return false;
             }
 
             int flags = Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_BACKGROUND;
--- a/mobile/android/base/resources/menu/home_contextmenu.xml
+++ b/mobile/android/base/resources/menu/home_contextmenu.xml
@@ -9,15 +9,21 @@
           android:title="@string/contextmenu_open_new_tab"/>
 
     <item android:id="@+id/home_open_private_tab"
           android:title="@string/contextmenu_open_private_tab"/>
 
     <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>
--- a/mobile/android/base/tests/StringHelper.java.in
+++ b/mobile/android/base/tests/StringHelper.java.in
@@ -35,16 +35,21 @@ class StringHelper {
     public static final String[] CONTEXT_MENU_ITEMS_IN_NORMAL_TAB = new String[] {
         "Open Link in New Tab",
         "Open Link in Private Tab", 
         "Copy Link", 
         "Share Link", 
         "Bookmark Link"
     };
 
+    public static final String[] BOOKMARKS_OPTIONS_CONTEXTMENU_ITEMS = new String[] {
+        "Edit",
+        "Add to Home Screen"
+    };
+
     public static final String TITLE_PLACE_HOLDER = "Enter Search or Address";
 
     // Robocop page urls
     // Note: please use getAbsoluteUrl(String url) on each robocop url to get the correct url
     public static final String ROBOCOP_BIG_LINK_URL = "/robocop/robocop_big_link.html";
     public static final String ROBOCOP_BIG_MAILTO_URL = "/robocop/robocop_big_mailto.html";
     public static final String ROBOCOP_BLANK_PAGE_01_URL = "/robocop/robocop_blank_01.html";
     public static final String ROBOCOP_BLANK_PAGE_02_URL = "/robocop/robocop_blank_02.html";
--- a/mobile/android/base/tests/testShareLink.java.in
+++ b/mobile/android/base/tests/testShareLink.java.in
@@ -15,32 +15,35 @@ import android.widget.AbsListView;
 import android.widget.GridView;
 import android.widget.ListView;
 import android.widget.TextView;
 import java.util.ArrayList;
 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";
 
     @Override
     protected int getTestType() {
         return TEST_MOCHITEST;
     }
 
     public void testShareLink() {
         url = getAbsoluteUrl("/robocop/robocop_big_link.html");
         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
 
         selectMenuItem("Share");
         if (Build.VERSION.SDK_INT >= 14) {
             // Check for our own sync in the submenu.
             waitForText("Sync$");
         } else {
@@ -60,16 +63,81 @@ public class testShareLink extends BaseT
         mSolo.clickLongOnText(urlTitle);
         verifySharePopup(shareOptions,"urlbar");
 
         // The link has a 60px height, so let's try to hit the middle
         float top = mDriver.getGeckoTop() + 30 * mDevice.density;
         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) {
         verifySharePopup("Share", shareOptions, openedFrom);
     }
 
     public void verifySharePopup(String shareItemText, ArrayList<String> shareOptions, String openedFrom) {
         waitForText(shareItemText);