Bug 1116415 - 7. Update BaseTest for the new tabs panel class heirarchy. draft
authorTom Klein <twointofive@gmail.com>
Mon, 12 Sep 2016 10:54:46 -0500
changeset 418598 3cf80d428847b8f5d6fd507caa2c41b130eda237
parent 418597 331217104d35c969192d22c0660ac40125711503
child 418599 4bcb00cb8673ab141b50d990fd48e698d139a7d0
push id30721
push userbmo:twointofive@gmail.com
push dateWed, 28 Sep 2016 19:14:00 +0000
bugs1116415
milestone52.0a1
Bug 1116415 - 7. Update BaseTest for the new tabs panel class heirarchy. MozReview-Commit-ID: 7YcpakQnpI
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/BaseTest.java
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/BaseTest.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/BaseTest.java
@@ -608,91 +608,54 @@ abstract class BaseTest extends BaseRobo
     }
 
     public void closeAddedTabs() {
         for(int tabID : mKnownTabIDs) {
             closeTab(tabID);
         }
     }
 
-    // A temporary tabs list/grid holder while the list and grid views are being transitioned to
-    // RecyclerViews.
-    private static class TabsView {
-        private AdapterView<ListAdapter> gridView;
-        private RecyclerView listView;
-
-        public TabsView(View view) {
-            if (view instanceof RecyclerView) {
-                listView = (RecyclerView) view;
-            } else {
-                gridView = (AdapterView<ListAdapter>) view;
-            }
-        }
-
-        public void bringPositionIntoView(int index) {
-            if (gridView != null) {
-                gridView.setSelection(index);
-            } else {
-                listView.scrollToPosition(index);
-            }
-        }
-
-        public View getViewAtIndex(int index) {
-            if (gridView != null) {
-                return gridView.getChildAt(index - gridView.getFirstVisiblePosition());
-            } else {
-                final RecyclerView.ViewHolder itemViewHolder = listView.findViewHolderForLayoutPosition(index);
-                return itemViewHolder == null ? null : itemViewHolder.itemView;
-            }
-        }
-
-        public void post(Runnable runnable) {
-            if (gridView != null) {
-                gridView.post(runnable);
-            } else {
-                listView.post(runnable);
-            }
-        }
-    }
     /**
-     * Gets the AdapterView of the tabs list.
+     * Gets the RecyclerView of the tabs list.
      *
      * @return List view in the tabs panel
      */
-    private final TabsView getTabsLayout() {
+    private final RecyclerView getTabsLayout() {
         Element tabs = mDriver.findElement(getActivity(), R.id.tabs);
         tabs.click();
-        return new TabsView(getActivity().findViewById(R.id.normal_tabs));
+        return (RecyclerView) getActivity().findViewById(R.id.normal_tabs);
     }
 
     /**
      * Gets the view in the tabs panel at the specified index.
      *
      * @return View at index
      */
     private View getTabViewAt(final int index) {
         final View[] childView = { null };
 
-        final TabsView view = getTabsLayout();
+        final RecyclerView view = getTabsLayout();
 
         runOnUiThreadSync(new Runnable() {
             @Override
             public void run() {
-                view.bringPositionIntoView(index);
+                view.scrollToPosition(index);
 
                 // The selection isn't updated synchronously; posting a
                 // runnable to the view's queue guarantees we'll run after the
                 // layout pass.
                 // Question: Actually it could take many layouts before the desired index is
-                // scrolled to (in both the list and grid case), no?
+                // scrolled to, no?
                 view.post(new Runnable() {
                     @Override
                     public void run() {
                         // Index is relative to all views in the list.
-                        childView[0] = view.getViewAtIndex(index);
+                        final RecyclerView.ViewHolder itemViewHolder =
+                                view.findViewHolderForLayoutPosition(index);
+                        childView[0] = itemViewHolder == null ? null : itemViewHolder.itemView;
                     }
                 });
             }
         });
 
         boolean result = waitForCondition(new Condition() {
             @Override
             public boolean isSatisfied() {