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