Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.compositor.bottombar; | 5 package org.chromium.chrome.browser.compositor.bottombar; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.support.test.InstrumentationRegistry; | |
| 9 import android.support.test.annotation.UiThreadTest; | |
| 8 import android.support.test.filters.SmallTest; | 10 import android.support.test.filters.SmallTest; |
| 9 import android.test.InstrumentationTestCase; | 11 import android.support.test.rule.UiThreadTestRule; |
| 10 import android.view.MotionEvent; | 12 import android.view.MotionEvent; |
| 11 import android.view.ViewConfiguration; | 13 import android.view.ViewConfiguration; |
| 12 import android.view.ViewGroup; | 14 import android.view.ViewGroup; |
| 13 | 15 |
| 16 import org.junit.Assert; | |
| 17 import org.junit.Before; | |
| 18 import org.junit.Rule; | |
| 19 import org.junit.Test; | |
| 20 import org.junit.runner.RunWith; | |
| 21 | |
| 14 import org.chromium.base.test.util.Feature; | 22 import org.chromium.base.test.util.Feature; |
| 15 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EventFilterHos t; | 23 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EventFilterHos t; |
| 16 import org.chromium.chrome.browser.compositor.layouts.eventfilter.OverlayPanelEv entFilter; | 24 import org.chromium.chrome.browser.compositor.layouts.eventfilter.OverlayPanelEv entFilter; |
| 25 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; | |
| 17 import org.chromium.content.browser.ContentViewCore; | 26 import org.chromium.content.browser.ContentViewCore; |
| 18 | 27 |
| 19 /** | 28 /** |
| 20 * Class responsible for testing the OverlayPanelEventFilter. | 29 * Class responsible for testing the OverlayPanelEventFilter. |
| 21 */ | 30 */ |
| 22 public class OverlayPanelEventFilterTest extends InstrumentationTestCase { | 31 @RunWith(ChromeJUnit4ClassRunner.class) |
| 23 | 32 public class OverlayPanelEventFilterTest { |
| 24 private static final float PANEL_ALMOST_MAXIMIZED_OFFSET_Y_DP = 50.f; | 33 private static final float PANEL_ALMOST_MAXIMIZED_OFFSET_Y_DP = 50.f; |
| 25 private static final float BAR_HEIGHT_DP = 100.f; | 34 private static final float BAR_HEIGHT_DP = 100.f; |
| 26 | 35 |
| 27 private static final float LAYOUT_WIDTH_DP = 600.f; | 36 private static final float LAYOUT_WIDTH_DP = 600.f; |
| 28 private static final float LAYOUT_HEIGHT_DP = 800.f; | 37 private static final float LAYOUT_HEIGHT_DP = 800.f; |
| 29 | 38 |
| 30 // A small value used to check whether two floats are almost equal. | 39 // A small value used to check whether two floats are almost equal. |
| 31 private static final float EPSILON = 1e-04f; | 40 private static final float EPSILON = 1e-04f; |
| 32 | 41 |
| 33 private float mTouchSlopDp; | 42 private float mTouchSlopDp; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 46 | 55 |
| 47 private boolean mShouldLockHorizontalMotionInContent; | 56 private boolean mShouldLockHorizontalMotionInContent; |
| 48 private MotionEvent mEventPropagatedToContent; | 57 private MotionEvent mEventPropagatedToContent; |
| 49 private boolean mEventWasScroll; | 58 private boolean mEventWasScroll; |
| 50 private boolean mEventWasTap; | 59 private boolean mEventWasTap; |
| 51 | 60 |
| 52 // ------------------------------------------------------------------------- ------------------- | 61 // ------------------------------------------------------------------------- ------------------- |
| 53 // OverlayPanelEventFilterWrapper | 62 // OverlayPanelEventFilterWrapper |
| 54 // ------------------------------------------------------------------------- ------------------- | 63 // ------------------------------------------------------------------------- ------------------- |
| 55 | 64 |
| 65 @Rule | |
| 66 public UiThreadTestRule mRule = new UiThreadTestRule(); | |
|
Ted C
2017/03/22 16:32:51
Same comment
| |
| 67 | |
| 56 /** | 68 /** |
| 57 * Wrapper around OverlayPanelEventFilter used by tests. | 69 * Wrapper around OverlayPanelEventFilter used by tests. |
| 58 */ | 70 */ |
| 59 public final class OverlayPanelEventFilterWrapper extends OverlayPanelEventF ilter { | 71 public final class OverlayPanelEventFilterWrapper extends OverlayPanelEventF ilter { |
| 60 public OverlayPanelEventFilterWrapper(Context context, EventFilterHost h ost, | 72 public OverlayPanelEventFilterWrapper(Context context, EventFilterHost h ost, |
| 61 OverlayPanel panel) { | 73 OverlayPanel panel) { |
| 62 super(context, host, panel); | 74 super(context, host, panel); |
| 63 } | 75 } |
| 64 | 76 |
| 65 @Override | 77 @Override |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 93 // StubbedContentViewCore | 105 // StubbedContentViewCore |
| 94 // ------------------------------------------------------------------------- ------------------- | 106 // ------------------------------------------------------------------------- ------------------- |
| 95 | 107 |
| 96 private final class StubbedContentViewCore extends ContentViewCore { | 108 private final class StubbedContentViewCore extends ContentViewCore { |
| 97 public StubbedContentViewCore(Context context) { | 109 public StubbedContentViewCore(Context context) { |
| 98 super(context, ""); | 110 super(context, ""); |
| 99 } | 111 } |
| 100 | 112 |
| 101 @Override | 113 @Override |
| 102 public ViewGroup getContainerView() { | 114 public ViewGroup getContainerView() { |
| 103 return new ViewGroup(getContext()) { | 115 return new ViewGroup(InstrumentationRegistry.getContext()) { |
| 104 @Override | 116 @Override |
| 105 public boolean dispatchTouchEvent(MotionEvent e) { | 117 public boolean dispatchTouchEvent(MotionEvent e) { |
| 106 if (e.getActionMasked() != MotionEvent.ACTION_CANCEL) { | 118 if (e.getActionMasked() != MotionEvent.ACTION_CANCEL) { |
| 107 mWasScrollDetectedOnContent = mEventWasScroll; | 119 mWasScrollDetectedOnContent = mEventWasScroll; |
| 108 mWasTapDetectedOnContent = mEventWasTap; | 120 mWasTapDetectedOnContent = mEventWasTap; |
| 109 | 121 |
| 110 // Check that the event offset is correct. | 122 // Check that the event offset is correct. |
| 111 if (!mShouldLockHorizontalMotionInContent) { | 123 if (!mShouldLockHorizontalMotionInContent) { |
| 112 float propagatedEventY = mEventPropagatedToContent.g etY(); | 124 float propagatedEventY = mEventPropagatedToContent.g etY(); |
| 113 float offsetY = mPanel.getContentY() * mDpToPx; | 125 float offsetY = mPanel.getContentY() * mDpToPx; |
| 114 assertEquals(propagatedEventY - offsetY, e.getY(), E PSILON); | 126 Assert.assertEquals(propagatedEventY - offsetY, e.ge tY(), EPSILON); |
| 115 } | 127 } |
| 116 } else { | 128 } else { |
| 117 mWasScrollDetectedOnContent = false; | 129 mWasScrollDetectedOnContent = false; |
| 118 mWasTapDetectedOnContent = false; | 130 mWasTapDetectedOnContent = false; |
| 119 } | 131 } |
| 120 return super.dispatchTouchEvent(e); | 132 return super.dispatchTouchEvent(e); |
| 121 } | 133 } |
| 122 | 134 |
| 123 @Override | 135 @Override |
| 124 public void onLayout(boolean changed, int l, int t, int r, int b ) {} | 136 public void onLayout(boolean changed, int l, int t, int r, int b ) {} |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 public void onLongPress(float x, float y) {} | 213 public void onLongPress(float x, float y) {} |
| 202 | 214 |
| 203 @Override | 215 @Override |
| 204 public void onPinch(float x0, float y0, float x1, float y1, boolean firs tEvent) {} | 216 public void onPinch(float x0, float y0, float x1, float y1, boolean firs tEvent) {} |
| 205 } | 217 } |
| 206 | 218 |
| 207 // ------------------------------------------------------------------------- ------------------- | 219 // ------------------------------------------------------------------------- ------------------- |
| 208 // Test Suite | 220 // Test Suite |
| 209 // ------------------------------------------------------------------------- ------------------- | 221 // ------------------------------------------------------------------------- ------------------- |
| 210 | 222 |
| 211 @Override | 223 @Before |
| 212 protected void setUp() throws Exception { | 224 public void setUp() throws Exception { |
| 213 super.setUp(); | 225 Context context = InstrumentationRegistry.getInstrumentation().getTarget Context(); |
| 214 | |
| 215 Context context = getInstrumentation().getTargetContext(); | |
| 216 | 226 |
| 217 mDpToPx = context.getResources().getDisplayMetrics().density; | 227 mDpToPx = context.getResources().getDisplayMetrics().density; |
| 218 mTouchSlopDp = ViewConfiguration.get(context).getScaledTouchSlop() / mDp ToPx; | 228 mTouchSlopDp = ViewConfiguration.get(context).getScaledTouchSlop() / mDp ToPx; |
| 219 | 229 |
| 220 mPanel = new MockOverlayPanel(context, new OverlayPanelManager()); | 230 mPanel = new MockOverlayPanel(context, new OverlayPanelManager()); |
| 221 mEventFilter = new OverlayPanelEventFilterWrapper(context, null, mPanel) ; | 231 mEventFilter = new OverlayPanelEventFilterWrapper(context, null, mPanel) ; |
| 222 | 232 |
| 223 mPanel.setSearchBarHeightForTesting(BAR_HEIGHT_DP); | 233 mPanel.setSearchBarHeightForTesting(BAR_HEIGHT_DP); |
| 224 mPanel.setHeightForTesting(LAYOUT_HEIGHT_DP); | 234 mPanel.setHeightForTesting(LAYOUT_HEIGHT_DP); |
| 225 mPanel.setIsFullWidthSizePanelForTesting(true); | 235 mPanel.setIsFullWidthSizePanelForTesting(true); |
| 226 | 236 |
| 227 // NOTE(pedrosimonetti): This should be called after calling the method | 237 // NOTE(pedrosimonetti): This should be called after calling the method |
| 228 // setIsFullWidthSizePanelForTesting(), otherwise it will crash the test . | 238 // setIsFullWidthSizePanelForTesting(), otherwise it will crash the test . |
| 229 mPanel.onSizeChanged(LAYOUT_WIDTH_DP, LAYOUT_HEIGHT_DP, 0, 0); | 239 mPanel.onSizeChanged(LAYOUT_WIDTH_DP, LAYOUT_HEIGHT_DP, 0, 0); |
| 230 | 240 |
| 231 setContentViewVerticalScroll(0); | 241 setContentViewVerticalScroll(0); |
| 232 | 242 |
| 233 mAlmostMaximizedContentOffsetYDp = | 243 mAlmostMaximizedContentOffsetYDp = |
| 234 PANEL_ALMOST_MAXIMIZED_OFFSET_Y_DP + BAR_HEIGHT_DP; | 244 PANEL_ALMOST_MAXIMIZED_OFFSET_Y_DP + BAR_HEIGHT_DP; |
| 235 mMaximizedContentOffsetYDp = BAR_HEIGHT_DP; | 245 mMaximizedContentOffsetYDp = BAR_HEIGHT_DP; |
| 236 | 246 |
| 237 mWasTapDetectedOnContent = false; | 247 mWasTapDetectedOnContent = false; |
| 238 mWasScrollDetectedOnContent = false; | 248 mWasScrollDetectedOnContent = false; |
| 239 | 249 |
| 240 mShouldLockHorizontalMotionInContent = false; | 250 mShouldLockHorizontalMotionInContent = false; |
| 241 } | 251 } |
| 242 | 252 |
| 253 @Test | |
| 243 @SmallTest | 254 @SmallTest |
| 244 @Feature({"OverlayPanel"}) | 255 @Feature({"OverlayPanel"}) |
| 256 @UiThreadTest | |
| 245 public void testTapContentView() { | 257 public void testTapContentView() { |
| 246 positionPanelInAlmostMaximizedState(); | 258 positionPanelInAlmostMaximizedState(); |
| 247 | 259 |
| 248 // Simulate tap. | 260 // Simulate tap. |
| 249 simulateActionDownEvent(0.f, mAlmostMaximizedContentOffsetYDp + 1.f); | 261 simulateActionDownEvent(0.f, mAlmostMaximizedContentOffsetYDp + 1.f); |
| 250 simulateActionUpEvent(0.f, mAlmostMaximizedContentOffsetYDp + 1.f); | 262 simulateActionUpEvent(0.f, mAlmostMaximizedContentOffsetYDp + 1.f); |
| 251 | 263 |
| 252 assertFalse(mPanel.getWasScrollDetected()); | 264 Assert.assertFalse(mPanel.getWasScrollDetected()); |
| 253 assertFalse(mPanel.getWasTapDetected()); | 265 Assert.assertFalse(mPanel.getWasTapDetected()); |
| 254 | 266 |
| 255 assertTrue(mWasTapDetectedOnContent); | 267 Assert.assertTrue(mWasTapDetectedOnContent); |
| 256 assertFalse(mWasScrollDetectedOnContent); | 268 Assert.assertFalse(mWasScrollDetectedOnContent); |
| 257 } | 269 } |
| 258 | 270 |
| 271 @Test | |
| 259 @SmallTest | 272 @SmallTest |
| 260 @Feature({"OverlayPanel"}) | 273 @Feature({"OverlayPanel"}) |
| 274 @UiThreadTest | |
| 261 public void testScrollingContentViewDragsPanel() { | 275 public void testScrollingContentViewDragsPanel() { |
| 262 positionPanelInAlmostMaximizedState(); | 276 positionPanelInAlmostMaximizedState(); |
| 263 | 277 |
| 264 // Simulate swipe up sequence. | 278 // Simulate swipe up sequence. |
| 265 simulateActionDownEvent(0.f, mAlmostMaximizedContentOffsetYDp + 1.f); | 279 simulateActionDownEvent(0.f, mAlmostMaximizedContentOffsetYDp + 1.f); |
| 266 simulateActionMoveEvent(0.f, mMaximizedContentOffsetYDp); | 280 simulateActionMoveEvent(0.f, mMaximizedContentOffsetYDp); |
| 267 simulateActionUpEvent(0.f, mMaximizedContentOffsetYDp); | 281 simulateActionUpEvent(0.f, mMaximizedContentOffsetYDp); |
| 268 | 282 |
| 269 assertTrue(mPanel.getWasScrollDetected()); | 283 Assert.assertTrue(mPanel.getWasScrollDetected()); |
| 270 assertFalse(mPanel.getWasTapDetected()); | 284 Assert.assertFalse(mPanel.getWasTapDetected()); |
| 271 | 285 |
| 272 assertFalse(mWasScrollDetectedOnContent); | 286 Assert.assertFalse(mWasScrollDetectedOnContent); |
| 273 assertFalse(mWasTapDetectedOnContent); | 287 Assert.assertFalse(mWasTapDetectedOnContent); |
| 274 } | 288 } |
| 275 | 289 |
| 290 @Test | |
| 276 @SmallTest | 291 @SmallTest |
| 277 @Feature({"OverlayPanel"}) | 292 @Feature({"OverlayPanel"}) |
| 293 @UiThreadTest | |
| 278 public void testScrollUpContentView() { | 294 public void testScrollUpContentView() { |
| 279 positionPanelInMaximizedState(); | 295 positionPanelInMaximizedState(); |
| 280 | 296 |
| 281 // Simulate swipe up sequence. | 297 // Simulate swipe up sequence. |
| 282 simulateActionDownEvent(0.f, mAlmostMaximizedContentOffsetYDp + 1.f); | 298 simulateActionDownEvent(0.f, mAlmostMaximizedContentOffsetYDp + 1.f); |
| 283 simulateActionMoveEvent(0.f, mMaximizedContentOffsetYDp); | 299 simulateActionMoveEvent(0.f, mMaximizedContentOffsetYDp); |
| 284 simulateActionUpEvent(0.f, mMaximizedContentOffsetYDp); | 300 simulateActionUpEvent(0.f, mMaximizedContentOffsetYDp); |
| 285 | 301 |
| 286 assertFalse(mPanel.getWasScrollDetected()); | 302 Assert.assertFalse(mPanel.getWasScrollDetected()); |
| 287 assertFalse(mPanel.getWasTapDetected()); | 303 Assert.assertFalse(mPanel.getWasTapDetected()); |
| 288 | 304 |
| 289 assertTrue(mWasScrollDetectedOnContent); | 305 Assert.assertTrue(mWasScrollDetectedOnContent); |
| 290 assertFalse(mWasTapDetectedOnContent); | 306 Assert.assertFalse(mWasTapDetectedOnContent); |
| 291 } | 307 } |
| 292 | 308 |
| 309 @Test | |
| 293 @SmallTest | 310 @SmallTest |
| 294 @Feature({"OverlayPanel"}) | 311 @Feature({"OverlayPanel"}) |
| 312 @UiThreadTest | |
| 295 public void testScrollDownContentView() { | 313 public void testScrollDownContentView() { |
| 296 positionPanelInMaximizedState(); | 314 positionPanelInMaximizedState(); |
| 297 | 315 |
| 298 // When the Panel is maximized and the scroll position is greater than z ero, a swipe down | 316 // When the Panel is maximized and the scroll position is greater than z ero, a swipe down |
| 299 // on the ContentView should trigger a scroll on it. | 317 // on the ContentView should trigger a scroll on it. |
| 300 setContentViewVerticalScroll(100.f); | 318 setContentViewVerticalScroll(100.f); |
| 301 | 319 |
| 302 // Simulate swipe down sequence. | 320 // Simulate swipe down sequence. |
| 303 simulateActionDownEvent(0.f, mMaximizedContentOffsetYDp + 1.f); | 321 simulateActionDownEvent(0.f, mMaximizedContentOffsetYDp + 1.f); |
| 304 simulateActionMoveEvent(0.f, mAlmostMaximizedContentOffsetYDp); | 322 simulateActionMoveEvent(0.f, mAlmostMaximizedContentOffsetYDp); |
| 305 simulateActionUpEvent(0.f, mAlmostMaximizedContentOffsetYDp); | 323 simulateActionUpEvent(0.f, mAlmostMaximizedContentOffsetYDp); |
| 306 | 324 |
| 307 assertFalse(mPanel.getWasScrollDetected()); | 325 Assert.assertFalse(mPanel.getWasScrollDetected()); |
| 308 assertFalse(mPanel.getWasTapDetected()); | 326 Assert.assertFalse(mPanel.getWasTapDetected()); |
| 309 | 327 |
| 310 assertTrue(mWasScrollDetectedOnContent); | 328 Assert.assertTrue(mWasScrollDetectedOnContent); |
| 311 assertFalse(mWasTapDetectedOnContent); | 329 Assert.assertFalse(mWasTapDetectedOnContent); |
| 312 } | 330 } |
| 313 | 331 |
| 332 @Test | |
| 314 @SmallTest | 333 @SmallTest |
| 315 @Feature({"OverlayPanel"}) | 334 @Feature({"OverlayPanel"}) |
| 335 @UiThreadTest | |
| 316 public void testDragByOverscrollingContentView() { | 336 public void testDragByOverscrollingContentView() { |
| 317 positionPanelInMaximizedState(); | 337 positionPanelInMaximizedState(); |
| 318 | 338 |
| 319 // When the Panel is maximized and the scroll position is zero, a swipe down on the | 339 // When the Panel is maximized and the scroll position is zero, a swipe down on the |
| 320 // ContentView should trigger a swipe on the Panel. | 340 // ContentView should trigger a swipe on the Panel. |
| 321 setContentViewVerticalScroll(0.f); | 341 setContentViewVerticalScroll(0.f); |
| 322 | 342 |
| 323 // Simulate swipe down sequence. | 343 // Simulate swipe down sequence. |
| 324 simulateActionDownEvent(0.f, mMaximizedContentOffsetYDp + 1.f); | 344 simulateActionDownEvent(0.f, mMaximizedContentOffsetYDp + 1.f); |
| 325 simulateActionMoveEvent(0.f, mAlmostMaximizedContentOffsetYDp); | 345 simulateActionMoveEvent(0.f, mAlmostMaximizedContentOffsetYDp); |
| 326 simulateActionUpEvent(0.f, mAlmostMaximizedContentOffsetYDp); | 346 simulateActionUpEvent(0.f, mAlmostMaximizedContentOffsetYDp); |
| 327 | 347 |
| 328 assertTrue(mPanel.getWasScrollDetected()); | 348 Assert.assertTrue(mPanel.getWasScrollDetected()); |
| 329 assertFalse(mPanel.getWasTapDetected()); | 349 Assert.assertFalse(mPanel.getWasTapDetected()); |
| 330 | 350 |
| 331 assertFalse(mWasScrollDetectedOnContent); | 351 Assert.assertFalse(mWasScrollDetectedOnContent); |
| 332 assertFalse(mWasTapDetectedOnContent); | 352 Assert.assertFalse(mWasTapDetectedOnContent); |
| 333 } | 353 } |
| 334 | 354 |
| 355 @Test | |
| 335 @SmallTest | 356 @SmallTest |
| 336 @Feature({"OverlayPanel"}) | 357 @Feature({"OverlayPanel"}) |
| 358 @UiThreadTest | |
| 337 public void testUnwantedScrollDoesNotHappenInContentView() { | 359 public void testUnwantedScrollDoesNotHappenInContentView() { |
| 338 positionPanelInAlmostMaximizedState(); | 360 positionPanelInAlmostMaximizedState(); |
| 339 | 361 |
| 340 float contentViewOffsetYStart = mAlmostMaximizedContentOffsetYDp + 1.f; | 362 float contentViewOffsetYStart = mAlmostMaximizedContentOffsetYDp + 1.f; |
| 341 float contentViewOffsetYEnd = mMaximizedContentOffsetYDp - 1.f; | 363 float contentViewOffsetYEnd = mMaximizedContentOffsetYDp - 1.f; |
| 342 | 364 |
| 343 // Simulate swipe up to maximized position. | 365 // Simulate swipe up to maximized position. |
| 344 simulateActionDownEvent(0.f, contentViewOffsetYStart); | 366 simulateActionDownEvent(0.f, contentViewOffsetYStart); |
| 345 simulateActionMoveEvent(0.f, mMaximizedContentOffsetYDp); | 367 simulateActionMoveEvent(0.f, mMaximizedContentOffsetYDp); |
| 346 positionPanelInMaximizedState(); | 368 positionPanelInMaximizedState(); |
| 347 | 369 |
| 348 // Confirm that the Panel got a scroll event. | 370 // Confirm that the Panel got a scroll event. |
| 349 assertTrue(mPanel.getWasScrollDetected()); | 371 Assert.assertTrue(mPanel.getWasScrollDetected()); |
| 350 | 372 |
| 351 // Continue the swipe up for one more dp. From now on, the events might be forwarded | 373 // Continue the swipe up for one more dp. From now on, the events might be forwarded |
| 352 // to the ContentView. | 374 // to the ContentView. |
| 353 simulateActionMoveEvent(0.f, contentViewOffsetYEnd); | 375 simulateActionMoveEvent(0.f, contentViewOffsetYEnd); |
| 354 simulateActionUpEvent(0.f, contentViewOffsetYEnd); | 376 simulateActionUpEvent(0.f, contentViewOffsetYEnd); |
| 355 | 377 |
| 356 // But 1 dp is not enough to trigger a scroll in the ContentView, and in this | 378 // But 1 dp is not enough to trigger a scroll in the ContentView, and in this |
| 357 // particular case, it should also not trigger a tap because the total d isplacement | 379 // particular case, it should also not trigger a tap because the total d isplacement |
| 358 // of the touch gesture is greater than the touch slop. | 380 // of the touch gesture is greater than the touch slop. |
| 359 float contentViewOffsetDelta = | 381 float contentViewOffsetDelta = |
| 360 contentViewOffsetYStart - contentViewOffsetYEnd; | 382 contentViewOffsetYStart - contentViewOffsetYEnd; |
| 361 assertTrue(Math.abs(contentViewOffsetDelta) > mTouchSlopDp); | 383 Assert.assertTrue(Math.abs(contentViewOffsetDelta) > mTouchSlopDp); |
| 362 | 384 |
| 363 assertFalse(mPanel.getWasTapDetected()); | 385 Assert.assertFalse(mPanel.getWasTapDetected()); |
| 364 | 386 |
| 365 assertFalse(mWasScrollDetectedOnContent); | 387 Assert.assertFalse(mWasScrollDetectedOnContent); |
| 366 assertFalse(mWasTapDetectedOnContent); | 388 Assert.assertFalse(mWasTapDetectedOnContent); |
| 367 } | 389 } |
| 368 | 390 |
| 391 @Test | |
| 369 @SmallTest | 392 @SmallTest |
| 370 @Feature({"OverlayPanel"}) | 393 @Feature({"OverlayPanel"}) |
| 394 @UiThreadTest | |
| 371 public void testDragPanelThenContinuouslyScrollContentView() { | 395 public void testDragPanelThenContinuouslyScrollContentView() { |
| 372 positionPanelInAlmostMaximizedState(); | 396 positionPanelInAlmostMaximizedState(); |
| 373 | 397 |
| 374 // Simulate swipe up to maximized position. | 398 // Simulate swipe up to maximized position. |
| 375 simulateActionDownEvent(0.f, mAlmostMaximizedContentOffsetYDp + 1.f); | 399 simulateActionDownEvent(0.f, mAlmostMaximizedContentOffsetYDp + 1.f); |
| 376 simulateActionMoveEvent(0.f, mMaximizedContentOffsetYDp); | 400 simulateActionMoveEvent(0.f, mMaximizedContentOffsetYDp); |
| 377 positionPanelInMaximizedState(); | 401 positionPanelInMaximizedState(); |
| 378 | 402 |
| 379 // Confirm that the Panel got a scroll event. | 403 // Confirm that the Panel got a scroll event. |
| 380 assertTrue(mPanel.getWasScrollDetected()); | 404 Assert.assertTrue(mPanel.getWasScrollDetected()); |
| 381 | 405 |
| 382 // Continue the swipe up for one more dp. From now on, the events might be forwarded | 406 // Continue the swipe up for one more dp. From now on, the events might be forwarded |
| 383 // to the ContentView. | 407 // to the ContentView. |
| 384 simulateActionMoveEvent(0.f, mMaximizedContentOffsetYDp - 1.f); | 408 simulateActionMoveEvent(0.f, mMaximizedContentOffsetYDp - 1.f); |
| 385 | 409 |
| 386 // Now keep swiping up an amount greater than the touch slop. In this ca se a scroll | 410 // Now keep swiping up an amount greater than the touch slop. In this ca se a scroll |
| 387 // should be triggered in the ContentView. | 411 // should be triggered in the ContentView. |
| 388 simulateActionMoveEvent(0.f, mMaximizedContentOffsetYDp - 2 * mTouchSlop Dp); | 412 simulateActionMoveEvent(0.f, mMaximizedContentOffsetYDp - 2 * mTouchSlop Dp); |
| 389 simulateActionUpEvent(0.f, mMaximizedContentOffsetYDp - 2 * mTouchSlopDp ); | 413 simulateActionUpEvent(0.f, mMaximizedContentOffsetYDp - 2 * mTouchSlopDp ); |
| 390 | 414 |
| 391 assertFalse(mPanel.getWasTapDetected()); | 415 Assert.assertFalse(mPanel.getWasTapDetected()); |
| 392 | 416 |
| 393 assertTrue(mWasScrollDetectedOnContent); | 417 Assert.assertTrue(mWasScrollDetectedOnContent); |
| 394 assertFalse(mWasTapDetectedOnContent); | 418 Assert.assertFalse(mWasTapDetectedOnContent); |
| 395 } | 419 } |
| 396 | 420 |
| 421 @Test | |
| 397 @SmallTest | 422 @SmallTest |
| 398 @Feature({"OverlayPanel"}) | 423 @Feature({"OverlayPanel"}) |
| 424 @UiThreadTest | |
| 399 public void testTapPanel() { | 425 public void testTapPanel() { |
| 400 positionPanelInAlmostMaximizedState(); | 426 positionPanelInAlmostMaximizedState(); |
| 401 | 427 |
| 402 // Simulate tap. | 428 // Simulate tap. |
| 403 simulateActionDownEvent(0.f, mAlmostMaximizedContentOffsetYDp - 1.f); | 429 simulateActionDownEvent(0.f, mAlmostMaximizedContentOffsetYDp - 1.f); |
| 404 simulateActionUpEvent(0.f, mAlmostMaximizedContentOffsetYDp - 1.f); | 430 simulateActionUpEvent(0.f, mAlmostMaximizedContentOffsetYDp - 1.f); |
| 405 | 431 |
| 406 assertFalse(mPanel.getWasScrollDetected()); | 432 Assert.assertFalse(mPanel.getWasScrollDetected()); |
| 407 assertTrue(mPanel.getWasTapDetected()); | 433 Assert.assertTrue(mPanel.getWasTapDetected()); |
| 408 | 434 |
| 409 assertFalse(mWasScrollDetectedOnContent); | 435 Assert.assertFalse(mWasScrollDetectedOnContent); |
| 410 assertFalse(mWasTapDetectedOnContent); | 436 Assert.assertFalse(mWasTapDetectedOnContent); |
| 411 } | 437 } |
| 412 | 438 |
| 439 @Test | |
| 413 @SmallTest | 440 @SmallTest |
| 414 @Feature({"OverlayPanel"}) | 441 @Feature({"OverlayPanel"}) |
| 442 @UiThreadTest | |
| 415 public void testScrollPanel() { | 443 public void testScrollPanel() { |
| 416 positionPanelInAlmostMaximizedState(); | 444 positionPanelInAlmostMaximizedState(); |
| 417 | 445 |
| 418 // Simulate swipe up sequence. | 446 // Simulate swipe up sequence. |
| 419 simulateActionDownEvent(0.f, mAlmostMaximizedContentOffsetYDp - 1.f); | 447 simulateActionDownEvent(0.f, mAlmostMaximizedContentOffsetYDp - 1.f); |
| 420 simulateActionMoveEvent(0.f, mMaximizedContentOffsetYDp); | 448 simulateActionMoveEvent(0.f, mMaximizedContentOffsetYDp); |
| 421 simulateActionUpEvent(0.f, mMaximizedContentOffsetYDp); | 449 simulateActionUpEvent(0.f, mMaximizedContentOffsetYDp); |
| 422 | 450 |
| 423 assertTrue(mPanel.getWasScrollDetected()); | 451 Assert.assertTrue(mPanel.getWasScrollDetected()); |
| 424 assertFalse(mPanel.getWasTapDetected()); | 452 Assert.assertFalse(mPanel.getWasTapDetected()); |
| 425 | 453 |
| 426 assertFalse(mWasScrollDetectedOnContent); | 454 Assert.assertFalse(mWasScrollDetectedOnContent); |
| 427 assertFalse(mWasTapDetectedOnContent); | 455 Assert.assertFalse(mWasTapDetectedOnContent); |
| 428 } | 456 } |
| 429 | 457 |
| 430 // ------------------------------------------------------------------------- ------------------- | 458 // ------------------------------------------------------------------------- ------------------- |
| 431 // Helpers | 459 // Helpers |
| 432 // ------------------------------------------------------------------------- ------------------- | 460 // ------------------------------------------------------------------------- ------------------- |
| 433 | 461 |
| 434 /** | 462 /** |
| 435 * Positions the Panel in the almost maximized state. | 463 * Positions the Panel in the almost maximized state. |
| 436 */ | 464 */ |
| 437 private void positionPanelInAlmostMaximizedState() { | 465 private void positionPanelInAlmostMaximizedState() { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 | 516 |
| 489 /** | 517 /** |
| 490 * Simulates a MotionEvent.ACTION_UP in the OverlayPanelEventFilter. | 518 * Simulates a MotionEvent.ACTION_UP in the OverlayPanelEventFilter. |
| 491 * @param x The event's x coordinate in dps. | 519 * @param x The event's x coordinate in dps. |
| 492 * @param y The event's y coordinate in dps. | 520 * @param y The event's y coordinate in dps. |
| 493 */ | 521 */ |
| 494 private void simulateActionUpEvent(float x, float y) { | 522 private void simulateActionUpEvent(float x, float y) { |
| 495 simulateEvent(MotionEvent.ACTION_UP, x, y); | 523 simulateEvent(MotionEvent.ACTION_UP, x, y); |
| 496 } | 524 } |
| 497 } | 525 } |
| OLD | NEW |