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.browser.ntp.cards.ItemViewType; | 17 import org.chromium.chrome.browser.ntp.cards.ItemViewType; |
17 import org.chromium.chrome.test.BottomSheetTestCaseBase; | 18 import org.chromium.chrome.test.BottomSheetTestCaseBase; |
18 import org.chromium.chrome.test.util.browser.RecyclerViewTestUtils; | 19 import org.chromium.chrome.test.util.browser.RecyclerViewTestUtils; |
19 import org.chromium.chrome.test.util.browser.suggestions.DummySuggestionsMetrics
Reporter; | 20 import org.chromium.chrome.test.util.browser.suggestions.DummySuggestionsMetrics
Reporter; |
20 import org.chromium.chrome.test.util.browser.suggestions.FakeSuggestionsSource; | 21 import org.chromium.chrome.test.util.browser.suggestions.FakeSuggestionsSource; |
21 import org.chromium.content.browser.test.util.TestTouchUtils; | 22 import org.chromium.content.browser.test.util.TestTouchUtils; |
22 | 23 |
23 /** | 24 /** |
24 * Instrumentation tests for {@link SuggestionsBottomSheetContent}. | 25 * Instrumentation tests for {@link SuggestionsBottomSheetContent}. |
25 */ | 26 */ |
(...skipping 14 matching lines...) Expand all Loading... |
40 protected void tearDown() throws Exception { | 41 protected void tearDown() throws Exception { |
41 SuggestionsBottomSheetContent.setSuggestionsSourceForTesting(null); | 42 SuggestionsBottomSheetContent.setSuggestionsSourceForTesting(null); |
42 SuggestionsBottomSheetContent.setMetricsReporterForTesting(null); | 43 SuggestionsBottomSheetContent.setMetricsReporterForTesting(null); |
43 super.tearDown(); | 44 super.tearDown(); |
44 } | 45 } |
45 | 46 |
46 @RetryOnFailure | 47 @RetryOnFailure |
47 @MediumTest | 48 @MediumTest |
48 public void testContextMenu() throws InterruptedException { | 49 public void testContextMenu() throws InterruptedException { |
49 SuggestionsRecyclerView recyclerView = | 50 SuggestionsRecyclerView recyclerView = |
50 (SuggestionsRecyclerView) getBottomSheetContent().getContentView
(); | 51 (SuggestionsRecyclerView) getBottomSheetContent().getContentView
().findViewById( |
| 52 R.id.recycler_view); |
51 | 53 |
52 ViewHolder firstCardViewHolder = RecyclerViewTestUtils.waitForView(recyc
lerView, 2); | 54 ViewHolder firstCardViewHolder = RecyclerViewTestUtils.waitForView(recyc
lerView, 2); |
53 assertEquals(firstCardViewHolder.getItemViewType(), ItemViewType.SNIPPET
); | 55 assertEquals(firstCardViewHolder.getItemViewType(), ItemViewType.SNIPPET
); |
54 | 56 |
55 assertFalse(recyclerView.onInterceptTouchEvent(createTapEvent())); | 57 assertFalse(recyclerView.onInterceptTouchEvent(createTapEvent())); |
56 | 58 |
57 TestTouchUtils.longClickView(getInstrumentation(), firstCardViewHolder.i
temView); | 59 TestTouchUtils.longClickView(getInstrumentation(), firstCardViewHolder.i
temView); |
58 assertTrue(recyclerView.onInterceptTouchEvent(createTapEvent())); | 60 assertTrue(recyclerView.onInterceptTouchEvent(createTapEvent())); |
59 | 61 |
60 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 62 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
61 @Override | 63 @Override |
62 public void run() { | 64 public void run() { |
63 getActivity().closeContextMenu(); | 65 getActivity().closeContextMenu(); |
64 } | 66 } |
65 }); | 67 }); |
66 | 68 |
67 assertFalse(recyclerView.onInterceptTouchEvent(createTapEvent())); | 69 assertFalse(recyclerView.onInterceptTouchEvent(createTapEvent())); |
68 } | 70 } |
69 | 71 |
70 private static MotionEvent createTapEvent() { | 72 private static MotionEvent createTapEvent() { |
71 return MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptime
Millis(), | 73 return MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptime
Millis(), |
72 MotionEvent.ACTION_DOWN, 0f, 0f, 0); | 74 MotionEvent.ACTION_DOWN, 0f, 0f, 0); |
73 } | 75 } |
74 } | 76 } |
OLD | NEW |