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.app.DownloadManager;
20 import android.app.DownloadManager.Request;
21 import android.content.Context;
22 import android.net.Uri;
23 import android.support.test.uiautomator.Configurator;
24 import android.support.test.uiautomator.UiObject;
25 import android.view.MotionEvent;
26 
27 import androidx.test.filters.LargeTest;
28 import androidx.test.filters.Suppress;
29 
30 import com.android.documentsui.files.FilesActivity;
31 
32 // TODO: As of this writing all tests in this class are disabled. Please fix.
33 @LargeTest
34 public class IntegratedDownloadsUiTest extends ActivityTest<FilesActivity> {
35 
IntegratedDownloadsUiTest()36     public IntegratedDownloadsUiTest() {
37         super(FilesActivity.class);
38     }
39 
40     // We don't really need to test the entirety of download support
41     // since downloads is (almost) just another provider.
42     @Suppress
testDownload_Queued()43     public void testDownload_Queued() throws Exception {
44         DownloadManager dm = (DownloadManager) context.getSystemService(
45                 Context.DOWNLOAD_SERVICE);
46         // This downloads ends up being queued (because DNS can't be resolved).
47         // We'll still see an entry in the downloads UI with a "Queued" label.
48         dm.enqueue(new Request(Uri.parse("http://hammychamp.toodles")));
49 
50         bots.roots.openRoot("Downloads");
51         bots.directory.assertDocumentsPresent("Queued");
52     }
53 
54     @Suppress
testDownload_RetryUnsuccessful()55     public void testDownload_RetryUnsuccessful() throws Exception {
56         DownloadManager dm = (DownloadManager) context.getSystemService(
57                 Context.DOWNLOAD_SERVICE);
58         // This downloads fails! But it'll still show up.
59         dm.enqueue(new Request(Uri.parse("http://www.google.com/hamfancy")));
60 
61         bots.roots.openRoot("Downloads");
62         UiObject doc = bots.directory.findDocument("Unsuccessful");
63         doc.waitForExists(TIMEOUT);
64 
65         int toolType = Configurator.getInstance().getToolType();
66         Configurator.getInstance().setToolType(MotionEvent.TOOL_TYPE_FINGER);
67         doc.click();
68         Configurator.getInstance().setToolType(toolType);
69 
70         assertTrue(bots.main.findDownloadRetryDialog().exists());
71 
72         device.pressBack(); // to clear the dialog.
73     }
74 }
75