gecko/mobile/android/base/tests/testShareLink.java

270 lines
11 KiB
Java
Raw Normal View History

Bug 905703 - Remove preprocessing from robocop harness and tests. r=nalexander --HG-- rename : build/mobile/robocop/Actions.java.in => build/mobile/robocop/Actions.java rename : build/mobile/robocop/Assert.java.in => build/mobile/robocop/Assert.java rename : build/mobile/robocop/Driver.java.in => build/mobile/robocop/Driver.java rename : build/mobile/robocop/Element.java.in => build/mobile/robocop/Element.java rename : build/mobile/robocop/FennecInstrumentationTestRunner.java.in => build/mobile/robocop/FennecInstrumentationTestRunner.java rename : build/mobile/robocop/FennecMochitestAssert.java.in => build/mobile/robocop/FennecMochitestAssert.java rename : build/mobile/robocop/FennecNativeActions.java.in => build/mobile/robocop/FennecNativeActions.java rename : build/mobile/robocop/FennecNativeDriver.java.in => build/mobile/robocop/FennecNativeDriver.java rename : build/mobile/robocop/FennecNativeElement.java.in => build/mobile/robocop/FennecNativeElement.java rename : build/mobile/robocop/FennecTalosAssert.java.in => build/mobile/robocop/FennecTalosAssert.java rename : build/mobile/robocop/PaintedSurface.java.in => build/mobile/robocop/PaintedSurface.java rename : build/mobile/robocop/RoboCopException.java.in => build/mobile/robocop/RoboCopException.java rename : build/mobile/robocop/RobocopUtils.java.in => build/mobile/robocop/RobocopUtils.java rename : mobile/android/base/tests/AboutHomeTest.java.in => mobile/android/base/tests/AboutHomeTest.java rename : mobile/android/base/tests/BaseTest.java.in => mobile/android/base/tests/BaseTest.java rename : mobile/android/base/tests/ContentContextMenuTest.java.in => mobile/android/base/tests/ContentContextMenuTest.java rename : mobile/android/base/tests/ContentProviderTest.java.in => mobile/android/base/tests/ContentProviderTest.java rename : mobile/android/base/tests/DatabaseHelper.java.in => mobile/android/base/tests/DatabaseHelper.java rename : mobile/android/base/tests/JavascriptTest.java.in => mobile/android/base/tests/JavascriptTest.java rename : mobile/android/base/tests/MotionEventHelper.java.in => mobile/android/base/tests/MotionEventHelper.java rename : mobile/android/base/tests/MotionEventReplayer.java.in => mobile/android/base/tests/MotionEventReplayer.java rename : mobile/android/base/tests/PixelTest.java.in => mobile/android/base/tests/PixelTest.java rename : mobile/android/base/tests/StringHelper.java.in => mobile/android/base/tests/StringHelper.java rename : mobile/android/base/tests/testAboutPage.java.in => mobile/android/base/tests/testAboutPage.java rename : mobile/android/base/tests/testAddSearchEngine.java.in => mobile/android/base/tests/testAddSearchEngine.java rename : mobile/android/base/tests/testAddonManager.java.in => mobile/android/base/tests/testAddonManager.java rename : mobile/android/base/tests/testAwesomebar.java.in => mobile/android/base/tests/testAwesomebar.java rename : mobile/android/base/tests/testAwesomebarSwipes.java.in => mobile/android/base/tests/testAwesomebarSwipes.java rename : mobile/android/base/tests/testAxisLocking.java.in => mobile/android/base/tests/testAxisLocking.java rename : mobile/android/base/tests/testBookmark.java.in => mobile/android/base/tests/testBookmark.java rename : mobile/android/base/tests/testBookmarkFolders.java.in => mobile/android/base/tests/testBookmarkFolders.java rename : mobile/android/base/tests/testBookmarkKeyword.java.in => mobile/android/base/tests/testBookmarkKeyword.java rename : mobile/android/base/tests/testBookmarklets.java.in => mobile/android/base/tests/testBookmarklets.java rename : mobile/android/base/tests/testBookmarksPage.java.in => mobile/android/base/tests/testBookmarksPage.java rename : mobile/android/base/tests/testBrowserProvider.java.in => mobile/android/base/tests/testBrowserProvider.java rename : mobile/android/base/tests/testBrowserProviderPerf.java.in => mobile/android/base/tests/testBrowserProviderPerf.java rename : mobile/android/base/tests/testBrowserSearchVisibility.java.in => mobile/android/base/tests/testBrowserSearchVisibility.java rename : mobile/android/base/tests/testCheck.java.in => mobile/android/base/tests/testCheck.java rename : mobile/android/base/tests/testCheck2.java.in => mobile/android/base/tests/testCheck2.java rename : mobile/android/base/tests/testClearPrivateData.java.in => mobile/android/base/tests/testClearPrivateData.java rename : mobile/android/base/tests/testDeviceSearchEngine.java.in => mobile/android/base/tests/testDeviceSearchEngine.java rename : mobile/android/base/tests/testDistribution.java.in => mobile/android/base/tests/testDistribution.java rename : mobile/android/base/tests/testDoorHanger.java.in => mobile/android/base/tests/testDoorHanger.java rename : mobile/android/base/tests/testFindInPage.java.in => mobile/android/base/tests/testFindInPage.java rename : mobile/android/base/tests/testFlingCorrectness.java.in => mobile/android/base/tests/testFlingCorrectness.java rename : mobile/android/base/tests/testFormHistory.java.in => mobile/android/base/tests/testFormHistory.java rename : mobile/android/base/tests/testGetUserMedia.java.in => mobile/android/base/tests/testGetUserMedia.java rename : mobile/android/base/tests/testHistory.java.in => mobile/android/base/tests/testHistory.java rename : mobile/android/base/tests/testHomeBanner.java.in => mobile/android/base/tests/testHomeBanner.java rename : mobile/android/base/tests/testImportFromAndroid.java.in => mobile/android/base/tests/testImportFromAndroid.java rename : mobile/android/base/tests/testInputUrlBar.java.in => mobile/android/base/tests/testInputUrlBar.java rename : mobile/android/base/tests/testJNI.java.in => mobile/android/base/tests/testJNI.java rename : mobile/android/base/tests/testJarReader.java.in => mobile/android/base/tests/testJarReader.java rename : mobile/android/base/tests/testLinkContextMenu.java.in => mobile/android/base/tests/testLinkContextMenu.java rename : mobile/android/base/tests/testLoad.java.in => mobile/android/base/tests/testLoad.java rename : mobile/android/base/tests/testMailToContextMenu.java.in => mobile/android/base/tests/testMailToContextMenu.java rename : mobile/android/base/tests/testMasterPassword.java.in => mobile/android/base/tests/testMasterPassword.java rename : mobile/android/base/tests/testNewTab.java.in => mobile/android/base/tests/testNewTab.java rename : mobile/android/base/tests/testOrderedBroadcast.java.in => mobile/android/base/tests/testOrderedBroadcast.java rename : mobile/android/base/tests/testOverscroll.java.in => mobile/android/base/tests/testOverscroll.java rename : mobile/android/base/tests/testPan.java.in => mobile/android/base/tests/testPan.java rename : mobile/android/base/tests/testPanCorrectness.java.in => mobile/android/base/tests/testPanCorrectness.java rename : mobile/android/base/tests/testPasswordEncrypt.java.in => mobile/android/base/tests/testPasswordEncrypt.java rename : mobile/android/base/tests/testPasswordProvider.java.in => mobile/android/base/tests/testPasswordProvider.java rename : mobile/android/base/tests/testPermissions.java.in => mobile/android/base/tests/testPermissions.java rename : mobile/android/base/tests/testPictureLinkContextMenu.java.in => mobile/android/base/tests/testPictureLinkContextMenu.java rename : mobile/android/base/tests/testPrefsObserver.java.in => mobile/android/base/tests/testPrefsObserver.java rename : mobile/android/base/tests/testPrivateBrowsing.java.in => mobile/android/base/tests/testPrivateBrowsing.java rename : mobile/android/base/tests/testPromptGridInput.java.in => mobile/android/base/tests/testPromptGridInput.java rename : mobile/android/base/tests/testReaderMode.java.in => mobile/android/base/tests/testReaderMode.java rename : mobile/android/base/tests/testSearchSuggestions.java.in => mobile/android/base/tests/testSearchSuggestions.java rename : mobile/android/base/tests/testSettingsMenuItems.java.in => mobile/android/base/tests/testSettingsMenuItems.java rename : mobile/android/base/tests/testShareLink.java.in => mobile/android/base/tests/testShareLink.java rename : mobile/android/base/tests/testSharedPreferences.java.in => mobile/android/base/tests/testSharedPreferences.java rename : mobile/android/base/tests/testSystemPages.java.in => mobile/android/base/tests/testSystemPages.java rename : mobile/android/base/tests/testTabHistory.java.in => mobile/android/base/tests/testTabHistory.java rename : mobile/android/base/tests/testThumbnails.java.in => mobile/android/base/tests/testThumbnails.java rename : mobile/android/base/tests/testVkbOverlap.java.in => mobile/android/base/tests/testVkbOverlap.java rename : mobile/android/base/tests/test_bug720538.java.in => mobile/android/base/tests/test_bug720538.java extra : rebase_source : c8d715aa110b07c6010054a674879e143a5f04e7 extra : amend_source : fb5714b78e055e336b5e0c6a0da8eb8c931ff09e extra : histedit_source : ec57d8ba94000092438a2ba0bf4fb66091e98513%2C114ade72bb9b72b96557da74f1179734fa347e5c
2013-11-07 08:18:51 -08:00
package org.mozilla.gecko.tests;
import org.mozilla.gecko.*;
import com.jayway.android.robotium.solo.Condition;
Bug 905703 - Remove preprocessing from robocop harness and tests. r=nalexander --HG-- rename : build/mobile/robocop/Actions.java.in => build/mobile/robocop/Actions.java rename : build/mobile/robocop/Assert.java.in => build/mobile/robocop/Assert.java rename : build/mobile/robocop/Driver.java.in => build/mobile/robocop/Driver.java rename : build/mobile/robocop/Element.java.in => build/mobile/robocop/Element.java rename : build/mobile/robocop/FennecInstrumentationTestRunner.java.in => build/mobile/robocop/FennecInstrumentationTestRunner.java rename : build/mobile/robocop/FennecMochitestAssert.java.in => build/mobile/robocop/FennecMochitestAssert.java rename : build/mobile/robocop/FennecNativeActions.java.in => build/mobile/robocop/FennecNativeActions.java rename : build/mobile/robocop/FennecNativeDriver.java.in => build/mobile/robocop/FennecNativeDriver.java rename : build/mobile/robocop/FennecNativeElement.java.in => build/mobile/robocop/FennecNativeElement.java rename : build/mobile/robocop/FennecTalosAssert.java.in => build/mobile/robocop/FennecTalosAssert.java rename : build/mobile/robocop/PaintedSurface.java.in => build/mobile/robocop/PaintedSurface.java rename : build/mobile/robocop/RoboCopException.java.in => build/mobile/robocop/RoboCopException.java rename : build/mobile/robocop/RobocopUtils.java.in => build/mobile/robocop/RobocopUtils.java rename : mobile/android/base/tests/AboutHomeTest.java.in => mobile/android/base/tests/AboutHomeTest.java rename : mobile/android/base/tests/BaseTest.java.in => mobile/android/base/tests/BaseTest.java rename : mobile/android/base/tests/ContentContextMenuTest.java.in => mobile/android/base/tests/ContentContextMenuTest.java rename : mobile/android/base/tests/ContentProviderTest.java.in => mobile/android/base/tests/ContentProviderTest.java rename : mobile/android/base/tests/DatabaseHelper.java.in => mobile/android/base/tests/DatabaseHelper.java rename : mobile/android/base/tests/JavascriptTest.java.in => mobile/android/base/tests/JavascriptTest.java rename : mobile/android/base/tests/MotionEventHelper.java.in => mobile/android/base/tests/MotionEventHelper.java rename : mobile/android/base/tests/MotionEventReplayer.java.in => mobile/android/base/tests/MotionEventReplayer.java rename : mobile/android/base/tests/PixelTest.java.in => mobile/android/base/tests/PixelTest.java rename : mobile/android/base/tests/StringHelper.java.in => mobile/android/base/tests/StringHelper.java rename : mobile/android/base/tests/testAboutPage.java.in => mobile/android/base/tests/testAboutPage.java rename : mobile/android/base/tests/testAddSearchEngine.java.in => mobile/android/base/tests/testAddSearchEngine.java rename : mobile/android/base/tests/testAddonManager.java.in => mobile/android/base/tests/testAddonManager.java rename : mobile/android/base/tests/testAwesomebar.java.in => mobile/android/base/tests/testAwesomebar.java rename : mobile/android/base/tests/testAwesomebarSwipes.java.in => mobile/android/base/tests/testAwesomebarSwipes.java rename : mobile/android/base/tests/testAxisLocking.java.in => mobile/android/base/tests/testAxisLocking.java rename : mobile/android/base/tests/testBookmark.java.in => mobile/android/base/tests/testBookmark.java rename : mobile/android/base/tests/testBookmarkFolders.java.in => mobile/android/base/tests/testBookmarkFolders.java rename : mobile/android/base/tests/testBookmarkKeyword.java.in => mobile/android/base/tests/testBookmarkKeyword.java rename : mobile/android/base/tests/testBookmarklets.java.in => mobile/android/base/tests/testBookmarklets.java rename : mobile/android/base/tests/testBookmarksPage.java.in => mobile/android/base/tests/testBookmarksPage.java rename : mobile/android/base/tests/testBrowserProvider.java.in => mobile/android/base/tests/testBrowserProvider.java rename : mobile/android/base/tests/testBrowserProviderPerf.java.in => mobile/android/base/tests/testBrowserProviderPerf.java rename : mobile/android/base/tests/testBrowserSearchVisibility.java.in => mobile/android/base/tests/testBrowserSearchVisibility.java rename : mobile/android/base/tests/testCheck.java.in => mobile/android/base/tests/testCheck.java rename : mobile/android/base/tests/testCheck2.java.in => mobile/android/base/tests/testCheck2.java rename : mobile/android/base/tests/testClearPrivateData.java.in => mobile/android/base/tests/testClearPrivateData.java rename : mobile/android/base/tests/testDeviceSearchEngine.java.in => mobile/android/base/tests/testDeviceSearchEngine.java rename : mobile/android/base/tests/testDistribution.java.in => mobile/android/base/tests/testDistribution.java rename : mobile/android/base/tests/testDoorHanger.java.in => mobile/android/base/tests/testDoorHanger.java rename : mobile/android/base/tests/testFindInPage.java.in => mobile/android/base/tests/testFindInPage.java rename : mobile/android/base/tests/testFlingCorrectness.java.in => mobile/android/base/tests/testFlingCorrectness.java rename : mobile/android/base/tests/testFormHistory.java.in => mobile/android/base/tests/testFormHistory.java rename : mobile/android/base/tests/testGetUserMedia.java.in => mobile/android/base/tests/testGetUserMedia.java rename : mobile/android/base/tests/testHistory.java.in => mobile/android/base/tests/testHistory.java rename : mobile/android/base/tests/testHomeBanner.java.in => mobile/android/base/tests/testHomeBanner.java rename : mobile/android/base/tests/testImportFromAndroid.java.in => mobile/android/base/tests/testImportFromAndroid.java rename : mobile/android/base/tests/testInputUrlBar.java.in => mobile/android/base/tests/testInputUrlBar.java rename : mobile/android/base/tests/testJNI.java.in => mobile/android/base/tests/testJNI.java rename : mobile/android/base/tests/testJarReader.java.in => mobile/android/base/tests/testJarReader.java rename : mobile/android/base/tests/testLinkContextMenu.java.in => mobile/android/base/tests/testLinkContextMenu.java rename : mobile/android/base/tests/testLoad.java.in => mobile/android/base/tests/testLoad.java rename : mobile/android/base/tests/testMailToContextMenu.java.in => mobile/android/base/tests/testMailToContextMenu.java rename : mobile/android/base/tests/testMasterPassword.java.in => mobile/android/base/tests/testMasterPassword.java rename : mobile/android/base/tests/testNewTab.java.in => mobile/android/base/tests/testNewTab.java rename : mobile/android/base/tests/testOrderedBroadcast.java.in => mobile/android/base/tests/testOrderedBroadcast.java rename : mobile/android/base/tests/testOverscroll.java.in => mobile/android/base/tests/testOverscroll.java rename : mobile/android/base/tests/testPan.java.in => mobile/android/base/tests/testPan.java rename : mobile/android/base/tests/testPanCorrectness.java.in => mobile/android/base/tests/testPanCorrectness.java rename : mobile/android/base/tests/testPasswordEncrypt.java.in => mobile/android/base/tests/testPasswordEncrypt.java rename : mobile/android/base/tests/testPasswordProvider.java.in => mobile/android/base/tests/testPasswordProvider.java rename : mobile/android/base/tests/testPermissions.java.in => mobile/android/base/tests/testPermissions.java rename : mobile/android/base/tests/testPictureLinkContextMenu.java.in => mobile/android/base/tests/testPictureLinkContextMenu.java rename : mobile/android/base/tests/testPrefsObserver.java.in => mobile/android/base/tests/testPrefsObserver.java rename : mobile/android/base/tests/testPrivateBrowsing.java.in => mobile/android/base/tests/testPrivateBrowsing.java rename : mobile/android/base/tests/testPromptGridInput.java.in => mobile/android/base/tests/testPromptGridInput.java rename : mobile/android/base/tests/testReaderMode.java.in => mobile/android/base/tests/testReaderMode.java rename : mobile/android/base/tests/testSearchSuggestions.java.in => mobile/android/base/tests/testSearchSuggestions.java rename : mobile/android/base/tests/testSettingsMenuItems.java.in => mobile/android/base/tests/testSettingsMenuItems.java rename : mobile/android/base/tests/testShareLink.java.in => mobile/android/base/tests/testShareLink.java rename : mobile/android/base/tests/testSharedPreferences.java.in => mobile/android/base/tests/testSharedPreferences.java rename : mobile/android/base/tests/testSystemPages.java.in => mobile/android/base/tests/testSystemPages.java rename : mobile/android/base/tests/testTabHistory.java.in => mobile/android/base/tests/testTabHistory.java rename : mobile/android/base/tests/testThumbnails.java.in => mobile/android/base/tests/testThumbnails.java rename : mobile/android/base/tests/testVkbOverlap.java.in => mobile/android/base/tests/testVkbOverlap.java rename : mobile/android/base/tests/test_bug720538.java.in => mobile/android/base/tests/test_bug720538.java extra : rebase_source : c8d715aa110b07c6010054a674879e143a5f04e7 extra : amend_source : fb5714b78e055e336b5e0c6a0da8eb8c931ff09e extra : histedit_source : ec57d8ba94000092438a2ba0bf4fb66091e98513%2C114ade72bb9b72b96557da74f1179734fa347e5c
2013-11-07 08:18:51 -08:00
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
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, a link context menu and the Awesomescreen tabs
*/
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 {
waitForText("Share via");
}
// Get list of current avaliable share activities and verify them
shareOptions = getShareOptions();
ArrayList<String> displayedOptions = getShareOptionsList();
for (String option:shareOptions) {
// Verify if the option is present in the list of displayed share options
mAsserter.ok(optionDisplayed(option, displayedOptions), "Share option found", option);
}
// Test share from the urlbar context menu
mActions.sendSpecialKey(Actions.SpecialKey.BACK); // Close the share menu
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);
mSolo.clickOnText(shareItemText);
waitForText("Share via");
ArrayList<String> displayedOptions = getSharePopupOption();
for (String option:shareOptions) {
// Verify if the option is present in the list of displayed share options
mAsserter.ok(optionDisplayed(option, displayedOptions), "Share option for " + openedFrom + (openedFrom.equals("urlbar") ? "" : " item") + " found", option);
}
mActions.sendSpecialKey(Actions.SpecialKey.BACK);
/**
* Adding a wait for the page title to make sure the Awesomebar will be dismissed
* Because of Bug 712370 the Awesomescreen will be dismissed when the Share Menu is closed
* so there is no need for handeling this different depending on where the share menu was invoced from
* TODO: Look more into why the delay is needed here now and it was working before
*/
waitForText(urlTitle);
}
// Create a SEND intent and get the possible activities offered
public ArrayList getShareOptions() {
ArrayList<String> shareOptions = new ArrayList();
Activity currentActivity = getActivity();
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, url);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Robocop Blank 01");
shareIntent.setType("text/plain");
PackageManager pm = currentActivity.getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(shareIntent, 0);
for (ResolveInfo activity : activities) {
shareOptions.add(activity.loadLabel(pm).toString());
}
return shareOptions;
}
// Traverse the group of views, adding strings from TextViews to the list.
private void getGroupTextViews(ViewGroup group, ArrayList<String> list) {
for (int i = 0; i < group.getChildCount(); i++) {
View child = group.getChildAt(i);
if (child instanceof AbsListView) {
getGroupTextViews((AbsListView)child, list);
} else if (child instanceof ViewGroup) {
getGroupTextViews((ViewGroup)child, list);
} else if (child instanceof TextView) {
String viewText = ((TextView)child).getText().toString();
if (viewText != null && viewText.length() > 0) {
list.add(viewText);
}
}
}
}
// Traverse the group of views, adding strings from TextViews to the list.
// This override is for AbsListView, which has adapters. If adapters are
// available, it is better to use them so that child views that are not
// yet displayed can be examined.
private void getGroupTextViews(AbsListView group, ArrayList<String> list) {
for (int i = 0; i < group.getAdapter().getCount(); i++) {
View child = group.getAdapter().getView(i, null, group);
if (child instanceof AbsListView) {
getGroupTextViews((AbsListView)child, list);
} else if (child instanceof ViewGroup) {
getGroupTextViews((ViewGroup)child, list);
} else if (child instanceof TextView) {
String viewText = ((TextView)child).getText().toString();
if (viewText != null && viewText.length() > 0) {
list.add(viewText);
}
}
}
}
public ArrayList<String> getSharePopupOption() {
ArrayList<String> displayedOptions = new ArrayList();
AbsListView shareMenu = getDisplayedShareList();
getGroupTextViews(shareMenu, displayedOptions);
return displayedOptions;
}
public ArrayList<String> getShareSubMenuOption() {
ArrayList<String> displayedOptions = new ArrayList();
AbsListView shareMenu = getDisplayedShareList();
getGroupTextViews(shareMenu, displayedOptions);
return displayedOptions;
}
public ArrayList<String> getShareOptionsList() {
if (Build.VERSION.SDK_INT >= 14) {
return getShareSubMenuOption();
} else {
return getSharePopupOption();
}
}
private boolean optionDisplayed(String shareOption, ArrayList<String> displayedOptions) {
for (String displayedOption: displayedOptions) {
if (shareOption.equals(displayedOption)) {
return true;
}
}
return false;
}
private AbsListView mViewGroup;
private AbsListView getDisplayedShareList() {
mViewGroup = null;
boolean success = waitForTest(new BooleanTest() {
@Override
public boolean test() {
ArrayList<View> views = mSolo.getCurrentViews();
for (View view : views) {
// List may be displayed in different view formats.
// On JB, GridView is common; on ICS-, ListView is common.
if (view instanceof ListView ||
view instanceof GridView) {
mViewGroup = (AbsListView)view;
return true;
}
}
return false;
}
}, MAX_WAIT_MS);
mAsserter.ok(success,"Got the displayed share options?", "Got the share options view");
return mViewGroup;
}
}