Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5108)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/compositor/bottombar/OverlayPanelEventFilterTest.java

Issue 2760153002: Convert chrome compositor test's InstrumentationTestCases (Closed)
Patch Set: Address comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/compositor/bottombar/OverlayPanelEventFilterTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/compositor/bottombar/OverlayPanelEventFilterTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/compositor/bottombar/OverlayPanelEventFilterTest.java
index f5d61fbab3ec910bdb42fe6b9f9b2a7c1156ffa8..d4fcb4c4091016d59530b65e5fe65bb7f113be4e 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/compositor/bottombar/OverlayPanelEventFilterTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/compositor/bottombar/OverlayPanelEventFilterTest.java
@@ -5,22 +5,31 @@
package org.chromium.chrome.browser.compositor.bottombar;
import android.content.Context;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.SmallTest;
-import android.test.InstrumentationTestCase;
+import android.support.test.rule.UiThreadTestRule;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.compositor.layouts.eventfilter.EventFilterHost;
import org.chromium.chrome.browser.compositor.layouts.eventfilter.OverlayPanelEventFilter;
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.content.browser.ContentViewCore;
/**
* Class responsible for testing the OverlayPanelEventFilter.
*/
-public class OverlayPanelEventFilterTest extends InstrumentationTestCase {
-
+@RunWith(ChromeJUnit4ClassRunner.class)
+public class OverlayPanelEventFilterTest {
private static final float PANEL_ALMOST_MAXIMIZED_OFFSET_Y_DP = 50.f;
private static final float BAR_HEIGHT_DP = 100.f;
@@ -53,6 +62,9 @@ public class OverlayPanelEventFilterTest extends InstrumentationTestCase {
// OverlayPanelEventFilterWrapper
// --------------------------------------------------------------------------------------------
+ @Rule
+ public UiThreadTestRule mRule = new UiThreadTestRule();
+
/**
* Wrapper around OverlayPanelEventFilter used by tests.
*/
@@ -100,7 +112,7 @@ public class OverlayPanelEventFilterTest extends InstrumentationTestCase {
@Override
public ViewGroup getContainerView() {
- return new ViewGroup(getContext()) {
+ return new ViewGroup(InstrumentationRegistry.getContext()) {
@Override
public boolean dispatchTouchEvent(MotionEvent e) {
if (e.getActionMasked() != MotionEvent.ACTION_CANCEL) {
@@ -111,7 +123,7 @@ public class OverlayPanelEventFilterTest extends InstrumentationTestCase {
if (!mShouldLockHorizontalMotionInContent) {
float propagatedEventY = mEventPropagatedToContent.getY();
float offsetY = mPanel.getContentY() * mDpToPx;
- assertEquals(propagatedEventY - offsetY, e.getY(), EPSILON);
+ Assert.assertEquals(propagatedEventY - offsetY, e.getY(), EPSILON);
}
} else {
mWasScrollDetectedOnContent = false;
@@ -208,11 +220,9 @@ public class OverlayPanelEventFilterTest extends InstrumentationTestCase {
// Test Suite
// --------------------------------------------------------------------------------------------
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- Context context = getInstrumentation().getTargetContext();
+ @Before
+ public void setUp() throws Exception {
+ Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
mDpToPx = context.getResources().getDisplayMetrics().density;
mTouchSlopDp = ViewConfiguration.get(context).getScaledTouchSlop() / mDpToPx;
@@ -240,8 +250,10 @@ public class OverlayPanelEventFilterTest extends InstrumentationTestCase {
mShouldLockHorizontalMotionInContent = false;
}
+ @Test
@SmallTest
@Feature({"OverlayPanel"})
+ @UiThreadTest
public void testTapContentView() {
positionPanelInAlmostMaximizedState();
@@ -249,15 +261,17 @@ public class OverlayPanelEventFilterTest extends InstrumentationTestCase {
simulateActionDownEvent(0.f, mAlmostMaximizedContentOffsetYDp + 1.f);
simulateActionUpEvent(0.f, mAlmostMaximizedContentOffsetYDp + 1.f);
- assertFalse(mPanel.getWasScrollDetected());
- assertFalse(mPanel.getWasTapDetected());
+ Assert.assertFalse(mPanel.getWasScrollDetected());
+ Assert.assertFalse(mPanel.getWasTapDetected());
- assertTrue(mWasTapDetectedOnContent);
- assertFalse(mWasScrollDetectedOnContent);
+ Assert.assertTrue(mWasTapDetectedOnContent);
+ Assert.assertFalse(mWasScrollDetectedOnContent);
}
+ @Test
@SmallTest
@Feature({"OverlayPanel"})
+ @UiThreadTest
public void testScrollingContentViewDragsPanel() {
positionPanelInAlmostMaximizedState();
@@ -266,15 +280,17 @@ public class OverlayPanelEventFilterTest extends InstrumentationTestCase {
simulateActionMoveEvent(0.f, mMaximizedContentOffsetYDp);
simulateActionUpEvent(0.f, mMaximizedContentOffsetYDp);
- assertTrue(mPanel.getWasScrollDetected());
- assertFalse(mPanel.getWasTapDetected());
+ Assert.assertTrue(mPanel.getWasScrollDetected());
+ Assert.assertFalse(mPanel.getWasTapDetected());
- assertFalse(mWasScrollDetectedOnContent);
- assertFalse(mWasTapDetectedOnContent);
+ Assert.assertFalse(mWasScrollDetectedOnContent);
+ Assert.assertFalse(mWasTapDetectedOnContent);
}
+ @Test
@SmallTest
@Feature({"OverlayPanel"})
+ @UiThreadTest
public void testScrollUpContentView() {
positionPanelInMaximizedState();
@@ -283,15 +299,17 @@ public class OverlayPanelEventFilterTest extends InstrumentationTestCase {
simulateActionMoveEvent(0.f, mMaximizedContentOffsetYDp);
simulateActionUpEvent(0.f, mMaximizedContentOffsetYDp);
- assertFalse(mPanel.getWasScrollDetected());
- assertFalse(mPanel.getWasTapDetected());
+ Assert.assertFalse(mPanel.getWasScrollDetected());
+ Assert.assertFalse(mPanel.getWasTapDetected());
- assertTrue(mWasScrollDetectedOnContent);
- assertFalse(mWasTapDetectedOnContent);
+ Assert.assertTrue(mWasScrollDetectedOnContent);
+ Assert.assertFalse(mWasTapDetectedOnContent);
}
+ @Test
@SmallTest
@Feature({"OverlayPanel"})
+ @UiThreadTest
public void testScrollDownContentView() {
positionPanelInMaximizedState();
@@ -304,15 +322,17 @@ public class OverlayPanelEventFilterTest extends InstrumentationTestCase {
simulateActionMoveEvent(0.f, mAlmostMaximizedContentOffsetYDp);
simulateActionUpEvent(0.f, mAlmostMaximizedContentOffsetYDp);
- assertFalse(mPanel.getWasScrollDetected());
- assertFalse(mPanel.getWasTapDetected());
+ Assert.assertFalse(mPanel.getWasScrollDetected());
+ Assert.assertFalse(mPanel.getWasTapDetected());
- assertTrue(mWasScrollDetectedOnContent);
- assertFalse(mWasTapDetectedOnContent);
+ Assert.assertTrue(mWasScrollDetectedOnContent);
+ Assert.assertFalse(mWasTapDetectedOnContent);
}
+ @Test
@SmallTest
@Feature({"OverlayPanel"})
+ @UiThreadTest
public void testDragByOverscrollingContentView() {
positionPanelInMaximizedState();
@@ -325,15 +345,17 @@ public class OverlayPanelEventFilterTest extends InstrumentationTestCase {
simulateActionMoveEvent(0.f, mAlmostMaximizedContentOffsetYDp);
simulateActionUpEvent(0.f, mAlmostMaximizedContentOffsetYDp);
- assertTrue(mPanel.getWasScrollDetected());
- assertFalse(mPanel.getWasTapDetected());
+ Assert.assertTrue(mPanel.getWasScrollDetected());
+ Assert.assertFalse(mPanel.getWasTapDetected());
- assertFalse(mWasScrollDetectedOnContent);
- assertFalse(mWasTapDetectedOnContent);
+ Assert.assertFalse(mWasScrollDetectedOnContent);
+ Assert.assertFalse(mWasTapDetectedOnContent);
}
+ @Test
@SmallTest
@Feature({"OverlayPanel"})
+ @UiThreadTest
public void testUnwantedScrollDoesNotHappenInContentView() {
positionPanelInAlmostMaximizedState();
@@ -346,7 +368,7 @@ public class OverlayPanelEventFilterTest extends InstrumentationTestCase {
positionPanelInMaximizedState();
// Confirm that the Panel got a scroll event.
- assertTrue(mPanel.getWasScrollDetected());
+ Assert.assertTrue(mPanel.getWasScrollDetected());
// Continue the swipe up for one more dp. From now on, the events might be forwarded
// to the ContentView.
@@ -358,16 +380,18 @@ public class OverlayPanelEventFilterTest extends InstrumentationTestCase {
// of the touch gesture is greater than the touch slop.
float contentViewOffsetDelta =
contentViewOffsetYStart - contentViewOffsetYEnd;
- assertTrue(Math.abs(contentViewOffsetDelta) > mTouchSlopDp);
+ Assert.assertTrue(Math.abs(contentViewOffsetDelta) > mTouchSlopDp);
- assertFalse(mPanel.getWasTapDetected());
+ Assert.assertFalse(mPanel.getWasTapDetected());
- assertFalse(mWasScrollDetectedOnContent);
- assertFalse(mWasTapDetectedOnContent);
+ Assert.assertFalse(mWasScrollDetectedOnContent);
+ Assert.assertFalse(mWasTapDetectedOnContent);
}
+ @Test
@SmallTest
@Feature({"OverlayPanel"})
+ @UiThreadTest
public void testDragPanelThenContinuouslyScrollContentView() {
positionPanelInAlmostMaximizedState();
@@ -377,7 +401,7 @@ public class OverlayPanelEventFilterTest extends InstrumentationTestCase {
positionPanelInMaximizedState();
// Confirm that the Panel got a scroll event.
- assertTrue(mPanel.getWasScrollDetected());
+ Assert.assertTrue(mPanel.getWasScrollDetected());
// Continue the swipe up for one more dp. From now on, the events might be forwarded
// to the ContentView.
@@ -388,14 +412,16 @@ public class OverlayPanelEventFilterTest extends InstrumentationTestCase {
simulateActionMoveEvent(0.f, mMaximizedContentOffsetYDp - 2 * mTouchSlopDp);
simulateActionUpEvent(0.f, mMaximizedContentOffsetYDp - 2 * mTouchSlopDp);
- assertFalse(mPanel.getWasTapDetected());
+ Assert.assertFalse(mPanel.getWasTapDetected());
- assertTrue(mWasScrollDetectedOnContent);
- assertFalse(mWasTapDetectedOnContent);
+ Assert.assertTrue(mWasScrollDetectedOnContent);
+ Assert.assertFalse(mWasTapDetectedOnContent);
}
+ @Test
@SmallTest
@Feature({"OverlayPanel"})
+ @UiThreadTest
public void testTapPanel() {
positionPanelInAlmostMaximizedState();
@@ -403,15 +429,17 @@ public class OverlayPanelEventFilterTest extends InstrumentationTestCase {
simulateActionDownEvent(0.f, mAlmostMaximizedContentOffsetYDp - 1.f);
simulateActionUpEvent(0.f, mAlmostMaximizedContentOffsetYDp - 1.f);
- assertFalse(mPanel.getWasScrollDetected());
- assertTrue(mPanel.getWasTapDetected());
+ Assert.assertFalse(mPanel.getWasScrollDetected());
+ Assert.assertTrue(mPanel.getWasTapDetected());
- assertFalse(mWasScrollDetectedOnContent);
- assertFalse(mWasTapDetectedOnContent);
+ Assert.assertFalse(mWasScrollDetectedOnContent);
+ Assert.assertFalse(mWasTapDetectedOnContent);
}
+ @Test
@SmallTest
@Feature({"OverlayPanel"})
+ @UiThreadTest
public void testScrollPanel() {
positionPanelInAlmostMaximizedState();
@@ -420,11 +448,11 @@ public class OverlayPanelEventFilterTest extends InstrumentationTestCase {
simulateActionMoveEvent(0.f, mMaximizedContentOffsetYDp);
simulateActionUpEvent(0.f, mMaximizedContentOffsetYDp);
- assertTrue(mPanel.getWasScrollDetected());
- assertFalse(mPanel.getWasTapDetected());
+ Assert.assertTrue(mPanel.getWasScrollDetected());
+ Assert.assertFalse(mPanel.getWasTapDetected());
- assertFalse(mWasScrollDetectedOnContent);
- assertFalse(mWasTapDetectedOnContent);
+ Assert.assertFalse(mWasScrollDetectedOnContent);
+ Assert.assertFalse(mWasTapDetectedOnContent);
}
// --------------------------------------------------------------------------------------------

Powered by Google App Engine
This is Rietveld 408576698