2013-01-04 00:53:22 -08:00
|
|
|
#filter substitution
|
|
|
|
package @ANDROID_PACKAGE_NAME@.tests;
|
|
|
|
|
|
|
|
import @ANDROID_PACKAGE_NAME@.*;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.pm.ResolveInfo;
|
|
|
|
import android.widget.ListView;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import android.app.Activity;
|
2013-05-29 16:06:41 -07:00
|
|
|
import android.os.Build;
|
2013-02-12 00:00:54 -08:00
|
|
|
import android.util.DisplayMetrics;
|
2013-01-04 00:53:22 -08:00
|
|
|
|
2013-02-12 00:00:54 -08:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2013-01-04 00:53:22 -08:00
|
|
|
public class testShareLink extends BaseTest {
|
|
|
|
ListView list;
|
|
|
|
String url;
|
2013-07-11 02:30:10 -07:00
|
|
|
String urlTitle = "Big Link";
|
2013-01-04 00:53:22 -08:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected int getTestType() {
|
|
|
|
return TEST_MOCHITEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testShareLink() {
|
2013-02-12 00:00:54 -08:00
|
|
|
url = getAbsoluteUrl("/robocop/robocop_big_link.html");
|
2013-01-04 00:53:22 -08:00
|
|
|
ArrayList<String> shareOptions;
|
|
|
|
blockForGeckoReady();
|
|
|
|
|
|
|
|
loadUrl(url);
|
2013-07-11 02:30:10 -07:00
|
|
|
waitForText(urlTitle); // Waiting for page title to ensure the page is loaded
|
2013-01-04 00:53:22 -08:00
|
|
|
selectMenuItem("Share");
|
2013-05-29 16:06:41 -07:00
|
|
|
if (Build.VERSION.SDK_INT >= 14) {
|
|
|
|
// Check for our own sync in the submenu.
|
|
|
|
waitForText("Sync$");
|
|
|
|
} else {
|
|
|
|
waitForText("Share via");
|
|
|
|
}
|
2013-01-04 00:53:22 -08:00
|
|
|
|
2013-02-12 00:00:54 -08:00
|
|
|
// Get list of current avaliable share activities and verify them
|
2013-01-04 00:53:22 -08:00
|
|
|
shareOptions = getShareOptions();
|
2013-05-29 16:06:41 -07:00
|
|
|
ArrayList<String> displayedOptions = getShareOptionsList();
|
2013-02-12 00:00:54 -08:00
|
|
|
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 awesomebar context menu
|
|
|
|
mActions.sendSpecialKey(Actions.SpecialKey.BACK); // Close the share menu
|
2013-07-11 02:30:10 -07:00
|
|
|
mSolo.clickLongOnText(urlTitle);
|
2013-02-12 00:00:54 -08:00
|
|
|
verifySharePopup(shareOptions,"Awesomebar");
|
|
|
|
|
|
|
|
// Test link Context Menu
|
|
|
|
DisplayMetrics dm = new DisplayMetrics();
|
|
|
|
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
|
|
|
|
|
|
|
|
// The link has a 60px height, so let's try to hit the middle
|
|
|
|
float top = mDriver.getGeckoTop() + 30 * dm.density;
|
|
|
|
float left = mDriver.getGeckoLeft() + mDriver.getGeckoWidth() / 2;
|
|
|
|
mSolo.clickLongOnScreen(left, top);
|
|
|
|
verifySharePopup(shareOptions,"Link");
|
|
|
|
|
|
|
|
// Test share popup in Top Sites
|
|
|
|
ListView tslist = getAllPagesList(url);
|
|
|
|
|
|
|
|
// Make sure the keyboard is closed since a back here would just close the Awesomebar
|
|
|
|
mSolo.clickOnText("Bookmarks");
|
|
|
|
mSolo.clickOnText("Sites");
|
2013-02-27 07:21:24 -08:00
|
|
|
waitForText("Big Link");
|
2013-02-12 00:00:54 -08:00
|
|
|
|
|
|
|
View allpages = tslist.getChildAt(1);
|
|
|
|
if (allpages != null) {
|
|
|
|
mSolo.clickLongOnView(allpages);
|
|
|
|
verifySharePopup(shareOptions,"Top Sites");
|
|
|
|
} else {
|
|
|
|
// The view should not be null but sometimes getChildAt fails
|
|
|
|
// TODO: Investigate why this fails
|
|
|
|
mAsserter.todo_isnot(allpages, null, "View should not be null but sometimes it is");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test the share popup in the Bookmarks tab
|
2013-03-01 16:02:52 -08:00
|
|
|
ListView blist = getBookmarksList("about:firefox");
|
2013-02-12 00:00:54 -08:00
|
|
|
View bookmark = blist.getChildAt(1); // Getting child at 1 because 0 might be the Desktop folder
|
|
|
|
mSolo.clickLongOnView(bookmark);
|
|
|
|
verifySharePopup(shareOptions,"bookmarks");
|
|
|
|
|
|
|
|
// Test the share popup in the History tab
|
2013-03-01 16:02:52 -08:00
|
|
|
ListView hlist = getHistoryList("Today|Yesterday");
|
2013-02-12 00:00:54 -08:00
|
|
|
View history = hlist.getChildAt(1); // Getting child at 1 because 0 might be the "Today" label
|
|
|
|
mSolo.clickLongOnView(history);
|
|
|
|
verifySharePopup(shareOptions,"history");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void verifySharePopup(ArrayList<String> shareOptions, String openedFrom) {
|
2013-02-27 07:21:24 -08:00
|
|
|
waitForText("Share");
|
2013-02-12 00:00:54 -08:00
|
|
|
mSolo.clickOnText("Share");
|
2013-03-01 17:41:05 -08:00
|
|
|
waitForText("Share via");
|
2013-02-12 00:00:54 -08:00
|
|
|
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("Awesomebar") ? "" : " item") + " found", option);
|
|
|
|
}
|
|
|
|
mActions.sendSpecialKey(Actions.SpecialKey.BACK);
|
2013-07-11 02:30:10 -07:00
|
|
|
/**
|
|
|
|
* 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);
|
2013-01-04 00:53:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2013-02-12 00:00:54 -08:00
|
|
|
public ArrayList<String> getSharePopupOption() {
|
|
|
|
ArrayList<String> displayedOptions = new ArrayList();
|
|
|
|
ListView shareMenu = getDisplayedShareList();
|
|
|
|
|
|
|
|
/* Will have to go in the ListView, get each child, for the child separate the icon and the label
|
|
|
|
and from the label get the label text in a String Array */
|
|
|
|
for (int i = 0; i < shareMenu.getAdapter().getCount();i++) {
|
|
|
|
View shareItem = shareMenu.getAdapter().getView(i, null, null);
|
|
|
|
ViewGroup shareItemEntry = (ViewGroup)shareItem;
|
|
|
|
for (int j = 0; j < shareItemEntry.getChildCount(); j++) {
|
|
|
|
View shareItemLabel = shareItemEntry.getChildAt(j);
|
|
|
|
if (shareItemLabel instanceof android.widget.LinearLayout) {
|
|
|
|
// The Item label is a LinearLayout of LinearLayouts
|
|
|
|
ViewGroup itemLabel = (ViewGroup)shareItemLabel;
|
|
|
|
for (int k = 0; k < itemLabel.getChildCount(); k++) {
|
|
|
|
View shareItemName = itemLabel.getChildAt(k);
|
|
|
|
if (shareItemName instanceof android.widget.TextView) {
|
|
|
|
/* The displayedOptions list array will also contain other elements that make up the
|
|
|
|
share item label but we will check the option to be present here so there is no need
|
|
|
|
at the moment to try and clean this array up further */
|
|
|
|
displayedOptions.add(((android.widget.TextView)shareItemName).getText().toString());
|
|
|
|
}
|
2013-01-04 00:53:22 -08:00
|
|
|
}
|
|
|
|
}
|
2013-02-12 00:00:54 -08:00
|
|
|
}
|
2013-01-04 00:53:22 -08:00
|
|
|
}
|
2013-02-12 00:00:54 -08:00
|
|
|
return displayedOptions;
|
2013-01-04 00:53:22 -08:00
|
|
|
}
|
|
|
|
|
2013-05-29 16:06:41 -07:00
|
|
|
public ArrayList<String> getShareSubMenuOption() {
|
|
|
|
ArrayList<String> displayedOptions = new ArrayList();
|
|
|
|
ListView shareMenu = getDisplayedShareList();
|
|
|
|
for (int i = 0; i < shareMenu.getAdapter().getCount();i++) {
|
2013-06-07 10:50:43 -07:00
|
|
|
View shareItem = shareMenu.getAdapter().getView(i, null, shareMenu);
|
2013-05-29 16:06:41 -07:00
|
|
|
if (shareItem instanceof android.widget.TextView) {
|
|
|
|
displayedOptions.add(((android.widget.TextView)shareItem).getText().toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return displayedOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ArrayList<String> getShareOptionsList() {
|
|
|
|
if (Build.VERSION.SDK_INT >= 14) {
|
|
|
|
return getShareSubMenuOption();
|
|
|
|
} else {
|
|
|
|
return getSharePopupOption();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-04 00:53:22 -08:00
|
|
|
private boolean optionDisplayed(String shareOption, ArrayList<String> displayedOptions) {
|
|
|
|
for (String displayedOption: displayedOptions) {
|
|
|
|
if (shareOption.equals(displayedOption)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ListView getDisplayedShareList() {
|
|
|
|
final ArrayList<ListView> views = mSolo.getCurrentListViews();
|
|
|
|
|
|
|
|
list = null;
|
|
|
|
boolean success = waitForTest(new BooleanTest() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2013-01-04 00:53:22 -08:00
|
|
|
public boolean test() {
|
|
|
|
for (ListView view : views) {
|
|
|
|
list = view;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}, MAX_WAIT_MS);
|
|
|
|
mAsserter.ok(success,"Got the displayed share options?", "Got the share options list");
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
}
|