author | Adrian Tamas <adrian.tamas@softvision.ro> |
Tue, 12 Feb 2013 10:00:54 +0200 | |
changeset 122471 | fe3b9c524a1cd283475ed078577ff6d04164380b |
parent 122470 | 4fee85d29ee89725ec55a7e04cd0315b94ce4791 |
child 122472 | 979456163be10b9b6dee9c98606a9b1827617348 |
push id | 24342 |
push user | ryanvm@gmail.com |
push date | Thu, 21 Feb 2013 13:05:06 +0000 |
treeherder | mozilla-central@702d2814efbf [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | jmaher |
bugs | 841377 |
milestone | 22.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/mobile/android/base/tests/testShareLink.java.in +++ b/mobile/android/base/tests/testShareLink.java.in @@ -7,39 +7,107 @@ 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.widget.TextView; import android.app.Activity; +import android.util.DisplayMetrics; +/** + * 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 BaseTest { ListView list; String url; @Override protected int getTestType() { return TEST_MOCHITEST; } public void testShareLink() { - url = getAbsoluteUrl("/robocop/robocop_blank_01.html"); + url = getAbsoluteUrl("/robocop/robocop_big_link.html"); ArrayList<String> shareOptions; - blockForGeckoReady(); loadUrl(url); + mSolo.waitForText("Big Link"); // Waiting for page title to ensure the page is loaded selectMenuItem("Share"); mSolo.waitForText("Share Via"); - // Get list of current avaliable share activities + // Get list of current avaliable share activities and verify them shareOptions = getShareOptions(); - verifyOptions(shareOptions); + 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 found", option); + } + + // Test share from the awesomebar context menu + mActions.sendSpecialKey(Actions.SpecialKey.BACK); // Close the share menu + mSolo.clickLongOnText("Big Link"); + 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"); + mSolo.waitForText("Big Link"); + + 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 + ListView blist = getBookmarksList(); + mSolo.clickOnText("Bookmarks"); + 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 + ListView hlist = getHistoryList(); + mSolo.clickOnText("History"); + 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) { + mSolo.waitForText("Share"); + mSolo.clickOnText("Share"); + mSolo.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("Awesomebar") ? "" : " item") + " found", option); + } + mActions.sendSpecialKey(Actions.SpecialKey.BACK); } // 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); @@ -48,56 +116,43 @@ public class testShareLink extends BaseT PackageManager pm = currentActivity.getPackageManager(); List<ResolveInfo> activities = pm.queryIntentActivities(shareIntent, 0); for (ResolveInfo activity : activities) { shareOptions.add(activity.loadLabel(pm).toString()); } return shareOptions; } - public void verifyOptions(ArrayList<String> shareOptions) { - Device device = new Device(); - if (device.version.equals("2.x")) { - ArrayList<String> displayedOptions = new ArrayList(); - ListView shareMenu = getDisplayedShareList(); + 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()); - } - } + /* 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()); + } } } - } - - 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); - } + } } - else { - // For Honeycomb and newer the share options list is displayed as a menu not as a list pop-up - for (String option:shareOptions) { - mAsserter.ok(mSolo.searchText(option), "Found the option in the share menu", option); - } - } + return displayedOptions; } private boolean optionDisplayed(String shareOption, ArrayList<String> displayedOptions) { for (String displayedOption: displayedOptions) { if (shareOption.equals(displayedOption)) { return true; } }