Bug 826261 - Robocop: Add test for Share Link option from the Firefox Mobile Menu. r=jmaher
authoradrian.tamas@softvision.ro
Fri, 04 Jan 2013 10:53:22 +0200
changeset 117603 5a20d8fd94cdbbbc9ee24cc2f28f6c282ec968e7
parent 117576 259982750c29ac150fb775c7fe18ba48d28a6c61
child 117604 9d3b1773a6938714c4e8fdc4e56217be7a1ac932
push id24110
push userphilringnalda@gmail.com
push dateSat, 05 Jan 2013 23:57:49 +0000
treeherdermozilla-central@20d1a5916ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs826261
milestone20.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
Bug 826261 - Robocop: Add test for Share Link option from the Firefox Mobile Menu. r=jmaher
mobile/android/base/tests/robocop.ini
mobile/android/base/tests/testShareLink.java.in
--- a/mobile/android/base/tests/robocop.ini
+++ b/mobile/android/base/tests/robocop.ini
@@ -22,16 +22,17 @@
 [testSearchSuggestions]
 [testTabsTrayMenu]
 # [testThumbnails] # see bug 813107
 # [testAddonManager] # see bug 817440
 [testHistory]
 [testVkbOverlap]
 [testDoorHanger]
 [testTabHistory]
+[testShareLink]
 # [testPermissions] # see bug 757475
 # [testJarReader] # see bug 738890
 
 # Used for Talos, please don't use in mochitest
 #[testPan]
 #[testCheck]
 #[testCheck2]
 #[testBrowserProviderPerf]
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/tests/testShareLink.java.in
@@ -0,0 +1,123 @@
+#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.widget.TextView;
+import android.app.Activity;
+
+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");
+        ArrayList<String> shareOptions;
+
+        blockForGeckoReady();
+
+        loadUrl(url);
+        selectMenuItem("Share");
+        mSolo.waitForText("Share Via");
+
+        // Get list of current avaliable share activities
+        shareOptions = getShareOptions();
+        verifyOptions(shareOptions);
+    }
+
+    // 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;
+    }
+
+    public void verifyOptions(ArrayList<String> shareOptions) {
+        Device device = new Device();
+        if (device.version.equals("2.x")) {
+            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());
+                               }
+                          }
+                      }
+                  }
+            }
+
+            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);
+            }
+        }
+    }
+
+    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() {
+            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;
+    }
+}