Home | History | Annotate | Download | only in dirlist
      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.dirlist;
     18 
     19 import android.support.test.filters.SmallTest;
     20 import android.support.test.runner.AndroidJUnit4;
     21 import android.view.KeyEvent;
     22 import android.view.MotionEvent;
     23 
     24 import com.android.documentsui.base.Events.InputEvent;
     25 import com.android.documentsui.selection.SelectionManager;
     26 import com.android.documentsui.selection.SelectionProbe;
     27 import com.android.documentsui.testing.SelectionManagers;
     28 import com.android.documentsui.testing.TestActionHandler;
     29 import com.android.documentsui.testing.TestEvent;
     30 import com.android.documentsui.testing.TestEvent.Builder;
     31 import com.android.documentsui.testing.TestEventHandler;
     32 import com.android.documentsui.testing.TestPredicate;
     33 
     34 import org.junit.Before;
     35 import org.junit.Test;
     36 import org.junit.runner.RunWith;
     37 
     38 import java.util.List;
     39 
     40 @RunWith(AndroidJUnit4.class)
     41 @SmallTest
     42 public final class UserInputHandler_KeyboardTest {
     43 
     44     private static final List<String> ITEMS = TestData.create(100);
     45 
     46     private UserInputHandler<TestEvent> mInputHandler;
     47     private TestActionHandler mActionHandler;
     48     private TestFocusHandler mFocusHandler;
     49     private SelectionProbe mSelection;
     50 
     51     private TestPredicate<DocumentDetails> mCanSelect;
     52     private TestEventHandler<InputEvent> mRightClickHandler;
     53     private TestEventHandler<InputEvent> mDragAndDropHandler;
     54     private TestEventHandler<InputEvent> mGestureSelectHandler;
     55     private TestEventHandler<Void> mPerformHapticFeedback;
     56 
     57     private Builder mEvent;
     58 
     59     @Before
     60     public void setUp() {
     61         SelectionManager selectionMgr = SelectionManagers.createTestInstance(ITEMS);
     62 
     63         mActionHandler = new TestActionHandler();
     64         mSelection = new SelectionProbe(selectionMgr);
     65         mFocusHandler = new TestFocusHandler();
     66         mCanSelect = new TestPredicate<>();
     67         mRightClickHandler = new TestEventHandler<>();
     68         mDragAndDropHandler = new TestEventHandler<>();
     69         mGestureSelectHandler = new TestEventHandler<>();
     70 
     71         mInputHandler = new UserInputHandler<>(
     72                 mActionHandler,
     73                 mFocusHandler,
     74                 selectionMgr,
     75                 (MotionEvent event) -> {
     76                     throw new UnsupportedOperationException("Not exercised in tests.");
     77                 },
     78                 mCanSelect,
     79                 mRightClickHandler::accept,
     80                 mDragAndDropHandler::accept,
     81                 mGestureSelectHandler::accept,
     82                 () -> mPerformHapticFeedback.accept(null));
     83 
     84         mEvent = TestEvent.builder().mouse().overDocIcon();
     85     }
     86 
     87     @Test
     88     public void testArrowKey_nonShiftClearsSelection() {
     89         mInputHandler.onSingleTapConfirmed(mEvent.at(11).build());
     90         mSelection.assertSelection(11);
     91 
     92         mFocusHandler.handleKey = true;
     93         KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_UP);
     94         mInputHandler.onKey(null, event.getKeyCode(), event);
     95 
     96         mSelection.assertNoSelection();
     97     }
     98 }