Home | History | Annotate | Download | only in selection
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.documentsui.selection;
     18 
     19 import static org.junit.Assert.assertFalse;
     20 import static org.junit.Assert.assertTrue;
     21 
     22 import android.support.test.filters.SmallTest;
     23 import android.support.test.runner.AndroidJUnit4;
     24 import android.view.MotionEvent;
     25 import android.view.View;
     26 
     27 import com.android.documentsui.selection.GestureSelectionHelper.RecyclerViewDelegate;
     28 import com.android.documentsui.testing.TestEvents;
     29 
     30 import org.junit.Test;
     31 import org.junit.runner.RunWith;
     32 
     33 @RunWith(AndroidJUnit4.class)
     34 @SmallTest
     35 public class GestureSelectionHelper_RecyclerViewDelegateTest {
     36 
     37     // Simulate a (20, 20) box locating at (20, 20)
     38     static final int LEFT_BORDER = 20;
     39     static final int RIGHT_BORDER = 40;
     40     static final int TOP_BORDER = 20;
     41     static final int BOTTOM_BORDER = 40;
     42 
     43     @Test
     44     public void testLtrPastLastItem() {
     45         MotionEvent event = createEvent(100, 100);
     46         assertTrue(RecyclerViewDelegate.isPastLastItem(
     47                 TOP_BORDER, LEFT_BORDER, RIGHT_BORDER, event, View.LAYOUT_DIRECTION_LTR));
     48     }
     49 
     50     @Test
     51     public void testLtrPastLastItem_Inverse() {
     52         MotionEvent event = createEvent(10, 10);
     53         assertFalse(RecyclerViewDelegate.isPastLastItem(
     54                 TOP_BORDER, LEFT_BORDER, RIGHT_BORDER, event, View.LAYOUT_DIRECTION_LTR));
     55     }
     56 
     57     @Test
     58     public void testRtlPastLastItem() {
     59         MotionEvent event = createEvent(10, 30);
     60         assertTrue(RecyclerViewDelegate.isPastLastItem(
     61                 TOP_BORDER, LEFT_BORDER, RIGHT_BORDER, event, View.LAYOUT_DIRECTION_RTL));
     62     }
     63 
     64     @Test
     65     public void testRtlPastLastItem_Inverse() {
     66         MotionEvent event = createEvent(100, 100);
     67         assertFalse(RecyclerViewDelegate.isPastLastItem(
     68                 TOP_BORDER, LEFT_BORDER, RIGHT_BORDER, event, View.LAYOUT_DIRECTION_RTL));
     69     }
     70 
     71     private static MotionEvent createEvent(int x, int y) {
     72         return TestEvents.builder().action(MotionEvent.ACTION_MOVE).location(x, y).build();
     73     }
     74 }
     75