Chromium Code Reviews| Index: chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/SuggestionsBottomSheetTest.java |
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/SuggestionsBottomSheetTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/SuggestionsBottomSheetTest.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..68cc3514f4f1afcb1b66a07ddea5102217a37b67 |
| --- /dev/null |
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/SuggestionsBottomSheetTest.java |
| @@ -0,0 +1,67 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.suggestions; |
| + |
| +import static org.chromium.chrome.test.util.browser.suggestions.ContentSuggestionsTestUtils.registerCategory; |
| + |
| +import android.os.SystemClock; |
| +import android.support.test.filters.MediumTest; |
| +import android.support.v7.widget.RecyclerView.ViewHolder; |
| +import android.view.MotionEvent; |
| + |
| +import org.chromium.chrome.browser.ntp.cards.ItemViewType; |
| +import org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView; |
| +import org.chromium.chrome.test.BottomSheetTestCaseBase; |
| +import org.chromium.chrome.test.util.browser.RecyclerViewTestUtils; |
| +import org.chromium.chrome.test.util.browser.suggestions.DummySuggestionsMetricsReporter; |
| +import org.chromium.chrome.test.util.browser.suggestions.FakeSuggestionsSource; |
| +import org.chromium.content.browser.test.util.TestTouchUtils; |
| + |
| +/** |
| + * Instrumentation tests for {@link SuggestionsBottomSheetContent}. |
| + */ |
| +public class SuggestionsBottomSheetTest extends BottomSheetTestCaseBase { |
| + private FakeSuggestionsSource mSuggestionsSource; |
| + |
| + @Override |
| + protected void setUp() throws Exception { |
| + mSuggestionsSource = new FakeSuggestionsSource(); |
| + registerCategory(mSuggestionsSource, /* category = */ 42, /* count = */ 5); |
| + SuggestionsBottomSheetContent.setSuggestionsSourceForTesting(mSuggestionsSource); |
| + SuggestionsBottomSheetContent.setMetricsReporterForTesting( |
| + new DummySuggestionsMetricsReporter()); |
| + super.setUp(); |
| + } |
| + |
| + @Override |
| + protected void tearDown() throws Exception { |
| + super.tearDown(); |
|
gone
2017/02/10 18:17:09
I usually like putting super.tearDown() at the bot
dgn
2017/02/13 14:25:39
Done.
|
| + SuggestionsBottomSheetContent.setSuggestionsSourceForTesting(null); |
| + SuggestionsBottomSheetContent.setMetricsReporterForTesting(null); |
| + mSuggestionsSource = null; |
|
Michael van Ouwerkerk
2017/02/07 11:12:41
nit: I think we need not null out any instance mem
dgn
2017/02/13 14:25:39
Done.
|
| + } |
| + |
| + @MediumTest |
| + public void testContextMenu() throws InterruptedException { |
| + NewTabPageRecyclerView recyclerView = |
| + (NewTabPageRecyclerView) getBottomSheetContent().getScrollingContentView(); |
| + |
| + ViewHolder firstCardViewHolder = RecyclerViewTestUtils.waitForView(recyclerView, 2); |
| + assertEquals(firstCardViewHolder.getItemViewType(), ItemViewType.SNIPPET); |
| + |
| + assertFalse(recyclerView.onInterceptTouchEvent(createTapEvent())); |
| + |
| + TestTouchUtils.longClickView(getInstrumentation(), firstCardViewHolder.itemView); |
| + assertTrue(recyclerView.onInterceptTouchEvent(createTapEvent())); |
| + |
| + getActivity().closeContextMenu(); |
| + assertFalse(recyclerView.onInterceptTouchEvent(createTapEvent())); |
| + } |
| + |
| + private static MotionEvent createTapEvent() { |
| + return MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), |
| + MotionEvent.ACTION_DOWN, 0f, 0f, 0); |
| + } |
| +} |