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
17package com.android.documentsui;
18
19import android.net.Uri;
20import android.os.RemoteException;
21import android.support.test.filters.LargeTest;
22
23import com.android.documentsui.files.FilesActivity;
24
25@LargeTest
26public class FilesActivityUiTest extends ActivityTest<FilesActivity> {
27
28    public FilesActivityUiTest() {
29        super(FilesActivity.class);
30    }
31
32    @Override
33    public void setUp() throws Exception {
34        super.setUp();
35        initTestFiles();
36    }
37
38    @Override
39    public void initTestFiles() throws RemoteException {
40        Uri uri = mDocsHelper.createFolder(rootDir0, dirName1);
41        mDocsHelper.createFolder(uri, childDir1);
42
43        mDocsHelper.createDocument(rootDir0, "text/plain", "file0.log");
44        mDocsHelper.createDocument(rootDir0, "image/png", "file1.png");
45        mDocsHelper.createDocument(rootDir0, "text/csv", "file2.csv");
46
47        mDocsHelper.createDocument(rootDir1, "text/plain", "anotherFile0.log");
48        mDocsHelper.createDocument(rootDir1, "text/plain", "poodles.text");
49    }
50
51    // Recents is a strange meta root that gathers entries from other providers.
52    // It is special cased in a variety of ways, which is why we just want
53    // to be able to click on it.
54    public void testClickRecent() throws Exception {
55        bots.roots.openRoot("Recent");
56        bots.main.assertWindowTitle("Recent");
57    }
58
59    public void testRootClick_SetsWindowTitle() throws Exception {
60        bots.roots.openRoot("Images");
61        bots.main.assertWindowTitle("Images");
62    }
63
64    public void testProtectedFolder_showsAuthenticationUi() throws Exception {
65        bots.roots.openRoot("Demo Root");
66        bots.main.switchToListMode();
67        bots.directory.openDocument("throw a authentication exception");
68        bots.directory.assertHeaderMessageText(
69                "To view this directory, sign in to DocumentsUI Tests");
70
71    }
72
73    public void testFilesListed() throws Exception {
74        bots.directory.assertDocumentsPresent("file0.log", "file1.png", "file2.csv");
75    }
76
77    public void testFilesList_LiveUpdate() throws Exception {
78        mDocsHelper.createDocument(rootDir0, "yummers/sandwich", "Ham & Cheese.sandwich");
79
80        bots.directory.waitForDocument("Ham & Cheese.sandwich");
81        bots.directory.assertDocumentsPresent(
82                "file0.log", "file1.png", "file2.csv", "Ham & Cheese.sandwich");
83    }
84
85    public void testNavigate_inFixedLayout_byBreadcrumb() throws Exception {
86        bots.directory.openDocument(dirName1);
87        bots.directory.waitForDocument(childDir1);  // wait for known content
88        bots.directory.assertDocumentsPresent(childDir1);
89
90        bots.breadcrumb.revealAsNeeded();
91        device.waitForIdle();
92        bots.breadcrumb.assertItemsPresent(dirName1, "TEST_ROOT_0");
93
94        bots.breadcrumb.clickItem("TEST_ROOT_0");
95        bots.directory.waitForDocument(dirName1);
96    }
97
98    public void testNavigate_inFixedLayout_whileHasSelection() throws Exception {
99        if (bots.main.inFixedLayout()) {
100            bots.roots.openRoot(rootDir0.title);
101            device.waitForIdle();
102            bots.directory.selectDocument("file0.log", 1);
103
104            // ensure no exception is thrown while navigating to a different root
105            bots.roots.openRoot(rootDir1.title);
106        }
107    }
108
109    public void testRootChange_UpdatesSortHeader() throws Exception {
110
111        // switch to separate display modes for two separate roots. Each
112        // mode has its own distinct sort header. This should be remembered
113        // by files app.
114        bots.roots.openRoot("Images");
115        bots.main.switchToGridMode();
116        bots.roots.openRoot("Videos");
117        bots.main.switchToListMode();
118
119        // Now switch back and assert the correct mode sort header mode
120        // is restored when we load the root with that display mode.
121        bots.roots.openRoot("Images");
122        bots.sortHeader.assertDropdownMode();
123        if (bots.main.inFixedLayout()) {
124            bots.roots.openRoot("Videos");
125            bots.sortHeader.assertColumnMode();
126        } else {
127            bots.roots.openRoot("Videos");
128            bots.sortHeader.assertDropdownMode();
129        }
130    }
131}
132