1 /* 2 * Copyright (C) 2015 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; 18 19 import android.os.RemoteException; 20 import android.support.test.filters.LargeTest; 21 import android.support.test.filters.Suppress; 22 import android.view.KeyEvent; 23 24 import com.android.documentsui.files.FilesActivity; 25 26 @LargeTest 27 public class KeyboardNavigationUiTest extends ActivityTest<FilesActivity> { 28 KeyboardNavigationUiTest()29 public KeyboardNavigationUiTest() { 30 super(FilesActivity.class); 31 } 32 33 @Override setUp()34 public void setUp() throws Exception { 35 super.setUp(); 36 initTestFiles(); 37 } 38 39 @Override initTestFiles()40 public void initTestFiles() throws RemoteException { 41 mDocsHelper.createDocument(rootDir0, "image/png", "file1.png"); 42 } 43 44 // Tests that pressing tab switches focus between the roots and directory listings. 45 @Suppress testKeyboard_tab()46 public void testKeyboard_tab() throws Exception { 47 bots.keyboard.pressKey(KeyEvent.KEYCODE_TAB); 48 bots.roots.assertHasFocus(); 49 bots.keyboard.pressKey(KeyEvent.KEYCODE_TAB); 50 bots.directory.assertHasFocus(); 51 } 52 53 // Tests that arrow keys do not switch focus away from the dir list. 54 @Suppress testKeyboard_arrowsDirList()55 public void testKeyboard_arrowsDirList() throws Exception { 56 for (int i = 0; i < 10; i++) { 57 bots.keyboard.pressKey(KeyEvent.KEYCODE_DPAD_LEFT); 58 bots.directory.assertHasFocus(); 59 } 60 for (int i = 0; i < 10; i++) { 61 bots.keyboard.pressKey(KeyEvent.KEYCODE_DPAD_RIGHT); 62 bots.directory.assertHasFocus(); 63 } 64 } 65 66 @Suppress testKeyboard_tabFocuses()67 public void testKeyboard_tabFocuses() throws Exception { 68 bots.roots.closeDrawer(); 69 if (bots.main.inFixedLayout()) { 70 // Tablet devices need to press one more tab since it focuses on root list first 71 bots.keyboard.pressKey(KeyEvent.KEYCODE_TAB); 72 } 73 bots.keyboard.pressKey(KeyEvent.KEYCODE_TAB); 74 bots.directory.assertFirstDocumentHasFocus(); 75 76 // This should not cause any exceptions 77 bots.keyboard.pressKey(KeyEvent.KEYCODE_F); 78 } 79 80 // Tests that arrow keys do not switch focus away from the roots list. testKeyboard_arrowsRootsList()81 public void testKeyboard_arrowsRootsList() throws Exception { 82 83 // Open the drawer so we can ensure root list available even for phones 84 bots.roots.openDrawer(); 85 86 bots.keyboard.pressKey(KeyEvent.KEYCODE_TAB); 87 for (int i = 0; i < 10; i++) { 88 bots.keyboard.pressKey(KeyEvent.KEYCODE_DPAD_RIGHT); 89 bots.roots.assertHasFocus(); 90 } 91 for (int i = 0; i < 10; i++) { 92 bots.keyboard.pressKey(KeyEvent.KEYCODE_DPAD_LEFT); 93 bots.roots.assertHasFocus(); 94 } 95 } 96 } 97