Chromium Code Reviews| Index: chrome/android/javatests/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerViewTest.java |
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerViewTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerViewTest.java |
| index bcdc1bcb6274bd332c164129a864b641c8879a32..2d6d7b0f705b437f31d89f03f7879b7d2cca1d4d 100644 |
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerViewTest.java |
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerViewTest.java |
| @@ -127,6 +127,14 @@ public class NewTabPageRecyclerViewTest { |
| } |
| + private int getLastCardPosition() { |
|
dgn
2017/05/24 11:30:31
nit: move at the end with the other utility functi
Bernhard Bauer
2017/05/25 12:27:54
Done.
|
| + int count = getAdapter().getItemCount(); |
| + for (int i = count - 1; i >= 0; i--) { |
| + if (getAdapter().getItemViewType(i) == ItemViewType.SNIPPET) return i; |
| + } |
| + return RecyclerView.NO_POSITION; |
| + } |
| + |
| @Test |
| @MediumTest |
| @Feature({"NewTabPage"}) |
| @@ -136,7 +144,7 @@ public class NewTabPageRecyclerViewTest { |
| // Scroll the last suggestion into view and click it. |
| SnippetArticle suggestion = suggestions.get(suggestions.size() - 1); |
| - int suggestionPosition = getSuggestionPosition(suggestion); |
| + int suggestionPosition = getLastCardPosition(); |
| final View suggestionView = getViewHolderAtPosition(suggestionPosition).itemView; |
| ChromeTabUtils.waitForTabPageLoaded(mTab, new Runnable() { |
| @Override |
| @@ -189,7 +197,7 @@ public class NewTabPageRecyclerViewTest { |
| Assert.assertEquals(10, suggestions.size()); |
| // Scroll a suggestion into view. |
| - int suggestionPosition = getSuggestionPosition(suggestions.get(suggestions.size() - 1)); |
| + int suggestionPosition = getLastCardPosition(); |
| View suggestionView = getViewHolderAtPosition(suggestionPosition).itemView; |
| // Dismiss the suggestion using the context menu. |
| @@ -362,15 +370,6 @@ public class NewTabPageRecyclerViewTest { |
| return getRecyclerView().getNewTabPageAdapter(); |
| } |
| - private int getSuggestionPosition(SnippetArticle article) { |
| - NewTabPageAdapter adapter = getAdapter(); |
| - for (int i = 0; i < adapter.getItemCount(); i++) { |
| - SnippetArticle articleToCheck = adapter.getSuggestionAt(i); |
| - if (articleToCheck != null && articleToCheck.equals(article)) return i; |
| - } |
| - return RecyclerView.NO_POSITION; |
| - } |
| - |
| /** |
| * Scroll the {@link View} at the given adapter position into view and returns |
| * its {@link ViewHolder}. |