Loading packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java +10 −4 Original line number Diff line number Diff line Loading @@ -283,10 +283,16 @@ public class FilesActivity extends BaseActivity { */ private void openDocument(DocumentInfo doc, Model model) { // Provide specialized handling of downloaded APKs This sends the APK // details off to get extra security information added, and finally // to be handled by the package manager. if (MimePredicate.isApkType(doc.mimeType)) { // Anything on downloads goes through the back through downloads manager // (that's the MANAGE_DOCUMENT bit). // This is done for two reasons: // 1) The file in question might be a failed/queued or otherwise have some // specialized download handling. // 2) For APKs, the download manager will add on some important security stuff // like origin URL. // All other files not on downloads, event APKs, would get no benefit from this // treatment, thusly the "isDownloads" check. if (getCurrentRoot().isDownloads()) { // First try managing the document; we expect manager to filter // based on authority, so we don't grant. final Intent manage = new Intent(DocumentsContract.ACTION_MANAGE_DOCUMENT); Loading packages/DocumentsUI/tests/AndroidManifest.xml +2 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.documentsui.tests"> <uses-permission android:name="android.permission.INTERNET" /> <application> <uses-library android:name="android.test.runner" /> <provider Loading packages/DocumentsUI/tests/src/com/android/documentsui/FilesActivityUiTest.java +40 −0 Original line number Diff line number Diff line Loading @@ -19,10 +19,17 @@ package com.android.documentsui; import static com.android.documentsui.StubProvider.ROOT_0_ID; import static com.android.documentsui.StubProvider.ROOT_1_ID; import android.app.DownloadManager; import android.app.DownloadManager.Request; import android.content.Context; import android.net.Uri; import android.os.RemoteException; import android.support.test.uiautomator.Configurator; import android.support.test.uiautomator.UiObject; import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.Suppress; import android.view.KeyEvent; import android.view.MotionEvent; import com.android.documentsui.model.RootInfo; Loading Loading @@ -173,4 +180,37 @@ public class FilesActivityUiTest extends ActivityTest<FilesActivity> { bots.roots.assertHasFocus(); } } // We don't really need to test the entirety of download support // since downloads is (almost) just another provider. public void testDownload_Queued() throws Exception { DownloadManager dm = (DownloadManager) context.getSystemService( Context.DOWNLOAD_SERVICE); // This downloads ends up being queued (because DNS can't be resolved). // We'll still see an entry in the downloads UI with a "Queued" label. dm.enqueue(new Request(Uri.parse("http://hammychamp.toodles"))); bots.roots.openRoot("Downloads"); bots.directory.assertDocumentsPresent("Queued"); } public void testDownload_RetryUnsuccessful() throws Exception { DownloadManager dm = (DownloadManager) context.getSystemService( Context.DOWNLOAD_SERVICE); // This downloads fails! But it'll still show up. dm.enqueue(new Request(Uri.parse("http://www.google.com/hamfancy"))); bots.roots.openRoot("Downloads"); UiObject doc = bots.directory.findDocument("Unsuccessful"); doc.waitForExists(TIMEOUT); int toolType = Configurator.getInstance().getToolType(); Configurator.getInstance().setToolType(MotionEvent.TOOL_TYPE_FINGER); doc.click(); Configurator.getInstance().setToolType(toolType); assertTrue(bots.main.findDownloadRetryDialog().exists()); device.pressBack(); // to clear the dialog. } } packages/DocumentsUI/tests/src/com/android/documentsui/bots/UiBot.java +7 −0 Original line number Diff line number Diff line Loading @@ -173,6 +173,13 @@ public class UiBot extends BaseBot { return findObject("android:id/content", "android:id/text1"); } public UiObject findDownloadRetryDialog() { UiSelector selector = new UiSelector().text("Couldn't download"); UiObject title = mDevice.findObject(selector); title.waitForExists(mTimeout); return title; } public UiObject findDialogOkButton() { UiObject object = findObject("android:id/content", "android:id/button1"); object.waitForExists(mTimeout); Loading Loading
packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java +10 −4 Original line number Diff line number Diff line Loading @@ -283,10 +283,16 @@ public class FilesActivity extends BaseActivity { */ private void openDocument(DocumentInfo doc, Model model) { // Provide specialized handling of downloaded APKs This sends the APK // details off to get extra security information added, and finally // to be handled by the package manager. if (MimePredicate.isApkType(doc.mimeType)) { // Anything on downloads goes through the back through downloads manager // (that's the MANAGE_DOCUMENT bit). // This is done for two reasons: // 1) The file in question might be a failed/queued or otherwise have some // specialized download handling. // 2) For APKs, the download manager will add on some important security stuff // like origin URL. // All other files not on downloads, event APKs, would get no benefit from this // treatment, thusly the "isDownloads" check. if (getCurrentRoot().isDownloads()) { // First try managing the document; we expect manager to filter // based on authority, so we don't grant. final Intent manage = new Intent(DocumentsContract.ACTION_MANAGE_DOCUMENT); Loading
packages/DocumentsUI/tests/AndroidManifest.xml +2 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.documentsui.tests"> <uses-permission android:name="android.permission.INTERNET" /> <application> <uses-library android:name="android.test.runner" /> <provider Loading
packages/DocumentsUI/tests/src/com/android/documentsui/FilesActivityUiTest.java +40 −0 Original line number Diff line number Diff line Loading @@ -19,10 +19,17 @@ package com.android.documentsui; import static com.android.documentsui.StubProvider.ROOT_0_ID; import static com.android.documentsui.StubProvider.ROOT_1_ID; import android.app.DownloadManager; import android.app.DownloadManager.Request; import android.content.Context; import android.net.Uri; import android.os.RemoteException; import android.support.test.uiautomator.Configurator; import android.support.test.uiautomator.UiObject; import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.Suppress; import android.view.KeyEvent; import android.view.MotionEvent; import com.android.documentsui.model.RootInfo; Loading Loading @@ -173,4 +180,37 @@ public class FilesActivityUiTest extends ActivityTest<FilesActivity> { bots.roots.assertHasFocus(); } } // We don't really need to test the entirety of download support // since downloads is (almost) just another provider. public void testDownload_Queued() throws Exception { DownloadManager dm = (DownloadManager) context.getSystemService( Context.DOWNLOAD_SERVICE); // This downloads ends up being queued (because DNS can't be resolved). // We'll still see an entry in the downloads UI with a "Queued" label. dm.enqueue(new Request(Uri.parse("http://hammychamp.toodles"))); bots.roots.openRoot("Downloads"); bots.directory.assertDocumentsPresent("Queued"); } public void testDownload_RetryUnsuccessful() throws Exception { DownloadManager dm = (DownloadManager) context.getSystemService( Context.DOWNLOAD_SERVICE); // This downloads fails! But it'll still show up. dm.enqueue(new Request(Uri.parse("http://www.google.com/hamfancy"))); bots.roots.openRoot("Downloads"); UiObject doc = bots.directory.findDocument("Unsuccessful"); doc.waitForExists(TIMEOUT); int toolType = Configurator.getInstance().getToolType(); Configurator.getInstance().setToolType(MotionEvent.TOOL_TYPE_FINGER); doc.click(); Configurator.getInstance().setToolType(toolType); assertTrue(bots.main.findDownloadRetryDialog().exists()); device.pressBack(); // to clear the dialog. } }
packages/DocumentsUI/tests/src/com/android/documentsui/bots/UiBot.java +7 −0 Original line number Diff line number Diff line Loading @@ -173,6 +173,13 @@ public class UiBot extends BaseBot { return findObject("android:id/content", "android:id/text1"); } public UiObject findDownloadRetryDialog() { UiSelector selector = new UiSelector().text("Couldn't download"); UiObject title = mDevice.findObject(selector); title.waitForExists(mTimeout); return title; } public UiObject findDialogOkButton() { UiObject object = findObject("android:id/content", "android:id/button1"); object.waitForExists(mTimeout); Loading