1 /*
2  * Copyright (C) 2016 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 package com.android.documentsui.ui;
17 
18 import androidx.fragment.app.FragmentManager;
19 
20 import com.android.documentsui.base.DocumentInfo;
21 import com.android.documentsui.picker.ConfirmFragment;
22 import com.android.documentsui.services.FileOperation;
23 import com.android.documentsui.services.FileOperations;
24 
25 import junit.framework.Assert;
26 
27 public class TestDialogController implements DialogController {
28 
29     private int mFileOpStatus;
30     private boolean mActionNotAllowed;
31     private boolean mNoApplicationFound;
32     private boolean mDocumentsClipped;
33     private boolean mViewInArchivesUnsupported;
34     private boolean mShowOperationUnsupported;
35     private boolean mShowShareOverLimit;
36     private DocumentInfo mTarget;
37     private int mConfrimType;
38 
TestDialogController()39     public TestDialogController() {
40     }
41 
42     @Override
showFileOperationStatus(int status, int opType, int docCount)43     public void showFileOperationStatus(int status, int opType, int docCount) {
44         mFileOpStatus = status;
45     }
46 
47     @Override
showProgressDialog(String jobId, FileOperation operation)48     public void showProgressDialog(String jobId, FileOperation operation) {
49         throw new UnsupportedOperationException();
50     }
51 
52     @Override
showActionNotAllowed()53     public void showActionNotAllowed() {
54         mActionNotAllowed = true;
55     }
56 
57     @Override
showNoApplicationFound()58     public void showNoApplicationFound() {
59         mNoApplicationFound = true;
60     }
61 
62     @Override
showOperationUnsupported()63     public void showOperationUnsupported() {
64         mShowOperationUnsupported = true;
65     }
66 
67     @Override
showViewInArchivesUnsupported()68     public void showViewInArchivesUnsupported() {
69         mViewInArchivesUnsupported = true;
70     }
71 
72     @Override
showDocumentsClipped(int size)73     public void showDocumentsClipped(int size) {
74         mDocumentsClipped = true;
75     }
76 
77     @Override
showShareOverLimit(int size)78     public void showShareOverLimit(int size) {
79         mShowShareOverLimit = true;
80     }
81 
82     @Override
confirmAction(FragmentManager fm, DocumentInfo pickTarget, int type)83     public void confirmAction(FragmentManager fm, DocumentInfo pickTarget, int type) {
84         mTarget = pickTarget;
85         mConfrimType = type;
86     }
87 
assertNoFileFailures()88     public void assertNoFileFailures() {
89         Assert.assertEquals(FileOperations.Callback.STATUS_ACCEPTED, mFileOpStatus);
90     }
91 
assertFileOpFailed()92     public void assertFileOpFailed() {
93         Assert.assertEquals(FileOperations.Callback.STATUS_FAILED, mFileOpStatus);
94     }
95 
assertActionNotAllowedShown()96     public void assertActionNotAllowedShown() {
97         Assert.assertTrue(mActionNotAllowed);
98     }
99 
assertActionNotAllowedNotShown()100     public void assertActionNotAllowedNotShown() {
101         Assert.assertFalse(mActionNotAllowed);
102     }
103 
assertNoAppFoundShown()104     public void assertNoAppFoundShown() {
105         Assert.assertFalse(mNoApplicationFound);
106     }
107 
assertShowOperationUnsupported()108     public void assertShowOperationUnsupported() {
109         Assert.assertTrue(mShowOperationUnsupported);
110     }
assertViewInArchivesShownUnsupported()111     public void assertViewInArchivesShownUnsupported() {
112         Assert.assertTrue(mViewInArchivesUnsupported);
113     }
114 
assertDocumentsClippedNotShown()115     public void assertDocumentsClippedNotShown() {
116         Assert.assertFalse(mDocumentsClipped);
117     }
118 
assertShareOverLimitShown()119     public void assertShareOverLimitShown() {
120         Assert.assertTrue(mShowShareOverLimit);
121     }
122 
assertOverwriteConfirmed(DocumentInfo expected)123     public void assertOverwriteConfirmed(DocumentInfo expected) {
124         Assert.assertEquals(expected, mTarget);
125         Assert.assertEquals(ConfirmFragment.TYPE_OVERWRITE, mConfrimType);
126     }
127 
assertDocumentTreeConfirmed(DocumentInfo expected)128     public void assertDocumentTreeConfirmed(DocumentInfo expected) {
129         Assert.assertEquals(expected, mTarget);
130         Assert.assertEquals(ConfirmFragment.TYPE_OEPN_TREE, mConfrimType);
131     }
132 }
133