Loading tests/common/com/android/documentsui/DocumentsProviderHelper.java +19 −0 Original line number Diff line number Diff line Loading @@ -304,6 +304,25 @@ public class DocumentsProviderHelper { return children; } /** List all the children for the specific `root`. */ public List<DocumentInfo> listAllChildren(RootInfo root) throws Exception { List<DocumentInfo> children = new ArrayList<>(); try (Cursor cursor = mClient.query( buildChildDocumentsUri(root.authority, root.documentId), null, null, null, null, null)) { Cursor wrapper = new RootCursorWrapper(mUserId, mAuthority, root.rootId, cursor, 100); while (wrapper.moveToNext()) { children.add(DocumentInfo.fromDirectoryCursor(wrapper)); } } return children; } public void assertFileContents(Uri documentUri, byte[] expected) throws Exception { MoreAsserts.assertEquals( "Copied file contents differ", Loading tests/functional/com/android/documentsui/BandSelectionUiTest.java +38 −8 Original line number Diff line number Diff line Loading @@ -17,16 +17,23 @@ package com.android.documentsui; import android.graphics.Point; import android.graphics.Rect; import android.view.View; import androidx.test.filters.LargeTest; import com.android.documentsui.base.DocumentInfo; import com.android.documentsui.base.RootInfo; import com.android.documentsui.files.FilesActivity; import com.android.documentsui.rules.TestFilesRule; import com.android.documentsui.sorting.SortDimension; import com.android.documentsui.sorting.SortModel; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import java.util.List; @LargeTest public class BandSelectionUiTest extends ActivityTestJunit4<FilesActivity> { Loading @@ -52,16 +59,39 @@ public class BandSelectionUiTest extends ActivityTestJunit4<FilesActivity> { @Test public void testBandSelection_someFiles() throws Exception { // Switch to Grid mode and ensure the list is sorted by title. bots.main.switchToGridMode(); bots.sort.sortBy(SortModel.SORT_DIMENSION_ID_TITLE, SortDimension.SORT_DIRECTION_ASCENDING); // Get all the documents to enumerate through and find all the documents in the top row. RootInfo root = mTestFiles.docsHelper.getRootList().get(0); List<DocumentInfo> createdDocs = mTestFiles.docsHelper.listAllChildren(root); // Work out the start and end of the drag selection to go select the top row of documents // if this is done in the opposite direction it will trigger the drawer to be swiped open. Rect dirListBounds = bots.directory.findDocumentsList().getBounds(); Rect startDoc = bots.directory.findDocument(TestFilesRule.FILE_NAME_NO_RENAME).getBounds(); Rect endDoc = bots.directory.findDocument(TestFilesRule.FILE_NAME_1).getBounds(); // Start from right side of file NoRename. Point start = new Point(dirListBounds.right - 1, startDoc.bottom - 1); // End is center of file1 Point end = new Point(endDoc.centerX(), endDoc.centerY()); bots.gesture.bandSelection(start, end); Rect startDoc = bots.directory.findDocument(createdDocs.get(0).displayName).getBounds(); Point endPoint = new Point(dirListBounds.left + 1, startDoc.centerY()); Point startPoint = new Point(dirListBounds.right - 1, startDoc.centerY()); bots.directory.assertSelection(3); // Count the number of documents in the top row. This can differ based on the screen size so // calculate it dynamically to avoid failing on different devices. int docsInTopRow = 0; for (DocumentInfo doc : createdDocs) { Rect docBounds = bots.directory.findDocument(doc.displayName).getBounds(); if (docBounds.centerY() != startDoc.centerY()) { break; } docsInTopRow++; } // Perform drag and assert that the number of docs in the top row is selected. if (context.getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { bots.gesture.bandSelection(endPoint, startPoint); } else { bots.gesture.bandSelection(startPoint, endPoint); } bots.directory.assertSelection(docsInTopRow); } } Loading
tests/common/com/android/documentsui/DocumentsProviderHelper.java +19 −0 Original line number Diff line number Diff line Loading @@ -304,6 +304,25 @@ public class DocumentsProviderHelper { return children; } /** List all the children for the specific `root`. */ public List<DocumentInfo> listAllChildren(RootInfo root) throws Exception { List<DocumentInfo> children = new ArrayList<>(); try (Cursor cursor = mClient.query( buildChildDocumentsUri(root.authority, root.documentId), null, null, null, null, null)) { Cursor wrapper = new RootCursorWrapper(mUserId, mAuthority, root.rootId, cursor, 100); while (wrapper.moveToNext()) { children.add(DocumentInfo.fromDirectoryCursor(wrapper)); } } return children; } public void assertFileContents(Uri documentUri, byte[] expected) throws Exception { MoreAsserts.assertEquals( "Copied file contents differ", Loading
tests/functional/com/android/documentsui/BandSelectionUiTest.java +38 −8 Original line number Diff line number Diff line Loading @@ -17,16 +17,23 @@ package com.android.documentsui; import android.graphics.Point; import android.graphics.Rect; import android.view.View; import androidx.test.filters.LargeTest; import com.android.documentsui.base.DocumentInfo; import com.android.documentsui.base.RootInfo; import com.android.documentsui.files.FilesActivity; import com.android.documentsui.rules.TestFilesRule; import com.android.documentsui.sorting.SortDimension; import com.android.documentsui.sorting.SortModel; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import java.util.List; @LargeTest public class BandSelectionUiTest extends ActivityTestJunit4<FilesActivity> { Loading @@ -52,16 +59,39 @@ public class BandSelectionUiTest extends ActivityTestJunit4<FilesActivity> { @Test public void testBandSelection_someFiles() throws Exception { // Switch to Grid mode and ensure the list is sorted by title. bots.main.switchToGridMode(); bots.sort.sortBy(SortModel.SORT_DIMENSION_ID_TITLE, SortDimension.SORT_DIRECTION_ASCENDING); // Get all the documents to enumerate through and find all the documents in the top row. RootInfo root = mTestFiles.docsHelper.getRootList().get(0); List<DocumentInfo> createdDocs = mTestFiles.docsHelper.listAllChildren(root); // Work out the start and end of the drag selection to go select the top row of documents // if this is done in the opposite direction it will trigger the drawer to be swiped open. Rect dirListBounds = bots.directory.findDocumentsList().getBounds(); Rect startDoc = bots.directory.findDocument(TestFilesRule.FILE_NAME_NO_RENAME).getBounds(); Rect endDoc = bots.directory.findDocument(TestFilesRule.FILE_NAME_1).getBounds(); // Start from right side of file NoRename. Point start = new Point(dirListBounds.right - 1, startDoc.bottom - 1); // End is center of file1 Point end = new Point(endDoc.centerX(), endDoc.centerY()); bots.gesture.bandSelection(start, end); Rect startDoc = bots.directory.findDocument(createdDocs.get(0).displayName).getBounds(); Point endPoint = new Point(dirListBounds.left + 1, startDoc.centerY()); Point startPoint = new Point(dirListBounds.right - 1, startDoc.centerY()); bots.directory.assertSelection(3); // Count the number of documents in the top row. This can differ based on the screen size so // calculate it dynamically to avoid failing on different devices. int docsInTopRow = 0; for (DocumentInfo doc : createdDocs) { Rect docBounds = bots.directory.findDocument(doc.displayName).getBounds(); if (docBounds.centerY() != startDoc.centerY()) { break; } docsInTopRow++; } // Perform drag and assert that the number of docs in the top row is selected. if (context.getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { bots.gesture.bandSelection(endPoint, startPoint); } else { bots.gesture.bandSelection(startPoint, endPoint); } bots.directory.assertSelection(docsInTopRow); } }