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; 18 19 import android.test.AndroidTestCase; 20 import android.test.suitebuilder.annotation.SmallTest; 21 22 import com.android.documentsui.base.Features; 23 import com.android.documentsui.dirlist.TestData; 24 import com.android.documentsui.testing.TestModel; 25 import com.android.documentsui.selection.SelectionManager; 26 import com.android.documentsui.testing.SelectionManagers; 27 import com.android.documentsui.testing.TestFeatures; 28 import com.android.documentsui.testing.TestRecyclerView; 29 30 import java.util.ArrayList; 31 import java.util.List; 32 33 @SmallTest 34 public class FocusManagerTest extends AndroidTestCase { 35 36 private static final String TEST_AUTHORITY = "test_authority"; 37 38 private static final List<String> ITEMS = TestData.create(10); 39 40 private FocusManager mManager; 41 private TestRecyclerView mView; 42 private SelectionManager mSelectionMgr; 43 private TestFeatures mFeatures; 44 45 @Override setUp()46 public void setUp() throws Exception { 47 mView = TestRecyclerView.create(ITEMS); 48 mSelectionMgr = SelectionManagers.createTestInstance(ITEMS); 49 mFeatures = new TestFeatures(); 50 mManager = new FocusManager(mFeatures, mSelectionMgr, null, null, 0) 51 .reset(mView, new TestModel(TEST_AUTHORITY, mFeatures)); 52 } 53 testFocus()54 public void testFocus() { 55 mManager.focusDocument(Integer.toString(3)); 56 mView.assertItemViewFocused(3); 57 } 58 testPendingFocus()59 public void testPendingFocus() { 60 mManager.focusDocument(Integer.toString(10)); 61 List<String> mutableItems = TestData.create(11); 62 mView.setItems(mutableItems); 63 mManager.onLayoutCompleted(); 64 // Should only be called once 65 mView.assertItemViewFocused(10); 66 } 67 testFocusDirectoryList_noItemsToFocus()68 public void testFocusDirectoryList_noItemsToFocus() { 69 mView = TestRecyclerView.create(new ArrayList<>()); 70 mManager = new FocusManager( 71 mFeatures, SelectionManagers.createTestInstance(), null, null, 0) 72 .reset(mView, new TestModel(TEST_AUTHORITY, mFeatures)); 73 assertFalse(mManager.focusDirectoryList()); 74 } 75 testFocusDirectoryList_hasSelection()76 public void testFocusDirectoryList_hasSelection() { 77 mSelectionMgr.toggleSelection("0"); 78 assertFalse(mManager.focusDirectoryList()); 79 } 80 } 81