| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.suggestions; | 5 package org.chromium.chrome.browser.suggestions; |
| 6 | 6 |
| 7 import static org.chromium.chrome.test.util.browser.suggestions.ContentSuggestio
nsTestUtils.registerCategory; | 7 import static org.chromium.chrome.test.util.browser.suggestions.ContentSuggestio
nsTestUtils.registerCategory; |
| 8 | 8 |
| 9 import android.os.SystemClock; | 9 import android.os.SystemClock; |
| 10 import android.support.test.filters.MediumTest; | 10 import android.support.test.filters.MediumTest; |
| 11 import android.support.v7.widget.RecyclerView.ViewHolder; | 11 import android.support.v7.widget.RecyclerView.ViewHolder; |
| 12 import android.view.MotionEvent; | 12 import android.view.MotionEvent; |
| 13 | 13 |
| 14 import org.chromium.base.ThreadUtils; | 14 import org.chromium.base.ThreadUtils; |
| 15 import org.chromium.base.test.util.RetryOnFailure; | 15 import org.chromium.base.test.util.RetryOnFailure; |
| 16 import org.chromium.chrome.R; | 16 import org.chromium.chrome.R; |
| 17 import org.chromium.chrome.browser.ntp.cards.ItemViewType; | 17 import org.chromium.chrome.browser.ntp.cards.ItemViewType; |
| 18 import org.chromium.chrome.test.BottomSheetTestCaseBase; | 18 import org.chromium.chrome.test.BottomSheetTestCaseBase; |
| 19 import org.chromium.chrome.test.util.browser.RecyclerViewTestUtils; | 19 import org.chromium.chrome.test.util.browser.RecyclerViewTestUtils; |
| 20 import org.chromium.chrome.test.util.browser.suggestions.DummySuggestionsMetrics
Reporter; | 20 import org.chromium.chrome.test.util.browser.suggestions.DummySuggestionsEventRe
porter; |
| 21 import org.chromium.chrome.test.util.browser.suggestions.FakeSuggestionsSource; | 21 import org.chromium.chrome.test.util.browser.suggestions.FakeSuggestionsSource; |
| 22 import org.chromium.content.browser.test.util.TestTouchUtils; | 22 import org.chromium.content.browser.test.util.TestTouchUtils; |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * Instrumentation tests for {@link SuggestionsBottomSheetContent}. | 25 * Instrumentation tests for {@link SuggestionsBottomSheetContent}. |
| 26 */ | 26 */ |
| 27 public class SuggestionsBottomSheetTest extends BottomSheetTestCaseBase { | 27 public class SuggestionsBottomSheetTest extends BottomSheetTestCaseBase { |
| 28 private FakeSuggestionsSource mSuggestionsSource; | 28 private FakeSuggestionsSource mSuggestionsSource; |
| 29 | 29 |
| 30 @Override | 30 @Override |
| 31 protected void setUp() throws Exception { | 31 protected void setUp() throws Exception { |
| 32 mSuggestionsSource = new FakeSuggestionsSource(); | 32 mSuggestionsSource = new FakeSuggestionsSource(); |
| 33 registerCategory(mSuggestionsSource, /* category = */ 42, /* count = */
5); | 33 registerCategory(mSuggestionsSource, /* category = */ 42, /* count = */
5); |
| 34 SuggestionsBottomSheetContent.setSuggestionsSourceForTesting(mSuggestion
sSource); | 34 SuggestionsBottomSheetContent.setSuggestionsSourceForTesting(mSuggestion
sSource); |
| 35 SuggestionsBottomSheetContent.setMetricsReporterForTesting( | 35 SuggestionsBottomSheetContent.setEventReporterForTesting( |
| 36 new DummySuggestionsMetricsReporter()); | 36 new DummySuggestionsEventReporter()); |
| 37 super.setUp(); | 37 super.setUp(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 @Override | 40 @Override |
| 41 protected void tearDown() throws Exception { | 41 protected void tearDown() throws Exception { |
| 42 SuggestionsBottomSheetContent.setSuggestionsSourceForTesting(null); | 42 SuggestionsBottomSheetContent.setSuggestionsSourceForTesting(null); |
| 43 SuggestionsBottomSheetContent.setMetricsReporterForTesting(null); | 43 SuggestionsBottomSheetContent.setEventReporterForTesting(null); |
| 44 super.tearDown(); | 44 super.tearDown(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 @RetryOnFailure | 47 @RetryOnFailure |
| 48 @MediumTest | 48 @MediumTest |
| 49 public void testContextMenu() throws InterruptedException { | 49 public void testContextMenu() throws InterruptedException { |
| 50 SuggestionsRecyclerView recyclerView = | 50 SuggestionsRecyclerView recyclerView = |
| 51 (SuggestionsRecyclerView) getBottomSheetContent().getContentView
().findViewById( | 51 (SuggestionsRecyclerView) getBottomSheetContent().getContentView
().findViewById( |
| 52 R.id.recycler_view); | 52 R.id.recycler_view); |
| 53 | 53 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 67 }); | 67 }); |
| 68 | 68 |
| 69 assertFalse(getActivity().getBottomSheet().onInterceptTouchEvent(createT
apEvent())); | 69 assertFalse(getActivity().getBottomSheet().onInterceptTouchEvent(createT
apEvent())); |
| 70 } | 70 } |
| 71 | 71 |
| 72 private static MotionEvent createTapEvent() { | 72 private static MotionEvent createTapEvent() { |
| 73 return MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptime
Millis(), | 73 return MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptime
Millis(), |
| 74 MotionEvent.ACTION_DOWN, 0f, 0f, 0); | 74 MotionEvent.ACTION_DOWN, 0f, 0f, 0); |
| 75 } | 75 } |
| 76 } | 76 } |
| OLD | NEW |