Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | package org.mozilla.gecko.tests; |
michael@0 | 2 | |
michael@0 | 3 | import java.util.ArrayList; |
michael@0 | 4 | import java.util.List; |
michael@0 | 5 | |
michael@0 | 6 | import org.mozilla.gecko.Actions; |
michael@0 | 7 | |
michael@0 | 8 | import android.app.Activity; |
michael@0 | 9 | import android.content.Intent; |
michael@0 | 10 | import android.content.pm.PackageManager; |
michael@0 | 11 | import android.content.pm.ResolveInfo; |
michael@0 | 12 | import android.os.Build; |
michael@0 | 13 | import android.view.View; |
michael@0 | 14 | import android.view.ViewGroup; |
michael@0 | 15 | import android.widget.AbsListView; |
michael@0 | 16 | import android.widget.GridView; |
michael@0 | 17 | import android.widget.ListView; |
michael@0 | 18 | import android.widget.TextView; |
michael@0 | 19 | |
michael@0 | 20 | import com.jayway.android.robotium.solo.Condition; |
michael@0 | 21 | |
michael@0 | 22 | /** |
michael@0 | 23 | * This test covers the opening and content of the Share Link pop-up list |
michael@0 | 24 | * The test opens the Share menu from the app menu, the URL bar, a link context menu and the Awesomescreen tabs |
michael@0 | 25 | */ |
michael@0 | 26 | public class testShareLink extends AboutHomeTest { |
michael@0 | 27 | String url; |
michael@0 | 28 | String urlTitle = "Big Link"; |
michael@0 | 29 | |
michael@0 | 30 | public void testShareLink() { |
michael@0 | 31 | url = getAbsoluteUrl("/robocop/robocop_big_link.html"); |
michael@0 | 32 | ArrayList<String> shareOptions; |
michael@0 | 33 | blockForGeckoReady(); |
michael@0 | 34 | |
michael@0 | 35 | // FIXME: This is a temporary hack workaround for a permissions problem. |
michael@0 | 36 | openAboutHomeTab(AboutHomeTabs.READING_LIST); |
michael@0 | 37 | |
michael@0 | 38 | inputAndLoadUrl(url); |
michael@0 | 39 | verifyPageTitle(urlTitle); // Waiting for page title to ensure the page is loaded |
michael@0 | 40 | |
michael@0 | 41 | selectMenuItem("Share"); |
michael@0 | 42 | if (Build.VERSION.SDK_INT >= 14) { |
michael@0 | 43 | // Check for our own sync in the submenu. |
michael@0 | 44 | waitForText("Sync$"); |
michael@0 | 45 | } else { |
michael@0 | 46 | waitForText("Share via"); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | // Get list of current avaliable share activities and verify them |
michael@0 | 50 | shareOptions = getShareOptions(); |
michael@0 | 51 | ArrayList<String> displayedOptions = getShareOptionsList(); |
michael@0 | 52 | for (String option:shareOptions) { |
michael@0 | 53 | // Verify if the option is present in the list of displayed share options |
michael@0 | 54 | mAsserter.ok(optionDisplayed(option, displayedOptions), "Share option found", option); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | // Test share from the urlbar context menu |
michael@0 | 58 | mActions.sendSpecialKey(Actions.SpecialKey.BACK); // Close the share menu |
michael@0 | 59 | mSolo.clickLongOnText(urlTitle); |
michael@0 | 60 | verifySharePopup(shareOptions,"urlbar"); |
michael@0 | 61 | |
michael@0 | 62 | // The link has a 60px height, so let's try to hit the middle |
michael@0 | 63 | float top = mDriver.getGeckoTop() + 30 * mDevice.density; |
michael@0 | 64 | float left = mDriver.getGeckoLeft() + mDriver.getGeckoWidth() / 2; |
michael@0 | 65 | mSolo.clickLongOnScreen(left, top); |
michael@0 | 66 | verifySharePopup("Share Link",shareOptions,"Link"); |
michael@0 | 67 | |
michael@0 | 68 | // Test the share popup in the Bookmarks page |
michael@0 | 69 | openAboutHomeTab(AboutHomeTabs.BOOKMARKS); |
michael@0 | 70 | |
michael@0 | 71 | final ListView bookmarksList = findListViewWithTag("bookmarks"); |
michael@0 | 72 | mAsserter.is(waitForNonEmptyListToLoad(bookmarksList), true, "list is properly loaded"); |
michael@0 | 73 | |
michael@0 | 74 | int headerViewsCount = bookmarksList.getHeaderViewsCount(); |
michael@0 | 75 | View bookmarksItem = bookmarksList.getChildAt(headerViewsCount); |
michael@0 | 76 | if (bookmarksItem == null) { |
michael@0 | 77 | mAsserter.dumpLog("no child at index " + headerViewsCount + "; waiting for one..."); |
michael@0 | 78 | Condition listWaitCondition = new Condition() { |
michael@0 | 79 | @Override |
michael@0 | 80 | public boolean isSatisfied() { |
michael@0 | 81 | if (bookmarksList.getChildAt(bookmarksList.getHeaderViewsCount()) == null) |
michael@0 | 82 | return false; |
michael@0 | 83 | return true; |
michael@0 | 84 | } |
michael@0 | 85 | }; |
michael@0 | 86 | waitForCondition(listWaitCondition, MAX_WAIT_MS); |
michael@0 | 87 | headerViewsCount = bookmarksList.getHeaderViewsCount(); |
michael@0 | 88 | bookmarksItem = bookmarksList.getChildAt(headerViewsCount); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | mSolo.clickLongOnView(bookmarksItem); |
michael@0 | 92 | verifySharePopup(shareOptions,"bookmarks"); |
michael@0 | 93 | |
michael@0 | 94 | // Prepopulate top sites with history items to overflow tiles. |
michael@0 | 95 | // We are trying to move away from using reflection and doing more black-box testing. |
michael@0 | 96 | inputAndLoadUrl(getAbsoluteUrl("/robocop/robocop_blank_01.html")); |
michael@0 | 97 | inputAndLoadUrl(getAbsoluteUrl("/robocop/robocop_blank_02.html")); |
michael@0 | 98 | inputAndLoadUrl(getAbsoluteUrl("/robocop/robocop_blank_03.html")); |
michael@0 | 99 | inputAndLoadUrl(getAbsoluteUrl("/robocop/robocop_blank_04.html")); |
michael@0 | 100 | if (mDevice.type.equals("tablet")) { |
michael@0 | 101 | // Tablets have more tile spaces to fill. |
michael@0 | 102 | inputAndLoadUrl(getAbsoluteUrl("/robocop/robocop_blank_05.html")); |
michael@0 | 103 | inputAndLoadUrl(getAbsoluteUrl("/robocop/robocop_boxes.html")); |
michael@0 | 104 | inputAndLoadUrl(getAbsoluteUrl("/robocop/robocop_search.html")); |
michael@0 | 105 | inputAndLoadUrl(getAbsoluteUrl("/robocop/robocop_text_page.html")); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | // Test the share popup in Top Sites. |
michael@0 | 109 | openAboutHomeTab(AboutHomeTabs.TOP_SITES); |
michael@0 | 110 | |
michael@0 | 111 | // Scroll down a bit so that the top sites list has more items on screen. |
michael@0 | 112 | int width = mDriver.getGeckoWidth(); |
michael@0 | 113 | int height = mDriver.getGeckoHeight(); |
michael@0 | 114 | mActions.drag(width / 2, width / 2, height - 10, height / 2); |
michael@0 | 115 | |
michael@0 | 116 | ListView topSitesList = findListViewWithTag("top_sites"); |
michael@0 | 117 | mAsserter.is(waitForNonEmptyListToLoad(topSitesList), true, "list is properly loaded"); |
michael@0 | 118 | View mostVisitedItem = topSitesList.getChildAt(topSitesList.getHeaderViewsCount()); |
michael@0 | 119 | mSolo.clickLongOnView(mostVisitedItem); |
michael@0 | 120 | verifySharePopup(shareOptions,"top_sites"); |
michael@0 | 121 | |
michael@0 | 122 | // Test the share popup in the Most Recent tab |
michael@0 | 123 | openAboutHomeTab(AboutHomeTabs.MOST_RECENT); |
michael@0 | 124 | |
michael@0 | 125 | ListView mostRecentList = findListViewWithTag("most_recent"); |
michael@0 | 126 | mAsserter.is(waitForNonEmptyListToLoad(mostRecentList), true, "list is properly loaded"); |
michael@0 | 127 | |
michael@0 | 128 | // Getting second child after header views because the first is the "Today" label |
michael@0 | 129 | View mostRecentItem = mostRecentList.getChildAt(mostRecentList.getHeaderViewsCount() + 1); |
michael@0 | 130 | mSolo.clickLongOnView(mostRecentItem); |
michael@0 | 131 | verifySharePopup(shareOptions,"most recent"); |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | public void verifySharePopup(ArrayList<String> shareOptions, String openedFrom) { |
michael@0 | 135 | verifySharePopup("Share", shareOptions, openedFrom); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | public void verifySharePopup(String shareItemText, ArrayList<String> shareOptions, String openedFrom) { |
michael@0 | 139 | waitForText(shareItemText); |
michael@0 | 140 | mSolo.clickOnText(shareItemText); |
michael@0 | 141 | waitForText("Share via"); |
michael@0 | 142 | ArrayList<String> displayedOptions = getSharePopupOption(); |
michael@0 | 143 | for (String option:shareOptions) { |
michael@0 | 144 | // Verify if the option is present in the list of displayed share options |
michael@0 | 145 | mAsserter.ok(optionDisplayed(option, displayedOptions), "Share option for " + openedFrom + (openedFrom.equals("urlbar") ? "" : " item") + " found", option); |
michael@0 | 146 | } |
michael@0 | 147 | mActions.sendSpecialKey(Actions.SpecialKey.BACK); |
michael@0 | 148 | /** |
michael@0 | 149 | * Adding a wait for the page title to make sure the Awesomebar will be dismissed |
michael@0 | 150 | * Because of Bug 712370 the Awesomescreen will be dismissed when the Share Menu is closed |
michael@0 | 151 | * so there is no need for handeling this different depending on where the share menu was invoced from |
michael@0 | 152 | * TODO: Look more into why the delay is needed here now and it was working before |
michael@0 | 153 | */ |
michael@0 | 154 | waitForText(urlTitle); |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | // Create a SEND intent and get the possible activities offered |
michael@0 | 158 | public ArrayList getShareOptions() { |
michael@0 | 159 | ArrayList<String> shareOptions = new ArrayList(); |
michael@0 | 160 | Activity currentActivity = getActivity(); |
michael@0 | 161 | final Intent shareIntent = new Intent(Intent.ACTION_SEND); |
michael@0 | 162 | shareIntent.putExtra(Intent.EXTRA_TEXT, url); |
michael@0 | 163 | shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Robocop Blank 01"); |
michael@0 | 164 | shareIntent.setType("text/plain"); |
michael@0 | 165 | PackageManager pm = currentActivity.getPackageManager(); |
michael@0 | 166 | List<ResolveInfo> activities = pm.queryIntentActivities(shareIntent, 0); |
michael@0 | 167 | for (ResolveInfo activity : activities) { |
michael@0 | 168 | shareOptions.add(activity.loadLabel(pm).toString()); |
michael@0 | 169 | } |
michael@0 | 170 | return shareOptions; |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | // Traverse the group of views, adding strings from TextViews to the list. |
michael@0 | 174 | private void getGroupTextViews(ViewGroup group, ArrayList<String> list) { |
michael@0 | 175 | for (int i = 0; i < group.getChildCount(); i++) { |
michael@0 | 176 | View child = group.getChildAt(i); |
michael@0 | 177 | if (child instanceof AbsListView) { |
michael@0 | 178 | getGroupTextViews((AbsListView)child, list); |
michael@0 | 179 | } else if (child instanceof ViewGroup) { |
michael@0 | 180 | getGroupTextViews((ViewGroup)child, list); |
michael@0 | 181 | } else if (child instanceof TextView) { |
michael@0 | 182 | String viewText = ((TextView)child).getText().toString(); |
michael@0 | 183 | if (viewText != null && viewText.length() > 0) { |
michael@0 | 184 | list.add(viewText); |
michael@0 | 185 | } |
michael@0 | 186 | } |
michael@0 | 187 | } |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | // Traverse the group of views, adding strings from TextViews to the list. |
michael@0 | 191 | // This override is for AbsListView, which has adapters. If adapters are |
michael@0 | 192 | // available, it is better to use them so that child views that are not |
michael@0 | 193 | // yet displayed can be examined. |
michael@0 | 194 | private void getGroupTextViews(AbsListView group, ArrayList<String> list) { |
michael@0 | 195 | for (int i = 0; i < group.getAdapter().getCount(); i++) { |
michael@0 | 196 | View child = group.getAdapter().getView(i, null, group); |
michael@0 | 197 | if (child instanceof AbsListView) { |
michael@0 | 198 | getGroupTextViews((AbsListView)child, list); |
michael@0 | 199 | } else if (child instanceof ViewGroup) { |
michael@0 | 200 | getGroupTextViews((ViewGroup)child, list); |
michael@0 | 201 | } else if (child instanceof TextView) { |
michael@0 | 202 | String viewText = ((TextView)child).getText().toString(); |
michael@0 | 203 | if (viewText != null && viewText.length() > 0) { |
michael@0 | 204 | list.add(viewText); |
michael@0 | 205 | } |
michael@0 | 206 | } |
michael@0 | 207 | } |
michael@0 | 208 | } |
michael@0 | 209 | |
michael@0 | 210 | public ArrayList<String> getSharePopupOption() { |
michael@0 | 211 | ArrayList<String> displayedOptions = new ArrayList(); |
michael@0 | 212 | AbsListView shareMenu = getDisplayedShareList(); |
michael@0 | 213 | getGroupTextViews(shareMenu, displayedOptions); |
michael@0 | 214 | return displayedOptions; |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | public ArrayList<String> getShareSubMenuOption() { |
michael@0 | 218 | ArrayList<String> displayedOptions = new ArrayList(); |
michael@0 | 219 | AbsListView shareMenu = getDisplayedShareList(); |
michael@0 | 220 | getGroupTextViews(shareMenu, displayedOptions); |
michael@0 | 221 | return displayedOptions; |
michael@0 | 222 | } |
michael@0 | 223 | |
michael@0 | 224 | public ArrayList<String> getShareOptionsList() { |
michael@0 | 225 | if (Build.VERSION.SDK_INT >= 14) { |
michael@0 | 226 | return getShareSubMenuOption(); |
michael@0 | 227 | } else { |
michael@0 | 228 | return getSharePopupOption(); |
michael@0 | 229 | } |
michael@0 | 230 | } |
michael@0 | 231 | |
michael@0 | 232 | private boolean optionDisplayed(String shareOption, ArrayList<String> displayedOptions) { |
michael@0 | 233 | for (String displayedOption: displayedOptions) { |
michael@0 | 234 | if (shareOption.equals(displayedOption)) { |
michael@0 | 235 | return true; |
michael@0 | 236 | } |
michael@0 | 237 | } |
michael@0 | 238 | return false; |
michael@0 | 239 | } |
michael@0 | 240 | |
michael@0 | 241 | private AbsListView mViewGroup; |
michael@0 | 242 | |
michael@0 | 243 | private AbsListView getDisplayedShareList() { |
michael@0 | 244 | mViewGroup = null; |
michael@0 | 245 | boolean success = waitForTest(new BooleanTest() { |
michael@0 | 246 | @Override |
michael@0 | 247 | public boolean test() { |
michael@0 | 248 | ArrayList<View> views = mSolo.getCurrentViews(); |
michael@0 | 249 | for (View view : views) { |
michael@0 | 250 | // List may be displayed in different view formats. |
michael@0 | 251 | // On JB, GridView is common; on ICS-, ListView is common. |
michael@0 | 252 | if (view instanceof ListView || |
michael@0 | 253 | view instanceof GridView) { |
michael@0 | 254 | mViewGroup = (AbsListView)view; |
michael@0 | 255 | return true; |
michael@0 | 256 | } |
michael@0 | 257 | } |
michael@0 | 258 | return false; |
michael@0 | 259 | } |
michael@0 | 260 | }, MAX_WAIT_MS); |
michael@0 | 261 | mAsserter.ok(success,"Got the displayed share options?", "Got the share options view"); |
michael@0 | 262 | return mViewGroup; |
michael@0 | 263 | } |
michael@0 | 264 | } |