Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8f06585b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Moving focus around with arrow key should de-select everything." into nyc-andromeda-dev

parents 14627f5f 41d7e22b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -432,6 +432,7 @@ public final class UserInputHandler<T extends InputEvent>
                    mSelectionMgr.snapRangeSelection(mFocusHandler.getFocusPosition());
                } else {
                    mSelectionMgr.endRangeSelection();
                    mSelectionMgr.clearSelection();
                }
                return true;
            }
+3 −1
Original line number Diff line number Diff line
@@ -24,9 +24,11 @@ import android.view.View;
 */
public final class TestFocusHandler implements FocusHandler {

    public boolean handleKey;

    @Override
    public boolean handleKey(DocumentHolder doc, int keyCode, KeyEvent event) {
        return false;
        return handleKey;
    }

    @Override
+98 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.documentsui.dirlist;

import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.view.KeyEvent;
import android.view.MotionEvent;

import com.android.documentsui.base.Events.InputEvent;
import com.android.documentsui.testing.MultiSelectManagers;
import com.android.documentsui.testing.TestActionHandler;
import com.android.documentsui.testing.TestEvent;
import com.android.documentsui.testing.TestEventHandler;
import com.android.documentsui.testing.TestPredicate;
import com.android.documentsui.testing.TestEvent.Builder;
import com.android.documentsui.testing.dirlist.SelectionProbe;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.List;

@RunWith(AndroidJUnit4.class)
@SmallTest
public final class UserInputHandler_KeyboardTest {

    private static final List<String> ITEMS = TestData.create(100);

    private UserInputHandler<TestEvent> mInputHandler;
    private TestActionHandler mActionHandler;
    private TestFocusHandler mFocusHandler;
    private SelectionProbe mSelection;

    private TestPredicate<DocumentDetails> mCanSelect;
    private TestEventHandler<InputEvent> mRightClickHandler;
    private TestEventHandler<DocumentDetails> mDeleteHandler;
    private TestEventHandler<InputEvent> mDragAndDropHandler;
    private TestEventHandler<InputEvent> mGestureSelectHandler;

    private Builder mEvent;

    @Before
    public void setUp() {
        MultiSelectManager selectionMgr = MultiSelectManagers.createTestInstance(ITEMS);

        mActionHandler = new TestActionHandler();
        mSelection = new SelectionProbe(selectionMgr);
        mFocusHandler = new TestFocusHandler();
        mCanSelect = new TestPredicate<>();
        mRightClickHandler = new TestEventHandler<>();
        mDeleteHandler = new TestEventHandler<>();
        mDragAndDropHandler = new TestEventHandler<>();
        mGestureSelectHandler = new TestEventHandler<>();

        mInputHandler = new UserInputHandler<>(
                mActionHandler,
                mFocusHandler,
                selectionMgr,
                (MotionEvent event) -> {
                    throw new UnsupportedOperationException("Not exercised in tests.");
                },
                mCanSelect,
                mRightClickHandler::accept,
                mDeleteHandler::accept,
                mDragAndDropHandler::accept,
                mGestureSelectHandler::accept);

        mEvent = TestEvent.builder().mouse();
    }

    @Test
    public void testArrowKey_nonShiftClearsSelection() {
        mInputHandler.onSingleTapConfirmed(mEvent.at(11).build());
        mSelection.assertSelection(11);

        mFocusHandler.handleKey = true;
        KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_UP);
        mInputHandler.onKey(null, event.getKeyCode(), event);

        mSelection.assertNoSelection();
    }
}
 No newline at end of file